如何实现Flutter WebView的拉式刷新



我在实现pull刷新flutter WebView时遇到问题。我的应用程序由单屏幕和当前网页组成。我很困惑如何实现,因为我试图使用RefreshIndicator,但它没有起作用。这是我的代码

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: MediaQuery.of(context).size * 0.05,
child: AppBar(
//leading: Image.asset(gnTabIcon),
elevation: 3.5,
shadowColor: AppColors.navyBlue,
backgroundColor: AppColors.orange,
title: const Text(title),
actions: <Widget>[
NavigationControls(_controller.future), // control navigation
],
),
),

// build scaffold for main app
body: Builder(
builder: (BuildContext context) {
return Stack(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 15.0),
child: WebView(
gestureNavigationEnabled: false,
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
zoomEnabled: false, // disable pinch to zoom
onWebViewCreated: (webViewController) {
print('WebView is created');
_controller.complete(webViewController);
},
onProgress: (int progress) {
print("WebView is loading (progress : $progress%)");
splashScreenDelay(progress);
},
javascriptChannels: <JavascriptChannel>{
_toasterJavascriptChannel(context),
},
onPageStarted: (String url) {
print('Page started loading: $url');
_loadingStateTrue();
},
onPageFinished: (String url) {
print('Page finished loading: $url');
_loadingStateFalse();
},
),
),
isLoading
? Center(
child: GnLoader(),
)
: Stack(),
],
);
},
),
);
}

我试过在互联网上搜索,但没有什么效果,因为方法不同,也令人困惑。请帮帮我。谢谢

您必须调用WebviewController 的重载方法

创建Webview控制器

WebViewController _webViewController;

在您的Webview 中

onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
},

则在Pull中调用CCD_ 1。您可以使用Pull_to_refresh包裹

最新更新