我有一個簡單的 webview 應用程式,當我瀏覽一些頁面并按下后退按鈕時,它會關閉應用程式。按下后退按鈕時,我想轉到上一頁。但是我的代碼給出了錯誤
Try correcting the name to the name of an existing method, or defining a method named '_onWillPop'.
onWillPop: () => _onWillPop(context),
return Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
WillPopScope(
onWillPop: () => onWillPop(context),
child: WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'https://google.com',
navigationDelegate: (NavigationRequest request) {
setState(() {
isLoading = true;
});
return NavigationDecision.navigate;
},
onPageFinished: (String url) {
setState(() {
isLoading = false;
});
},
// onPageFinished: (finish) {
// setState(() {
// var isLoading = false;
// });
// },
),
),
isLoading
? const Center(
child: CircularProgressIndicator(),
)
: Stack(),
],
),
),
);
uj5u.com熱心網友回復:
你需要為 onWillPopScope 創建方法
這是例子
Future<bool> initBackButton() async {
Logger().d('back button pressed');
return await showDialog(
context: context,
builder: (context) => ElasticIn(
child: AlertDialog(
title: const Text('Exit App'),
content: const Text('Do you really want to exit ?'),
actions: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('No'),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Yes'),
),
],
),
),
) ??
false;
}
在這樣的電話之后
onWillPop: () => initBackButton,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/529417.html
標籤:扑