flutter實現(xiàn)底部不規(guī)則導(dǎo)航欄
本文實例為大家分享了flutter實現(xiàn)底部不規(guī)則導(dǎo)航欄的具體代碼,供大家參考,具體內(nèi)容如下
scafford的bottomNavigationBar參數(shù)賦值BottomAppBar可以實現(xiàn),BottomAppBar比BottomNavigationBar靈活,在body參數(shù)之外準(zhǔn)備好一個fab,使用BottomAppBar的shape屬性設(shè)置BottomAppBar為一個挖了圓形的矩形,設(shè)置fab的位置便可;
main:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/EachView.dart';
import 'package:flutter_app/NewPage.dart';
void main(){
? runApp(MyApp());
}
class MyApp extends StatelessWidget{
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? // throw UnimplementedError();
? ? return new MaterialApp(
? ? ? theme: ThemeData(
? ? ? ? primarySwatch:Colors.lightBlue//fab的顏色
? ? ? ),
? ? ? home: MyNavigationBar(),
? ? );
? }
}
class ?MyNavigationBar extends StatefulWidget{
? @override
? MyNavigationBarState createState() {
? ? // TODO: implement createState
? ? // throw UnimplementedError();
? ? return new MyNavigationBarState();
? }
}
class MyNavigationBarState extends State<MyNavigationBar>{
? List<Widget> _list;
? int _index=0;
? @override
? void initState() {
? ? _list=[];
? ? _list..add(EachView(title: "0",))..add(EachView(title: "1",));
? }
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? // throw UnimplementedError();
? ? return new Scaffold(
? ? ? floatingActionButton: FloatingActionButton(//注意:如果想要fab放在默認(rèn)的位置,是放在scafford的floatingactionbar參數(shù)的,而不是放在body
? ? ? ? onPressed: (){
? ? ? ? ? Navigator.push(context, MaterialPageRoute(builder: (BuildContext context){
? ? ? ? ? ? return new NewPage();
? ? ? ? ? }));
? ? ? ? },
? ? ? ? child: Icon(Icons.add,color: Colors.white,),
? ? ? ),
? ? ? floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,//設(shè)置fab的位置
? ? ? body: _list[_index],
? ? ? bottomNavigationBar: BottomAppBar(
? ? ? ? color: Colors.amber,
? ? ? ? shape: CircularNotchedRectangle(),//讓bottomAppBar是一個挖了圓形的矩形
? ? ? ? child: Row(
? ? ? ? ? mainAxisAlignment: MainAxisAlignment.spaceAround,//首尾的寬度等于中間寬度的一半
? ? ? ? ? mainAxisSize: MainAxisSize.max,//表示占滿整個寬度,如果是min表示包裹子控件
? ? ? ? ? children: [
? ? ? ? ? ? IconButton(
? ? ? ? ? ? ? icon: Icon(Icons.home,color: Colors.lightBlue,),
? ? ? ? ? ? ? onPressed: (){
? ? ? ? ? ? ? ? setState(() {
? ? ? ? ? ? ? ? ? _index=0;
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? },
? ? ? ? ? ? ),
? ? ? ? ? ? IconButton(
? ? ? ? ? ? ? icon: Icon(Icons.photo,color: Colors.lightBlue,),
? ? ? ? ? ? ? onPressed: (){
? ? ? ? ? ? ? ? setState(() {
? ? ? ? ? ? ? ? ? _index=1;
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? },
? ? ? ? ? ? ),
? ? ? ? ? ],
? ? ? ? ),
? ? ? ),
? ? );
? }
}EachView:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class EachView extends StatelessWidget{
? final String title;
? const EachView({Key key, this.title}) : super(key: key);
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? // throw UnimplementedError();
? ? return new Scaffold(
? ? ? body: Center(
? ? ? ? child: Text("$title"),
? ? ? ),
? ? );
? }
}NewPage:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class NewPage extends StatelessWidget{
? @override
? Widget build(BuildContext context) {
? ? // TODO: implement build
? ? // throw UnimplementedError();
? ? return new Scaffold(
? ? ? body: Center(
? ? ? ? child: Text("NewPage"),
? ? ? ),
? ? );
? }
}效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳細(xì)分析Android中onTouch事件傳遞機(jī)制
相信不少朋友在剛開始學(xué)習(xí)Android的時候,對于onTouch相關(guān)的事件一頭霧水。分不清onTouch(),onTouchEvent()和OnClick()之間的關(guān)系和先后順序,所以覺得有必要搞清onTouch事件傳遞的原理。經(jīng)過一段時間的琢磨以及相關(guān)博客的介紹,這篇文章就給大家詳細(xì)的分析介紹下。2016-10-10
Android 系統(tǒng)實現(xiàn)多種開機(jī)動畫和logo切換功能
這篇文章主要介紹了android 系統(tǒng)實現(xiàn)多種開機(jī)動畫和logo切換功能,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-12-12
Android應(yīng)用開發(fā)中Fragment與Activity間通信示例講解
這篇文章主要介紹了Android應(yīng)用開發(fā)中Fragment與Activity間通信實例講解,需要的朋友可以參考下2016-02-02
PopupWindow?RecyclerView實現(xiàn)下拉選擇Spinner示例解析
這篇文章主要介紹了PopupWindow?RecyclerView實現(xiàn)下拉選擇Spinner示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
Android中使用TagFlowLayout制作動態(tài)添加刪除標(biāo)簽
這篇文章主要介紹了Android中使用TagFlowLayout制作動態(tài)添加刪除標(biāo)簽的步驟詳解,需要的朋友參考下吧2017-07-07

