Flutter基础控件:BottomNavigationBar

属性

onTap

点击Item回调事件

currentIndex

当前选择的item下标

elevation

阴影

type

bar 类型:fixed,shifting

Flutter的BottomNavigationBar如果不指定type,则当items小于4个时,类型是fixed,大于或等于4个时,自动变成了shifting

fixedColor

BottomNavigationBar.type为fixed设置fixedColor颜色

backgroundColor

整体背景色

iconSize

Item中图片大小

selectedItemColor

被选择item颜色

unselectedItemColor

未被选择item颜色

selectedIconTheme

被选择icon题主颜色

unselectedIconTheme

未被选择icon题主颜色

selectedFontSize

被选择item字体大小

unselectedFontSize

未被选择item字体大小

selectedLabelStyle

被选择item 文字风格

unselectedLabelStyle

未被选择item 文字风格

showSelectedLabels

被选中的item显示文字,未被选中的item不显示文字

showUnselectedLabels

未被选中的item显示文字,被选中的item不显示文字

void main() => runApp(new MyApp());

//StatelessWidget 无状态widget
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'welcome',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('首页'),
        ),
        body: new Center(
          child: new IconButton(
            icon: new Icon(Icons.volume_up),
            tooltip: 'Increase volume by 10%',
            onPressed: () {
              // ...
            },
          ),
        ),
        bottomNavigationBar: new BottomNavigationWidget(),
      ),
    );
  }
}

class BottomNavigationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => BottomNavigationWidgetState();
}

class BottomNavigationWidgetState extends State<BottomNavigationWidget> {
  int _currentIndex = 0;

  List<BottomNavigationBarItem> _barItem = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('新闻')),
    BottomNavigationBarItem(icon: Icon(Icons.people), title: Text('我的')),
    BottomNavigationBarItem(icon: Icon(Icons.phone), title: Text('隐私')),
  ];

  @override
  Widget build(BuildContext context) {
    return new BottomNavigationBar(
      items: _barItem,
      currentIndex: _currentIndex,
      onTap: (int index) {
        setState(() {
          _currentIndex = index;
        });
      },
      selectedItemColor: Colors.amber[800],
      unselectedItemColor: Colors.grey,
      selectedFontSize: 12.0,
      type: BottomNavigationBarType.fixed,
    );
  }
}
Flutter是一种跨平台的移动应用程序开发框架,它提供了丰富的UI控件来构建应用的用户界面。 Flutter的UI控件可以分为基础控件和组合控件两种类型。 基础控件包括Text、Image、Button、TextField、Checkbox等常用的用户界面元素。这些控件可用于构建最基本的用户界面,例如显示文本、图片、处理用户输入等。开发者可以通过自定义这些控件的属性和样式来满足应用需求。 组合控件可以由多个基础控件组合而成,以实现更复杂和功能更强大的用户界面。例如,开发者可以将多个基础控件嵌套在一起,创建出自定义的界面模块。Flutter提供了丰富的组合控件,例如ListView(列表视图)、GridView(网格视图)、AppBar(应用栏)、BottomNavigationBar(底部导航栏)等,开发者可以根据应用需求选择合适的组合控件。 除了基础控件和组合控件Flutter还提供了一些特殊的UI控件,用于处理特定场景的用户交互。例如,Flutter提供了Dialog(对话框)控件,用于显示弹出窗口,让用户进行选择或提供提示信息。Flutter还提供了SnackBar(消息提示条)控件,用于在屏幕底部显示临时的消息提示。 总结来说,Flutter提供了丰富多样的UI控件,开发者可以根据应用需求选择合适的控件来构建漂亮和交互性强的移动应用程序界面。无论是基础控件还是组合控件Flutter都提供了详细的文档和示例代码,方便开发者学习和使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值