码迷,mamicode.com
首页 > 其他好文 > 详细

flutter 底部导航栏 BottomNavigationBar

时间:2021-01-21 10:38:16      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:idg   lis   ons   tap   导航栏   底部导航   视频   消息   actions   

话不多说,上代码

import ‘package:flutter/material.dart‘;
import ‘package:flutter_zhihu/pages/tabs/homeTab.dart‘;

class TabsController extends StatefulWidget {
  @override
  _TabsControllerState createState() => _TabsControllerState();
}

class _TabsControllerState extends State<TabsController> {

  int _currentIndex = 0;
  final pages = [HomeTab(),HomeTab(),HomeTab(),HomeTab(),HomeTab()];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(‘标题‘),
        actions: [
          IconButton(icon: Icon(Icons.search), onPressed: (){
            print(‘惦记了搜索‘);
          })
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: bottomNavItems,//配置底部菜单
        currentIndex: _currentIndex,//当前菜单在第几个
        onTap: (index){
        //菜单切换事件 _changePage(index); }, type: BottomNavigationBarType.fixed,//菜单切换效果 ), body: pages[_currentIndex],//菜单页面切换 ); }
 //定义底部菜单
final List<BottomNavigationBarItem> bottomNavItems = [ BottomNavigationBarItem( backgroundColor: Colors.blue, icon: Icon(Icons.home), label: ‘首页‘, ), BottomNavigationBarItem( backgroundColor: Colors.green, icon: Icon(Icons.message), label: ‘视频‘, ), BottomNavigationBarItem( backgroundColor: Colors.amber, icon: Icon(Icons.shopping_cart), label: ‘会员‘, ), BottomNavigationBarItem( backgroundColor: Colors.red, icon: Icon(Icons.person), label: ‘消息‘, ), BottomNavigationBarItem( backgroundColor: Colors.red, icon: Icon(Icons.person), label: ‘我的‘, ), ]; /*切换页面*/ void _changePage(int index) { /*如果点击的导航项不是当前项 切换 */ if (index != _currentIndex) { setState(() { _currentIndex = index; }); } } }

 

flutter 底部导航栏 BottomNavigationBar

标签:idg   lis   ons   tap   导航栏   底部导航   视频   消息   actions   

原文地址:https://www.cnblogs.com/zhouyong0330/p/14303714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!