Flutter实现底部导航栏效果
作者:BrodyWu 时间:2022-03-28 05:41:46
大家最近都在讨论新鲜技术-flutter,小编也在学习中,遇到大家都遇到的问题,底部导航。下面给大家贴出底部导航的编写,主要参考了lime这个项目。
上代码
一.在main.dart文件中
定义APP的基本信息
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: themeColor(),
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
其中主要代码部分
class _MyHomePageState extends State<MyHomePage> {
PageController pageController;
int page = 0;
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.grey,
body: new PageView(
children: [
new Index(),
new Classify(),
new Shopping(),
new Myself()
],
controller: pageController,
onPageChanged: onPageChanged
),
bottomNavigationBar: new BottomNavigationBar(items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.laptop_chromebook),
title: new Text("主页"),
backgroundColor: Colors.grey
),
new BottomNavigationBarItem(
icon: new Icon(Icons.list), title: new Text("分类"),backgroundColor: Colors.grey),
new BottomNavigationBarItem(
icon: new Icon(Icons.local_grocery_store), title: new Text("购物车")),
new BottomNavigationBarItem(icon: new Icon(Icons.person), title: new Text("我的"))
],
onTap: onTap,
currentIndex: page
),
);
}
@override
void initState() {
super.initState();
pageController = new PageController(initialPage: this.page);
}
void onTap(int index) {
pageController.animateToPage(
index, duration: const Duration(milliseconds: 300),
curve: Curves.ease);
}
void onPageChanged(int page) {
setState(() {
this.page = page;
});
}
}
其中,各个页面的主要声明
底部导航栏的内容填充
二.其他四个页面的主要代码
import 'package:flutter/material.dart';
class Classify extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
body: new Center(
child:
new Text("分类"),
),
);
}
}
其他3个页面的代码是一样的,具体逻辑由需求去填写
三.效果图
来源:https://blog.csdn.net/u011045726/article/details/79583423
标签:Flutter,导航栏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
javaweb中Http协议详解
2022-03-21 05:12:41
![](https://img.aspxhome.com/file/2023/8/82998_0s.png)
Java8 Stream教程之collect()的技巧
2023-05-01 00:45:15
![](https://img.aspxhome.com/file/2023/7/61507_0s.png)
C# 通过 oledb 操作Excel实例代码
2022-12-22 04:27:49
java通过JFrame做一个登录系统的界面完整代码示例
2023-11-06 05:18:32
![](https://img.aspxhome.com/file/2023/0/110860_0s.png)
如何随机选取一个机器的ip
2022-03-01 12:20:43
Android软键盘弹出时的界面控制方法
2022-10-26 03:37:43
详解JavaWeb中的 Listener
2023-09-04 08:09:24
![](https://img.aspxhome.com/file/2023/5/110835_0s.png)
Java单例模式分析
2023-11-16 03:17:06
Maven构建时跳过部分测试的实例
2022-08-30 03:42:50
Android HorizontalScrollView滑动与ViewPager切换案例详解
2023-06-05 00:48:27
Java之单例模式实现方案详解
2022-02-15 19:02:29
实战SpringBoot集成JWT实现token验证
2022-10-07 15:57:49
![](https://img.aspxhome.com/file/2023/8/62138_0s.jpg)
C#删除只读文件或文件夹(解决File.Delete无法删除文件)
2022-06-30 15:01:59
Mybatis Plus中的流式查询案例
2023-08-18 16:35:13
流式图表拒绝增删改查之kafka核心消费逻辑上篇
2023-04-19 03:32:11
Netty组件NioEventLoopGroup创建线程执行器源码解析
2022-03-07 00:36:17
![](https://img.aspxhome.com/file/2023/5/98115_0s.png)
C++ pair的用法案例详解
2021-09-21 01:40:20
![](https://img.aspxhome.com/file/2023/1/124021_0s.png)
C#的正则表达式Regex类使用简明教程
2021-11-16 12:47:32
对Java的面对对象编程中对象和引用以及内部类的理解
2022-02-22 12:11:15
C#自定义签名章实现方法
2022-08-02 05:22:37