Flutter

Flutter -- 4.项目主要组织架构分析

2021-11-03  本文已影响0人  MissStitch丶

1.MaterialApp

class App extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ScaffoldBar(),
      theme: ThemeData(
          primarySwatch: Colors.grey, //可以影响导航颜色
          splashColor: Color.fromARGB(0, 0, 0, 0), //切换BarItem时,弹开时的颜色
          highlightColor: Color.fromARGB(0, 0, 0, 0) //切换BarItem时,按下时的颜色
      ),
    );
  }
}

2.Scaffold

class ScaffoldBar extends StatefulWidget {

  @override
  _ScaffoldBarState createState() => _ScaffoldBarState();
}

class _ScaffoldBarState extends State<ScaffoldBar> {

  int _currentIndex = 0;

  List<Widget> _bodys = [
    ChatPage(),
    FriendsPage(),
    DiscoverPage(),
    MinePage()
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _bodys[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        fixedColor: Colors.green,
        currentIndex: _currentIndex,
        selectedFontSize: 12,
        items: [
          BottomNavigationBarItem(
              icon: Image.asset('images/tabbar_chat.png', width: 20,height: 20,),
              activeIcon: Image(image: AssetImage('images/tabbar_chat_hl.png'), width: 20,height: 20,),
              label: '微信'
          ),
          BottomNavigationBarItem(
              icon: Image.asset('images/tabbar_friends.png', width: 20,height: 20,),
              activeIcon: Image(image: AssetImage('images/tabbar_friends_hl.png'), width: 20,height: 20,),
              label: '通讯录'
          ),
          BottomNavigationBarItem(
              icon: Image.asset('images/tabbar_discover.png', width: 20,height: 20,),
              activeIcon: Image(image: AssetImage('images/tabbar_discover_hl.png'), width: 20,height: 20,),
              label: '发现'
          ),
          BottomNavigationBarItem(
              icon: Image.asset('images/tabbar_mine.png', width: 20,height: 20,),
              activeIcon: Image(image: AssetImage('images/tabbar_mine_hl.png'), width: 20,height: 20,),
              label: '我'
          ),
        ],
        onTap: (int index){
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}

3.AppBar

AppBar(
        title: Text('Hello Flutter'),
        backgroundColor: ThemeColor,
        actions: [
          GestureDetector(
            child: Container(
              child: Image.asset('images/image.png', width: 20, height: 20,),
              margin: EdgeInsets.only(right: 10),
            ),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => DiscoverDetailPage(title: '通讯录搜索')));
            },
          )
        ],
      )
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => DiscoverDetailPage(title: '通讯录搜索')))
上一篇 下一篇

猜你喜欢

热点阅读