aru*_*rul 1 dart flutter flutter-layout
我有一个WebView包含多个链接的页面。通过单击链接,它将打开另一个WebView带有关闭按钮的页面。如果我点击关闭按钮,当前窗口应该关闭并且WebView页面不应该重新加载。我尝试使用,onPressed: () => Navigator.of(context).pop()但它显示WebView页面为空。请帮助解决这个问题。
class Leader 扩展 StatelessWidget {
@覆盖
小部件构建(BuildContext 上下文){
返回 MaterialApp(
title: 'Flutter 演示',
主题:主题数据(
主要色板:Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage 扩展 StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
最终字符串标题;
@覆盖
_MyHomePageState createState() => _MyHomePageState();
}
类 _MyHomePageState 扩展状态 {
@覆盖
小部件构建(BuildContext 上下文){
返回脚手架(
正文:堆栈(
孩子们: [
网页视图(
initialUrl: '网页浏览网址',
javascriptMode: JavascriptMode.unrestricted,
导航委托:(导航请求请求){
打印(请求。网址);
var url = request.url;
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => WebView2(urlVal: url)));
返回 NavigationDecision.navigate;
},
),
]
),
);
}
}
类 WebView2 扩展了 StatefulWidget {
最终字符串 urlVal;
WebView2({Key key, @required this.urlVal}) : super(key: key);
@覆盖
_WebView2State createState() => _WebView2State();
}
类 _WebView2State 扩展状态 {
@覆盖
小部件构建(BuildContext 上下文){
返回 MaterialApp(
主页: 脚手架(
正文:堆栈(
孩子们: [
SimplePdfViewerWidget(
完成回调:(布尔结果){
print("completeCallback,result:${result}");
},
初始网址:widget.urlVal,
),
对齐(
对齐:Alignment.bottomCenter,
孩子:SizedBox(
宽度:330,
孩子:凸起按钮(
onPressed: () => Navigator.of(context).pop(),
孩子:const Text('Close', style:TextStyle(fontSize:20)),
textColor: Colors.white,
颜色:Colors.blue,
海拔:5
),
)
)
]
)
),
);
}
}
您正在Navigator.pushReplacement()第一WebView个小部件中使用。因此,当您尝试弹出第二个时WebView,没有要显示的小部件。而不是使用Navigator.pushReplacement()尝试使用Navigator.push()
| 归档时间: |
|
| 查看次数: |
847 次 |
| 最近记录: |