日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Flutter定義tabbar底部導(dǎo)航路由跳轉(zhuǎn)的方法_Android

作者:明知山_ ? 更新時(shí)間: 2022-09-21 編程語(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

欄目分類(lèi)
最近更新