你能告诉我如何在我的webview应用程序中回到以前的页面吗?
我正在使用以下代码,适用于Android,但不能在iPhone上滑动-
late WebViewController? webViewController;
Future<bool> _onWillPop(BuildContext context) async {
if (await webViewController!.canGoBack()) {
webViewController!.goBack();
return Future value(false);
} else {
return Future value(true);
}
}
这是我完整的小部件代码-
return WillPopScope(
child: Scaffold(
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Colors.orange,
backgroundColor: Colors.white,
type: BottomNavigationBarType.fixed,
currentIndex: selectedIndex,
unselectedLabelStyle: TextStyle(color: Color.fromARGB(153, 162, 173, 1)),
selectedLabelStyle: TextStyle(fontSize: 11.9),
items: [
BottomNavigationBarItem(
icon: Container(margin: EdgeInsets.only(bottom: 5), height: 32, width: 35, child: Image.asset('assets/images/Home.png', fit: BoxFit.cover,),),
activeIcon: Container(margin: EdgeInsets.only(bottom: 5),height: 32, width: 35, child: Image.asset('assets/images/Home_color.png', fit: BoxFit.cover,),),
label: "Главная"
),
BottomNavigationBarItem(
icon: Container(margin: EdgeInsets.only(bottom: 5),height: 32, width: 32, child: Image.asset('assets/images/Catalog.png', fit: BoxFit.cover,)),
activeIcon: Container(margin: EdgeInsets.only(bottom: 5),height: 32, width: 32, child: Image.asset('assets/images/Catalog_color.png', fit: BoxFit.cover,),),
label: "Каталог",
),
],
onTap: (i) async {
webViewController?.loadUrl(linkNavbar[i]);
setState(() => selectedIndex = i);
},
),
body: SafeArea(
child: Stack(
children: [
WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: "https://caravan-store.shop/",
onWebViewCreated: (controller) {
setState(() {
webViewController = controller;
});
},
onWebResourceError: (WebResourceError error) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MyError(),
),
);
},
),
]
),
)
),
onWillPop: () => _onWillPop(context)
);
另外,我把这段代码添加到了我的main中。镖
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
}
)
在互联网上,我找不到解决这个问题的办法。我正在做的是尝试向右滑动以转到上一页。不幸的是,它不能在iPhone上工作,但它可以在Android上工作。
告诉我该怎么做?
2条答案
按热度按时间xn1cxnb41#
它的工作android和ios两个现在
t30tvxxf2#
老实说,我不知道为什么它能工作,但通过添加以下代码,一切都能在iPhone上工作。