美文网首页
Flutter 中底部导航栏 bottomNavigationB

Flutter 中底部导航栏 bottomNavigationB

作者: 喜剧收尾_XWX | 来源:发表于2020-07-28 13:17 被阅读0次
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return MaterialApp(
          title: "底部标签栏",
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key}) : super(key: key);
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      int _selectIndex = 1;
    
      //导航栏中数据
    
      final _widgetOotions = [
        Text('index 0 : 信息'),
        Text('index 1 : 通讯录'),
        Text('index 2 : 发现'),
      ];
    
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return Scaffold(
          appBar: AppBar(
            title: Text('底部导航栏'),
          ),
          body: Center(
            child: _widgetOotions.elementAt(_selectIndex),
          ),
          //底部按钮
          bottomNavigationBar: BottomNavigationBar(
            items: <BottomNavigationBarItem>[
              BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text('信息')),
              BottomNavigationBarItem(
                  icon: Icon(Icons.contacts), title: Text('通讯录')),
              BottomNavigationBarItem(
                  icon: Icon(Icons.access_alarm), title: Text('发现')),
            ],
    
            currentIndex: _selectIndex, //当前选中的索引
            fixedColor: Colors.lightBlue, //选中项的颜色
            onTap: _onItemTapped, //选择按下处理
          ),
        );
      }
    
      void _onItemTapped(int index) {
        setState(() {
          _selectIndex = index;
        });
      }
    }
    
    
    展示图片

    相关文章

      网友评论

          本文标题:Flutter 中底部导航栏 bottomNavigationB

          本文链接:https://www.haomeiwen.com/subject/fodfrktx.html