【问题标题】:Web view page is empty if clicks the back arrow in flutter?如果单击颤动中的后退箭头,网页视图页面为空?
【发布时间】:2020-05-19 20:32:11
【问题描述】:
我有一个带有多个链接的WebView 页面。通过单击链接,它将打开另一个带有关闭按钮的WebView 页面。如果我单击关闭按钮,当前窗口应该关闭并且WebView 页面不应该重新加载。我尝试使用onPressed: () => Navigator.of(context).pop(),但它显示WebView 页面为空。请帮助解决这个问题。
班长扩展 StatelessWidget {
@覆盖
小部件构建(BuildContext 上下文){
返回材料应用程序(
标题:“颤振演示”,
主题:主题数据(
primarySwatch:颜色.蓝色,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
类 MyHomePage 扩展 StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
最终字符串标题;
@覆盖
_MyHomePageState createState() => _MyHomePageState();
}
类 _MyHomePageState 扩展状态 {
@覆盖
小部件构建(BuildContext 上下文){
返回脚手架(
正文:堆栈(
孩子们: [
网页视图(
initialUrl: '网页浏览网址',
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (NavigationRequest 请求) {
打印(request.url);
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 上下文){
返回材料应用程序(
家:脚手架(
正文:堆栈(
孩子们: [
SimplePdfViewerWidget(
完成回调:(布尔结果){
print("completeCallback,result:${result}");
},
初始网址:小部件.urlVal,
),
对齐(
对齐:Alignment.bottomCenter,
孩子:大小框(
宽度:330,
孩子:RaisedButton(
onPressed: () => Navigator.of(context).pop(),
孩子:常量文本('关闭',样式:TextStyle(字体大小:20)),
文本颜色:颜色.白色,
颜色:颜色.蓝色,
海拔:5
),
)
)
]
)
),
);
}
}
【问题讨论】:
-
-
@SelimKundakçıoğlu 我已经添加了代码。请检查
标签:
flutter
dart
flutter-layout