Flutter底部不規(guī)則導航的實現(xiàn)過程
前言
本文主要介紹的是關(guān)于Flutter實現(xiàn)底部不規(guī)則導航的相關(guān)內(nèi)容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧
實現(xiàn)方法:
1、main.dart文件
import 'package:flutter/material.dart';
import 'bootom_appBar.dart';
void main () =>runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title:'不規(guī)則底部導航',
//自定義主題樣本
theme:ThemeData(
primarySwatch:Colors.lightBlue
),
home:BottomAppBarDemo(),
);
}
}
2、bootom_appBar.dart
import 'package:flutter/material.dart';
import 'each_view.dart';
class BottomAppBarDemo extends StatefulWidget {
@override
_BottomAppBarDemoState createState() => _BottomAppBarDemoState();
}
class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
List<Widget> _eachView;
int _index = 0;
@override
void initState() {
_eachView = List();
_eachView ..add(EachView('主頁的頁面'));
_eachView ..add(EachView('副頁的頁面'));
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
//變換頁面
body: _eachView[_index],
floatingActionButton: FloatingActionButton(
onPressed: (){
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context){
return EachView('新添加的頁面');
}));
},
tooltip: '添加',
child: Icon(
Icons.add,
color: Colors.white,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
//工具欄比NavigationBar靈活
color: Colors.lightBlue,
//與fab融合
//圓形缺口
shape: CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(
icon: Icon(Icons.home),
color: Colors.white,
onPressed: (){
setState(() {
_index = 0;
});
},
),
IconButton(
icon: Icon(Icons.airport_shuttle),
color: Colors.white,
onPressed: (){
setState(() {
_index = 1;
});
},
)
],
),
),
);
}
}
3、each_view.dart
import 'package:flutter/material.dart';
class EachView extends StatefulWidget {
String _title;
EachView(this._title);
@override
_EachViewState createState() => _EachViewState();
}
class _EachViewState extends State<EachView> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget._title),),
body: Center(child: Text(widget._title),),
);
}
}
4、效果展示

總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。
相關(guān)文章
Android開發(fā)者常見的UI組件總結(jié)大全
Android開發(fā)中UI組件是構(gòu)建用戶界面的基本元素,下面這篇文章主要給大家介紹了關(guān)于Android開發(fā)者常見的UI組件總結(jié)的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-04-04
Android Application存取公共數(shù)據(jù)的實例詳解
這篇文章主要介紹了Android Application存取公共數(shù)據(jù)的實例詳解的相關(guān)資料,需要的朋友可以參考下2017-07-07
Android開發(fā)獲取短信的內(nèi)容并截取短信
本文給大家介紹android開發(fā)獲取短信內(nèi)容并截取短息的相關(guān)內(nèi)容,本文代碼簡單易懂,感興趣的朋友一起學習吧2015-12-12
android動態(tài)布局之動態(tài)加入TextView和ListView的方法
這篇文章主要介紹了android動態(tài)布局之動態(tài)加入TextView和ListView的方法,涉及Android動態(tài)布局的實現(xiàn)技巧,需要的朋友可以參考下2015-05-05
flutter PositionedTransition實現(xiàn)縮放動畫
這篇文章主要為大家詳細介紹了flutter PositionedTransition實現(xiàn)縮放動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07

