栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

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

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

前言

本文主要介绍的是关于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、效果展示


总结

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/154868.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号