Flutter 在Flatter中从webview导航到InApp屏幕
我有一个Flitter应用程序,它有一个web视图和一个特定的URL。web视图具有表单,当表单被填充和提交时,web视图根据用户的表单填充将用户重定向到结果URL 我正在使用:InAppWebView插件进行webview 当我的重定向url被点击时,我想导航到我的仪表板屏幕。我无法浏览此屏幕。请帮忙 以下是我的构建方法:Flutter 在Flatter中从webview导航到InApp屏幕,flutter,webview,Flutter,Webview,我有一个Flitter应用程序,它有一个web视图和一个特定的URL。web视图具有表单,当表单被填充和提交时,web视图根据用户的表单填充将用户重定向到结果URL 我正在使用:InAppWebView插件进行webview 当我的重定向url被点击时,我想导航到我的仪表板屏幕。我无法浏览此屏幕。请帮忙 以下是我的构建方法: Widget build(BuildContext context) { return MaterialApp( debugShowCheckedMod
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("MyApp"),
),
body: InAppWebView(
initialUrl: "myURL",
onWebViewCreated: (InAppWebViewController controller) {
_webViewController = controller;
},
onLoadStop: (InAppWebViewController controller, String url) async {
if (url.startsWith("redirectURL")) {
// get your token from url
Navigator.pop(context);
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => DashboardScreen()));
}
},
),
),
);
}
这是一个背景问题。此外,您不必删除路线进行更换。使用以下工作代码将解决此问题
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text("MyApp"),
),
body: InAppWebView(
initialUrl: "https://www.google.com.pk/",
onWebViewCreated: (InAppWebViewController controller) {},
onLoadStop: (InAppWebViewController controller, String url) async {
if (url.contains("youtube")) {
// get your token from url
// Navigator.pop(scaffoldKey.currentContext); // No need of this
line
Navigator.pushReplacement(scaffoldKey.currentContext,
MaterialPageRoute(builder: (context) => DD()));
}
},
),
),
);
}
final scaffoldKey=GlobalKey();
@凌驾
小部件构建(构建上下文){
返回材料PP(
debugShowCheckedModeBanner:false,
家:脚手架(
钥匙:脚手架钥匙,
appBar:appBar(
标题:文本(“MyApp”),
),
正文:InAppWebView(
初始URL:“https://www.google.com.pk/",
onWebViewCreated:(InAppWebViewController控制器){},
onLoadStop:(InAppWebViewController控制器,字符串url)异步{
如果(url.contains(“youtube”)){
//从url获取您的令牌
//Navigator.pop(scaffoldKey.currentContext);//不需要这个
线
Navigator.pushReplacement(scaffoldKey.currentContext,
MaterialPage路由(生成器:(上下文)=>DD());
}
},
),
),
);
}
您到底被困在哪里?我无法从webview导航到下一个屏幕。