flutter - 同时颤动底部和垂直导航选项卡
问题描述
我想使用 Flutter 创建一个带有垂直和底部导航选项卡的屏幕,我测试了 2 种方法:
- 第一个是制作底部和顶部选项卡,然后旋转顶部使其垂直,结果是垂直选项卡填满整个屏幕。
- 第二个是使用带有vertical_tabs包的底部导航,在这种情况下我无法使用底部标签进行导航
解决方案
这是执行此操作的一种方法。我不确定这是否是最好的方法,但它有效。在底部,我使用的是 BottomNavigationBar,而对于垂直我使用的是 TabBar(您可以选择其他任何内容或您自己的自定义视图)。
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
var _bottomBarIndex = 0;
String title = "Screen 0";
TabController _tabController;
@override
void initState() {
_tabController = TabController(initialIndex: 0, length: 3, vsync: this);
_tabController.addListener(() {
switch (_tabController.index) {
case 0:
{
setState(() {
title = "Profile";
});
break;
}
case 1:
{
setState(() {
title = "Done";
});
break;
}
case 2:
{
setState(() {
title = "DashBoard";
});
break;
}
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: <Widget>[
RotatedBox(
quarterTurns: 1,
child: TabBar(
controller: _tabController,
tabs: <Widget>[
getItem(
icon: Icon(
Icons.person,
color: Colors.black,
),
text: Text(
"Profile",
style: TextStyle(color: Colors.black),
),
),
getItem(
icon: Icon(
Icons.done,
color: Colors.black,
),
text: Text(
"Done",
style: TextStyle(color: Colors.black),
),
),
getItem(
icon: Icon(
Icons.dashboard,
color: Colors.black,
),
text: Text(
"Dashboard",
style: TextStyle(color: Colors.black),
),
),
],
),
),
Expanded(
child: NewScreen(
title: title,
),
)
],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _bottomBarIndex,
onTap: (index) {
setState(() {
_bottomBarIndex = index;
title = "Screen $index";
});
},
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(icon: Icon(Icons.add), title: Text('Add')),
BottomNavigationBarItem(
icon: Icon(Icons.search), title: Text('Search')),
],
),
);
}
Widget getItem({Icon icon, Text text}) {
return RotatedBox(
quarterTurns: -1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[icon, text],
),
);
}
}
class NewScreen extends StatelessWidget {
const NewScreen({this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
title,
style: TextStyle(color: Colors.black, fontSize: 20.0),
),
),
);
}
}
推荐阅读
- java - 如何从 OAuth2 客户端应用程序中的授权服务器获取属于访问令牌响应的一部分的附加信息
- python-3.x - 如何为 scipy 最小化例程创建可调用的雅可比函数?
- macos - 插件中缺少 QT printsupport lib - 如何获取它?
- javascript - 如何将多个对象合并/组合成数组
- oracle - 唯一约束检查
- node.js - 读取智能卡时出现 ERR_SSL_CLIENT_AUTH_SIGNATURE_FAILED
- intellij-idea - 2019.2.3升级到2019.3后,在Intellij Debugger中运行kotlin卡在Collection data中
- amazon-cloudformation - 查询字符串中的替换变量
- c# - AuthorizeAttribute 上的 C# 线程安全 CreateIdentityAsync
- biztalk - 计算 BizTalk 业务流程中文件夹中的文件数