0 purchases
webview refresher
Webview Refresher #
bring pull to refresh feature to official webview plugin
Install #
flutter pub add webview_refresher
copied to clipboard
Usage #
final controller = WebViewController();
Completer<void>? _completer;
Future onRefresh() {
_completer = Completer<void>();
return _completer!.future;
}
finishRefresh() {
if (_completer?.isCompleted ?? false) {
_completer?.complete();
}
}
@override
void initState() {
super.initState();
controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (url) {
finishRefresh();
},
onWebResourceError: (error) {
finishRefresh();
},
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('demo'),
actions: [
IconButton(
onPressed: () {
controller.loadRequest(Uri.parse('https://www.zhihu.com/'));
},
icon: const Icon(Icons.play_arrow_rounded),
),
],
),
body: WebviewRefresher(
controller: controller,
onRefresh: onRefresh,
),
);
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.