android - 使用底部导航栏浏览网页视图
问题描述
我在 Flutter 应用程序中使用Flutter Web View Plugin。在我的应用程序中,webview
它运行良好并使用设备后退按钮导航到后页(当然在 Android 上)。我添加了一个BottomNavigation
栏,让用户通过webview
使用导航栏进行导航。
网络视图类:
class webView extends StatelessWidget {
final String url;
final String title;
webView({Key key, @required this.url, @required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme
: new ThemeData(
primaryColor: Color.fromRGBO(58, 66, 86, 1.0), fontFamily: 'Raleway'),
routes: {
"/": (_) => new WebviewScaffold(
url: url,
appBar: new AppBar(
title: Text(title),
actions: <Widget>[
IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(null),
)
],
),
withJavascript: true,
withLocalStorage: true,
appCacheEnabled: true,
hidden: true,
initialChild: Container(
child: const Center(
child: CircularProgressIndicator(),
),
),
bottomNavigationBar: bmnav.BottomNav(
index: 0,
labelStyle: bmnav.LabelStyle(visible: false),
items: [
bmnav.BottomNavItem(Icons.arrow_back_ios),
bmnav.BottomNavItem(Icons.home),
bmnav.BottomNavItem(Icons.arrow_forward_ios)
],
),
)
},
);
}
}
如何webview
使用此导航栏进行导航。有没有内置函数可以使用?请帮忙。
解决方案
初始化index
导航。
1. int currentTab = 0;
2.更新bottomNavigationBar
:
bottomNavigationBar: bmnav.BottomNav(
index: currentTab,
onTap: (i) {
splitScreen(i);
},
labelStyle: bmnav.LabelStyle(showOnSelect: true),
items: [
bmnav.BottomNavItem(Icons.arrow_back_ios, label: 'Back'),
bmnav.BottomNavItem(Icons.refresh, label: 'Reload'),
bmnav.BottomNavItem(Icons.arrow_forward_ios, label: 'Forward')
],
),
3.最后,阅读index
并导航webView
:
void _splitScreen(int i) {
switch (i) {
case 0:
flutterWebviewPlugin.goBack();
break;
case 1:
flutterWebviewPlugin.reload();
break;
case 2:
flutterWebviewPlugin.goForward();
break;
}
}
您可以在此处阅读文档。
推荐阅读
- jhipster - JHipster Registry v3.3.0 上的微服务状态已关闭
- android - 领域迁移错误“已添加属性‘x’”
- php - 我在一个寻呼机上有一个选择标签,我希望在选择某个选项时出现另一个选择标签
- javascript - 如何通过字符串中的数据属性获取元素并在 node.js 应用程序中获取内部文本?
- python - 从字符串中提取姓名和号码
- javascript - 名为“[DEFAULT]”的 Firebase 应用程序已存在 REACT
- directx - 使用 D2D 渲染文本
- node.js - promise.then 在异步 lambda 处理程序中不起作用
- docker - python + mysql - 通过 docker-compose 创建
- java - 找不到局部变量,这是一个公共类