4.flutter_demo之底部栏

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title:'Flutter Demo',
        theme: ThemeData.light(),
        home: LXTabBar(),
    );
  }
}

class LXTabBar extends StatefulWidget {
  @override
  _LXTabBarState createState() => _LXTabBarState();
}

class _LXTabBarState extends State<LXTabBar> {

  final _tabBarColor = Colors.blue;
  int _currentIndex = 0;
  List<Widget> list = List();

  @override
  void initState() {
    list..add(HomePage())..add(ChatPage())..add(MinePage());
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: list[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon:Icon(Icons.home, color: _tabBarColor),
              title: Text('首页', style: TextStyle(color: _tabBarColor))
          ),
          BottomNavigationBarItem(
              icon:Icon(Icons.chat, color: _tabBarColor),
              title: Text('消息', style: TextStyle(color: _tabBarColor))
          ),
          BottomNavigationBarItem(icon:Icon(Icons.person, color: _tabBarColor),
              title: Text('我的', style: TextStyle(color: _tabBarColor))
          )
        ],
        currentIndex: _currentIndex,
        onTap: (int index){
          setState(() {
            _currentIndex = index;
          });
        },
      )
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('首页'),),
      body: Center(child: Text('homePage'),)
    );
  }
}

class ChatPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('会话'),),
        body: Center(child: Text('chatPage'),)
    );
  }
}

class MinePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('我的'),),
        body: Center(child: Text('minePage'),)
    );
  }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值