Flutter 颤振-如何从底部导航栏移除衬垫?
我在颤振应用程序中使用BottomNavigationBar。我对外观有额外的要求,这是我得到的结果。除了顶部和底部填充物(图中的箭头)外,一切都很好 这是我的代码:Flutter 颤振-如何从底部导航栏移除衬垫?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我在颤振应用程序中使用BottomNavigationBar。我对外观有额外的要求,这是我得到的结果。除了顶部和底部填充物(图中的箭头)外,一切都很好 这是我的代码: BottomNavigationBar( selectedFontSize: 0, type: BottomNavigationBarType.fixed, currentIndex: currIndex, items: tabs.map((e) { return BottomNavi
BottomNavigationBar(
selectedFontSize: 0,
type: BottomNavigationBarType.fixed,
currentIndex: currIndex,
items: tabs.map((e) {
return BottomNavigationBarItem(
title: SizedBox.shrink(),
icon: _buildIcon(e),
);
}).toList(),
)
Widget _buildIcon(Data data) {
return Container(
width: double.infinity,
height:kBottomNavigationBarHeight ,
child: Material(
color: _getBackgroundColor(data.index),
child: InkWell(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.email_outlined),
Text('111', style: TextStyle(fontSize: 12, color: Colors.white)),
],
),
onTap: () {
onTabSelected(data.index);
},
),
),
);
}
BottomNavigationBar(
selectedFontSize:0,
类型:BottomNavigationBarType.fixed,
currentIndex:currentIndex,
项目:制表符。地图((e){
返回底部导航BarItem(
标题:SizedBox.shrink(),
图标:_buildIcon(e),
);
}).toList(),
)
小部件构建图标(数据){
返回容器(
宽度:double.infinity,
高度:kBottomNavigationBarHeight,
儿童:材料(
颜色:_getBackgroundColor(数据索引),
孩子:InkWell(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标(图标、电子邮件),
文本('111',样式:TextStyle(字体大小:12,颜色:Colors.white)),
],
),
onTap:(){
(数据索引);
},
),
),
);
}
我怎样才能去掉上面和下面的衬垫?任何想法我都将不胜感激。我使用您的零件代码制作了一个示例代码。
但是我不能像你一样复制你的代码共享问题。
你能分享Scaffold底部导航栏的一部分或其他与代码相关的内容吗。
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=0;
void _incrementCounter(){
设置状态(){
_计数器++;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
正文(
“您已经按了这么多次按钮:”,
),
正文(
“$”计数器“,
样式:Theme.of(context).textTheme.display1,
),
],
),
),
底部导航栏:底部导航栏(
selectedFontSize:0,
类型:BottomNavigationBarType.fixed,
当前索引:0,
项目:[
新海底导航气压计(
图标:_buildIcon(),
标题:SizedBox.shrink(),
),
新海底导航气压计(
图标:_buildIcon(),
标题:SizedBox.shrink(),
),
新海底导航气压计(
图标:_buildIcon(),
标题:SizedBox.shrink(),
)
]));
}
小部件_buildIcon(){
返回容器(
宽度:double.infinity,
高度:kBottomNavigationBarHeight,
儿童:材料(
颜色:颜色。灰色,
孩子:InkWell(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标(图标、电子邮件),
文本('111',样式:TextStyle(字体大小:12,颜色:Colors.white)),
],
),
onTap:(){},
),
),
);
}
}
谢谢。我尝试了不同的选择,但是。。。我想键是selectedFontSize:0,
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
bottomNavigationBar: BottomNavigationBar(
selectedFontSize: 0,
type: BottomNavigationBarType.fixed,
currentIndex: 0,
items: [
new BottomNavigationBarItem(
icon: _buildIcon(),
title: SizedBox.shrink(),
),
new BottomNavigationBarItem(
icon: _buildIcon(),
title: SizedBox.shrink(),
),
new BottomNavigationBarItem(
icon: _buildIcon(),
title: SizedBox.shrink(),
)
]));
}
Widget _buildIcon() {
return Container(
width: double.infinity,
height: kBottomNavigationBarHeight,
child: Material(
color: Colors.grey,
child: InkWell(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.email_outlined),
Text('111', style: TextStyle(fontSize: 12, color: Colors.white)),
],
),
onTap: () {},
),
),
);
}
}