Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 颤振/省道:自定义底部导航栏高度_Dart_Flutter_Material Ui - Fatal编程技术网

Dart 颤振/省道:自定义底部导航栏高度

Dart 颤振/省道:自定义底部导航栏高度,dart,flutter,material-ui,Dart,Flutter,Material Ui,有没有办法自定义底部导航栏的高度 我目前有一个BottomNavigationBar,带有选项卡,可以点击/滑动导航,但是默认高度(即使在减少文本和图标后)太高 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.blue, title: Text( 'RefLog', style: Styles.headerLarge

有没有办法自定义
底部导航栏的高度

我目前有一个
BottomNavigationBar
,带有选项卡,可以点击/滑动导航,但是默认高度(即使在减少文本和图标后)太高

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    backgroundColor: Colors.blue,
    title: Text( 'RefLog', style: Styles.headerLarge ),
    actions: <Widget>[
      new IconButton(
        icon: Icon(Icons.list),
        onPressed: () {},
      )
    ],
  ),
  body: DefaultTabController(
    length: 3,
    child: Scaffold(
      body: TabBarView(
        children: _children,
      ),
      bottomNavigationBar: TabBar(
        tabs: [
          Tab( text: 'One', icon: Icon(Icons.import_contacts, size: 20.0) ),
          Tab( text: 'Two', icon: Icon(Icons.restaurant, size: 20.0) ),
          Tab( text: 'Three', icon: Icon(Icons.record_voice_over, size: 20.0) ),
        ],
        labelStyle: TextStyle(fontSize: 12.0),
        labelColor: Colors.white,
        unselectedLabelColor: Colors.white30,
        indicatorSize: TabBarIndicatorSize.label,
        indicatorColor: Colors.white,
      ),
      backgroundColor: Colors.blue,
    ),
  ),
 );
}
@覆盖
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:Colors.blue,
标题:文本('RefLog',style:Styles.headerLarge),
行动:[
新图标按钮(
图标:图标(Icons.list),
按下:(){},
)
],
),
正文:DefaultTabController(
长度:3,
孩子:脚手架(
正文:选项卡视图(
儿童:_儿童,
),
底部导航栏:选项卡栏(
选项卡:[
选项卡(文本:“一”,图标:图标(Icons.import_contacts,大小:20.0)),
选项卡(文本:“两个”,图标:图标(Icons.restaurant,大小:20.0)),
选项卡(文本:“三”,图标:图标(Icons.record\u voice\u over,大小:20.0)),
],
标签样式:文本样式(字体大小:12.0),
labelColor:Colors.white,
未选择的LabelColor:Colors.white30,
indicatorSize:TabBarIndicatorSize.label,
指示颜色:颜色。白色,
),
背景颜色:Colors.blue,
),
),
);
}
有没有办法自定义BottomNavigationBar的高度

没有

为什么?

因为这个小部件的开发人员没有给我们任何控件来使用它

但我怎样才能做到呢

此外,如果要准备自定义
BottomNavBar
,则必须自己处理侦听器。它不仅仅是创建一个包含
图标按钮的
行的
容器

[更新]我说的“不”是指


正如公认的答案中所提到的,可以有变通办法。

我也有同样的问题,
底部导航栏的高度不能被覆盖,我的解决方案是使用
SizedBox
调整图标大小,它确实降低了高度,其他最终解决方案是更新title属性的字体大小,这是我的例子:

new BottomNavigationBarItem(
              icon:new SizedBox(
                child: new IconButton(
                    icon: new Image.asset("assets/images/icon_ar.png"),
                    onPressed: () {}),
                width: 38,
                height: 38,
              ),
              title: new Text("", style: new TextStyle(fontSize: 0),))

我的
BottomNavigationBar
在这两种平台上都有一个大小标准。

您可以创建自己的小部件

 Widget customBottomNavigationBar(BuildContext context){
    double myHeight =100.0;//Your height HERE
    return SizedBox(
    height: myHeight,
    width: MediaQuery.of(context).size.width,
    child:TabBar(
            tabs: [
              Tab( text: 'One', icon: Icon(Icons.import_contacts, size: 20.0) ),
              Tab( text: 'Two', icon: Icon(Icons.restaurant, size: 20.0) ),
              Tab( text: 'Three', icon: Icon(Icons.record_voice_over, size: 20.0) ),
            ],
            labelStyle: TextStyle(fontSize: 12.0),
            labelColor: Colors.white,
            unselectedLabelColor: Colors.white30,
            indicatorSize: TabBarIndicatorSize.label,
            indicatorColor: Colors.white,
          ),
    );
}

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    backgroundColor: Colors.blue,
    title: Text( 'RefLog', style: Styles.headerLarge ),
    actions: <Widget>[
      new IconButton(
        icon: Icon(Icons.list),
        onPressed: () {},
      )
    ],
  ),
  body: DefaultTabController(
    length: 3,
    child: Scaffold(
      body: TabBarView(
        children: _children,
      ),
      bottomNavigationBar: customBottomNavigationBar(context),
      backgroundColor: Colors.blue,
    ),
  ),
);
}
小部件customBottomNavigationBar(构建上下文){
double myHeight=100.0;//此处显示您的身高
返回大小框(
身高:我的身高,
宽度:MediaQuery.of(context).size.width,
孩子:TabBar(
选项卡:[
选项卡(文本:“一”,图标:图标(Icons.import_contacts,大小:20.0)),
选项卡(文本:“两个”,图标:图标(Icons.restaurant,大小:20.0)),
选项卡(文本:“三”,图标:图标(Icons.record\u voice\u over,大小:20.0)),
],
标签样式:文本样式(字体大小:12.0),
labelColor:Colors.white,
未选择的LabelColor:Colors.white30,
indicatorSize:TabBarIndicatorSize.label,
指示颜色:颜色。白色,
),
);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
背景颜色:Colors.blue,
标题:文本('RefLog',style:Styles.headerLarge),
行动:[
新图标按钮(
图标:图标(Icons.list),
按下:(){},
)
],
),
正文:DefaultTabController(
长度:3,
孩子:脚手架(
正文:选项卡视图(
儿童:_儿童,
),
bottomNavigationBar:customBottomNavigationBar(上下文),
背景颜色:Colors.blue,
),
),
);
}

您可以按大小框包装底部导航栏

bottomNavigationBar: SizedBox(height: 58, child: //some widget )

播放selectedfontsize和UnselectedFontSize属性。我将两者都设置为1.0,它似乎减少了导航栏顶部和底部的额外填充,从而降低了导航栏的高度

底部导航栏( iconSize:kIconSize20, selectedFontSize:1.0, 未选择的字体大小:1.0,

看起来高度是硬编码的。如果58的高度"对于小型设备来说太大,或者对于大型设备来说太小?使用MediaQuery获取设备的高度。尝试底部栏的各种高度,看看哪个看起来不错。用设备高度的百分比表示决定的大小。screenHeight*常量=底部导航栏高度。常量=sizeChosen/您使用的设备的屏幕高度d for DecisdingArticle已经不存在了。我学习的越多,Flitter看起来就越糟糕。小部件很复杂而且不灵活。您好!感谢您提出这个问题。另外,如果您觉得Flitter令人畏惧,我建议您选择本机框架(android或iOS)然后在颤振中努力。直接跳入混合框架并没有真正的帮助。:)