flutter - 如何将简单的条形图添加到底部导航栏
问题描述
如何从以下颤振示例中将条形图添加到底部导航栏中的业务按钮?我是否需要在 lib 文件夹下创建两个不同的 dart 文件,或者我只是在 main.dart 文件中添加图表?
试过了
BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
Stack(
children:<Widget>[
width:100,
height:100,
color: Colors.red,
),
Container(
width:90,
height:90,
color: Colors.green,
),
],
),
label: 'Business',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
],
解决方案
你不能用那个例子在这里添加任何复杂的东西。您可以在 Icon 下使用 Stack ,然后添加另一个小部件,即带有子容器的容器,并按照您想要的方式填充它。
但是,在处理屏幕方面,Flutter 确实很棒。您可以根据需要简单地创建自己的底部导航栏。只需将小部件传递给 bottomNavigationBar 并以您想要的任何方式创建它。
Scaffold(
bottomNavigationBar: Container(height: 100, color: Colors.red),
然后你可以用你通常做的任何方式创建小部件。
编辑:
这将是确切的解决方案:)
BottomNavigationBar(items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
label: 'Business',
icon: Container(
height: 32,
width: 50,
child: Stack(children: [
Container(
alignment: Alignment.topCenter,
child: Icon(Icons.business, size: 24),
),
Positioned(
top: 28,
child: Container(
width: 50,
height: 3,
color: Colors.red,
),
),
Positioned(
top: 28,
child: Container(
width: 40,
height: 3,
color: Colors.green,
),
),
]),
),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
]),
推荐阅读
- c# - 服务总线主题插入了相同 MessageId 的重复消息记录
- python - 使用 Holoviews 的 TreeMaps
- ios - 如何在不点击横幅或显示通知之前访问推送通知响应?
- powershell - 我有 2 个关于 powershell 和 IIS 的问题
- dynamics-crm - 如何在 Dynamic CRM365 视图中访问我的网格
- javascript - ScrollView 中的自动滚动 react-native
- graph - 图论(图可以划分为两棵树时的顶点度)
- c# - 将 ASC 文件读取与视频帧同步,没有任何共同值
- xml - Groovy XmlSlurper 将 " 添加到所有值
- java - ArangoDB、Java、Velocypack 错误尝试反序列化 DBEntity