话不多说,上代码

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的更多相关文章

  1. Flutter 底部导航栏bottomNavigationBar

    实现一个底部导航栏,包含3到4个功能标签,点击对应的导航标签可以切换到对应的页面内容,并且页面抬头显示的内容也会跟着改变. 实际上由于手机屏幕大小的限制,底部导航栏的功能标签一般在3到5个左右,如果太 ...

  2. Android------底部导航栏BottomNavigationBar

    Android 的底部导航栏 BottomNavigationBar 由Google官方Material design中增加的. Android底部导航栏的实现方式特别多,例如TabHost,TabL ...

  3. Flutter - BottomNavigationBar底部导航栏切换后,状态丢失

    如果你用过BottomNavigationBar.TabBar.还有Drawer,你就会发现,在切换页面之后,原来的页面状态就会丢失. 要是上一页有一个数据列表,很多数据,你滚动到了下头,切换页面后, ...

  4. Flutter——BottomNavigationBar组件(底部导航栏组件)

    BottomNavigationBar常用的属性: 属性名 说明 items List<BottomNavigationBarItem> 底部导航条按钮集合 iconSize icon c ...

  5. 【Flutter学习】基本组件之BottomNavigationBar底部导航栏

    一,概述 BottomNavigationBar即是底部导航栏控件,显示在页面底部的设计控件,用于在试图切换,底部导航栏包含多个标签.图标或者两者搭配的形式,简而言之提供了顶级视图之间的快速导航. 二 ...

  6. Flutter - 创建底部导航栏

    之前写过的一篇文章介绍了 Flutter - 创建横跨所有页面的侧滑菜单, 这次就一起来学习一下底部导航栏. 底部导航栏在ios平台上非常常见,app store就是这样的风格.还有就是大家最常用的微 ...

  7. Flutter移动电商实战 --(4)打通底部导航栏

    关于界面切换以及底栏的实现可参考之前写的一篇文章:Flutter实 ViewPager.bottomNavigationBar界面切换 1.新建4个基本dart文件 在pages目录下,我们新建下面四 ...

  8. Flutter移动电商实战 --(3)底部导航栏制作

    1.cupertino_IOS风格介绍 在Flutter里是有两种内置风格的: material风格: Material Design 是由 Google 推出的全新设计语言,这种设计语言是为手机.平 ...

  9. 底部导航栏使用BottomNavigationBar

    1.github地址 https://github.com/zhouxu88/BottomNavigationBar 2.基本使用 2,1添加依赖 implementation 'com.ashokv ...

  10. Flutter实战视频-移动电商-03.底部导航栏制作

    03.底部导航栏制作 material是谷歌退出的 还有另外的一种:cupertino是IOS的风格 我们底部的导航栏,静态的widget是不合适的,这垃圾我们用到动态的widget 这重新改成动态的 ...

随机推荐

  1. sql 字段分割函数 + 查询

    结果: 用于解决  这种 字段的查询 1.先创建分割函数 => 复制到数据库直接执行 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* by ...

  2. 实验一-Password engine-加密API研究

    加密API研究 181210 一.列举API在编程中的使用方式 GMT 0016-2012 类型定义 typedef struct Struct_DEVINFO{ VERSION Version; C ...

  3. oracle job的使用

    select job, next_date, next_sec, failures, broken from user_jobs; create or replace sequence END_RES ...

  4. GO 语言中的 sync Map

    为什么需要 sync map go 语言之所以引入 sync.Map主要是因为GO 语言自带的 map 是线程不安全的.只能保证并发的读,但是不能保证并发的写. 看下面的例子: func main() ...

  5. uml类图中的+,-,#符号的含义

    描述类的属性的可见性: UML中,可见性分为4级 1.public 公用的 :用+ 前缀表示 ,该属性对所有类可见 2.protected 受保护的:用 # 前缀表示,对该类的子孙可见 3.priva ...

  6. 实验1task5

    <实验结论> #include <stdio.h> #include <stdlib.h> int main() { float a,b,c; printf(&qu ...

  7. 3-MIRO发票校验设置默认税码-OMR2

  8. Dell CS24-SC 服务器详情

    详情介绍: https://www.viziotech.com/servers/58-dell-cs24-sc-dual-xeon-quad-core-l5420-25ghz-16gb-4x146gb ...

  9. echarts学习

    一.安装与引入 1.安装npm install echarts --save 2.引入import * as echarts from 'echarts';(main.js里全局引入) 二.详细概念 ...

  10. Android组件化开发-----页面路由(ARouter)

    平时开发中,我们经常用到页面跳转功能.之前我一直使用Intent过跳转 Intent intent = new Intent(A.this, B.class); intent.putExtra(&qu ...