網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
本文實(shí)例為大家分享了Flutter定義tabbar底部導(dǎo)航路由跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下
效果展示
整體實(shí)現(xiàn)的目錄結(jié)構(gòu)
第一步 把三個(gè)頁(yè)面放到tabs里 Category.dart || Home.dart || Setting.dart
在這里我只展示?Home.dart 另外兩個(gè)頁(yè)面相同
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("我是首頁(yè)組件");
? }
}
在?Tabs.dart 里import 引入三個(gè)頁(yè)面
import 'package:flutter/material.dart';
import 'tabs/Home.dart';
import 'tabs/Category.dart';
import 'tabs/Setting.dart';
class Tabs extends StatefulWidget {
? Tabs({Key key}) : super(key: key);
? @override
? _TabsState createState() => _TabsState();
}
class _TabsState extends State<Tabs> {
? int _currentIndex = 0;
? // 把頁(yè)面存放到數(shù)組里
? List _pageList = [
? ? HomePage(),
? ? CategoryPage(),
? ? SettingPage(),
? ];
? @override
? Widget build(BuildContext context) {
? ? return Scaffold(
? ? ? appBar: AppBar(
? ? ? ? title: Text('首頁(yè)'),
? ? ? ),
? ? ? body: this._pageList[this._currentIndex],
? ? ? bottomNavigationBar: BottomNavigationBar(
? ? ? ? // 默認(rèn)選中第幾項(xiàng)
? ? ? ? currentIndex: this._currentIndex,
? ? ? ? // 導(dǎo)航欄點(diǎn)擊獲取索引值
? ? ? ? onTap: (int index) {
? ? ? ? ? setState(() {
? ? ? ? ? ? this._currentIndex = index;
? ? ? ? ? });
? ? ? ? },
? ? ? ? iconSize: 30.0, //icon的大小
? ? ? ? fixedColor: Colors.red, //選中的顏色
? ? ? ? type: BottomNavigationBarType.fixed, //配置底部tabs可以有多個(gè)按鈕
? ? ? ? //定義導(dǎo)航欄的圖片+名稱
? ? ? ? items: [
? ? ? ? ? BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首頁(yè)")),
? ? ? ? ? BottomNavigationBarItem(
? ? ? ? ? ? ? icon: Icon(Icons.category), title: Text("分類(lèi)")),
? ? ? ? ? BottomNavigationBarItem(
? ? ? ? ? ? ? icon: Icon(Icons.settings), title: Text("設(shè)置")),
? ? ? ? ],
? ? ? ),
? ? );
? }
}
main.dart
import 'package:flutter/material.dart'; //快捷方式:fim
import 'pages/Tabs.dart';
void main() {
? runApp(MyApp());
}
//自定義組件
class MyApp extends StatelessWidget {
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? return MaterialApp(
? ? ? home: Tabs(),
? ? ? theme: ThemeData(primarySwatch: Colors.deepOrange),
? ? ? debugShowCheckedModeBanner: false,
? ? );
? }
}
原文鏈接:https://blog.csdn.net/AK852369/article/details/104815661
相關(guān)推薦
- 2023-02-23 GoLang中的互斥鎖Mutex和讀寫(xiě)鎖RWMutex使用教程_Golang
- 2023-02-10 利用Python獲取文件夾下所有文件實(shí)例代碼_python
- 2021-12-05 C++11?關(guān)鍵字?const?使用小結(jié)_C 語(yǔ)言
- 2022-12-27 Go學(xué)習(xí)筆記之map的聲明和初始化_Golang
- 2022-05-21 Deployment副本無(wú)狀態(tài)服務(wù)創(chuàng)建及水平擴(kuò)展_服務(wù)器其它
- 2024-03-19 Linux中 find 命令詳解
- 2022-05-13 FAILED: Execution Error, return code 1 from org.ap
- 2023-05-06 C++?lambda函數(shù)詳解_C 語(yǔ)言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支