Unity_UIWidgets学习笔记09_组件BottomNavigationBar

参考地址 https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html

1、

 public BottomNavigationBar(
            Key key = null,
            List items = null,//所有子项目
            ValueChanged<int> onTap = null,//点击
            int currentIndex = 0,//当前选择索引
            BottomNavigationBarType? type = null,//不清楚有
            Color fixedColor = null,
            float iconSize = 24.0f//图标大小
        )
public BottomNavigationBarItem(
            Widget icon = null,//图标
            Widget title = null,//变态
            Widget activeIcon = null,//激活图标
            Color backgroundColor = null//背景色
        )

2、例子

int selectedIndex = 0;
    TextStyle optionStyle = new TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
    List widgetOptions
    {
        get
        {
            return new List{
            new Text(
                "Index 0: Home",
                style: optionStyle
            ),
            new Text(
                "Index 1: Business",
                style: optionStyle
            ),
            new  Text(
                "Index 2: School",
                style: optionStyle
            ),
        };

        }
    }
    void onItemTapped(int index)
    {
        setState(() =>
        {
            selectedIndex = index;
        });
    }
public override Widget build(BuildContext context)
    {
        return new Scaffold(
          appBar: new AppBar(
          title: new Text("BottomNavigationBar Sample")
          ),
          body: new Center(
          child: widgetOptions[selectedIndex]
          ),
          bottomNavigationBar: new BottomNavigationBar(
          items: new List(){
               new  BottomNavigationBarItem(
                icon: new Icon(Icons.home),
                title:new  Text("Home")
                ),
               new  BottomNavigationBarItem(
                icon: new Icon(Icons.business),
                title:new  Text("Business")
                ),
               new  BottomNavigationBarItem(
                icon: new Icon(Icons.school),
                title: new Text("School")
                ),
          },
          currentIndex: selectedIndex,
          onTap: onItemTapped
          )
      );

    }

 

转载于:https://www.cnblogs.com/PandaHome/p/11114131.html

你可能感兴趣的:(Unity_UIWidgets学习笔记09_组件BottomNavigationBar)