網站首頁 編程語言 正文
本文實例為大家分享了Flutter自定義底部導航欄的具體代碼,供大家參考,具體內容如下
文件結構:
main.dart
import 'package:flutter/material.dart';
import 'pages/tabs.dart';
?
void main() => runApp(new MyApp());
?
class MyApp extends StatelessWidget {
? @override
? Widget build(BuildContext context) {
? ? return MaterialApp(
? ? ? home: Tabs(),
? ? );
? }
}
tabs.dart
import 'package:flutter/material.dart';
import 'tabs/home.dart';
import 'tabs/category.dart';
import 'tabs/user.dart';
class Tabs extends StatefulWidget {
? Tabs({Key key}) : super(key: key);
? @override
? _TabsState createState() => _TabsState();
}
?
class _TabsState extends State<Tabs> {
? int _currentIndex = 0;
?
? List _pageList=[
? ? HomePage(),
? ? CategoryPage(),
? ? UserPage(),
? ];
?
?
? @override
? Widget build(BuildContext context) {
? ? return Scaffold(
? ? ? appBar: AppBar(
? ? ? ? title: Text('自定義底部導航'),
? ? ? ),
? ? ? body: this._pageList[this._currentIndex],
? ? ? bottomNavigationBar: BottomNavigationBar(
? ? ? ? currentIndex: this._currentIndex,
? ? ? ? onTap: (int index) {
? ? ? ? ? setState(() {
? ? ? ? ? ? this._currentIndex = index;
? ? ? ? ? });
? ? ? ? },
? ? ? ? items: [
? ? ? ? ? BottomNavigationBarItem(
? ? ? ? ? ? icon: Icon(Icons.home),
? ? ? ? ? ? title: Text('首頁'),
? ? ? ? ? ),
? ? ? ? ? BottomNavigationBarItem(
? ? ? ? ? ? icon: Icon(Icons.category),
? ? ? ? ? ? title: Text('分類'),
? ? ? ? ? ),
? ? ? ? ? BottomNavigationBarItem(
? ? ? ? ? ? icon: Icon(Icons.supervised_user_circle),
? ? ? ? ? ? title: Text('會員'),
? ? ? ? ? ),
? ? ? ? ],
? ? ? ),
? ? );
? }
}
home.dart
import 'package:flutter/material.dart';
?
class HomePage extends StatefulWidget {
? HomePage({Key key}) : super(key: key);
?
? @override
? _HomePageState createState() => _HomePageState();
}
?
class _HomePageState extends State<HomePage> {
? @override
? Widget build(BuildContext context) {
? ? return Text('首頁');
? }
}
category.dart
import 'package:flutter/material.dart';
?
class CategoryPage extends StatefulWidget {
? CategoryPage({Key key}) : super(key: key);
?
? @override
? _CategoryPageState createState() => _CategoryPageState();
}
?
class _CategoryPageState extends State<CategoryPage> {
? @override
? Widget build(BuildContext context) {
? ? return Text('分類');
? }
}
user.dart
import 'package:flutter/material.dart';
?
class UserPage extends StatefulWidget {
? UserPage({Key key}) : super(key: key);
?
? @override
? _UserPageState createState() => _UserPageState();
}
?
class _UserPageState extends State<UserPage> {
? @override
? Widget build(BuildContext context) {
? ? return Text('會員');
? }
}
效果展示:
原文鏈接:https://blog.csdn.net/u013227399/article/details/103787189
相關推薦
- 2021-11-26 Linux下查看IP地址不顯示解決辦法_Linux
- 2022-10-24 Python?NumPy教程之數據類型對象詳解_python
- 2022-07-29 pytest解讀fixture有效性及跨文件共享fixtures_python
- 2023-04-04 C語言對于volatile與gcc優化的探究_C 語言
- 2023-04-13 element UI中flex布局下el-table寬度自適應在IE下出現一直加載寬度的bug解決
- 2022-12-23 一文帶你了解Android中的網絡請求_Android
- 2022-06-01 C語言詳細分析常見字符串函數與模擬實現_C 語言
- 2022-11-03 Python列表推導式,元組推導式,字典推導式,集合推導式_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支