Flutter底部不规则导航的实现过程

前言

东海ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

本文主要介绍的是关于Flutter实现底部不规则导航的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧

实现方法:

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:'不规则底部导航',
  //自定义主题样本
  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 {
 List _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: [
      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 {
 @override
 Widget build(BuildContext context) {
  return Scaffold(
   appBar: AppBar(title: Text(widget._title),),
   body: Center(child: Text(widget._title),),
  );
 }
}

4、效果展示

Flutter底部不规则导航的实现过程

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对创新互联的支持。


分享标题:Flutter底部不规则导航的实现过程
当前地址:http://myzitong.com/article/joephd.html