当前位置: 首页 > news >正文

仿知乎ui实现bottomNavigationBar

         

import 'package:flutter/material.dart';

import 'index/index.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '高仿知乎',
      home: Index(),
    );
  }
}

 

 

 

import 'package:flutter/material.dart';
import 'package:flutter_app/home/home_page.dart';
import 'package:flutter_app/idea/idea_page.dart';
import 'package:flutter_app/index/navigation_icon_view.dart';
import 'package:flutter_app/market/market_page.dart';
import 'package:flutter_app/my/my_page.dart';

import '../global_config.dart';

class Index extends StatefulWidget {
  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index>  with TickerProviderStateMixin {
  int _currentIndex=0;
  List<StatefulWidget> _pageList;
  List<NavigationIconView> _navigationViews;
  StatefulWidget _currentPage;


   @override
  void initState() {
    // TODO: implement initState
    super.initState();
    
    _navigationViews=<NavigationIconView>[
      new NavigationIconView(
       new Icon(Icons.assignment),
       Text("首页"),
        this,
     ),
      new NavigationIconView(
        new Icon(Icons.all_inclusive),
        Text("想法"),
        this,
      ),
      new NavigationIconView(
        new Icon(Icons.add_shopping_cart),
        Text("市场"),
        this,
      ),
      new NavigationIconView(
        new Icon(Icons.add_alert),
        Text("通知"),
        this,
      ),

      new NavigationIconView(
        new Icon(Icons.perm_identity),
        Text("我的"),
        this,
      ),

    ];


    for(NavigationIconView view in _navigationViews){
      view.controller.addListener(_rebuild);
    }

    _pageList=<StatefulWidget>[
      new HomePage(),
      new IdeaPage(),
      new MarketPage(),
      new MyPage()
    ];
    _currentPage=_pageList[_currentIndex];
    
  }
  
   void _rebuild(){
     setState(() {});
   }

   @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    for (NavigationIconView view in _navigationViews) {
      view.controller.dispose();
    }
  }

  @override
  Widget build(BuildContext context) {

   final BottomNavigationBar bottomNavigationBar=new BottomNavigationBar(
       items: _navigationViews
           .map((NavigationIconView navigationIconView) => navigationIconView.item)
            .toList(),
          currentIndex: _currentIndex,
        fixedColor: Colors.blue,
         type: BottomNavigationBarType.fixed,
     onTap: (int index){
         setState(() {
           _navigationViews[_currentIndex].controller.reverse();
           _currentIndex=index;
           _navigationViews[_currentIndex].controller.forward();
           _currentPage=_pageList[_currentIndex];
         });
     }


   );


    return new MaterialApp(
        home: Scaffold(
          body: Center(
             child: _currentPage,

          ),
          bottomNavigationBar: bottomNavigationBar,),
      theme: GlobalConfig.themeData,

    );
  }
}

 

 

import 'package:flutter/material.dart';


class NavigationIconView{
    NavigationIconView (Widget icon,Widget title,TickerProvider vsync){
       this.item=new BottomNavigationBarItem(icon: icon,title: title);
       this.controller=new AnimationController(
         duration: kThemeAnimationDuration,
         vsync: vsync
       );
    }
    BottomNavigationBarItem item;
    AnimationController controller;
}

 

import 'package:flutter/material.dart';

class GlobalConfig{
   static bool dark=true;
   static ThemeData themeData=new ThemeData.dark();
   static Color searchBackgroundColor =Colors.white10;
   static Color cardBackgroundColor = new Color(0xFF222222);
   static Color fontColor = Colors.white30;
}

 

相关文章:

  • 高效CSDNBLOG技巧终结篇
  • 给BLOG加一个控制菜单展开和收缩的按扭
  • 在自己Blog的导航菜单加动态摄影作品展
  • 给自己的BLOG加一个不用注册申请的计数计。
  • flutter轮播图swiper
  • 给自己的BLOG来点音乐如何?
  • flutter 设置状态栏的颜色,背景appBar
  • 跟我来玩转CSDN BLOG界面
  • flutter的PreferredSize
  • Dev-Cpp/Mingw32 环境介绍(1)
  • 新浪体育图片新闻动态效果代码
  • golang切片的容量长度
  • 看中国足球,哭笑不得
  • golang盲点扫描copy
  • SMS 2003 客户端常见问题
  • 【comparator, comparable】小总结
  • 4. 路由到控制器 - Laravel从零开始教程
  • fetch 从初识到应用
  • Flex布局到底解决了什么问题
  • Invalidate和postInvalidate的区别
  • LintCode 31. partitionArray 数组划分
  • Redux 中间件分析
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 第十八天-企业应用架构模式-基本模式
  • 翻译 | 老司机带你秒懂内存管理 - 第一部(共三部)
  • 官方解决所有 npm 全局安装权限问题
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 微信小程序--------语音识别(前端自己也能玩)
  • 小程序测试方案初探
  • 一道面试题引发的“血案”
  • 掌握面试——弹出框的实现(一道题中包含布局/js设计模式)
  • 找一份好的前端工作,起点很重要
  • 带你开发类似Pokemon Go的AR游戏
  • 通过调用文摘列表API获取文摘
  • ​LeetCode解法汇总2696. 删除子串后的字符串最小长度
  • # MySQL server 层和存储引擎层是怎么交互数据的?
  • #### go map 底层结构 ####
  • #Linux(make工具和makefile文件以及makefile语法)
  • #Z0458. 树的中心2
  • #我与Java虚拟机的故事#连载06:收获颇多的经典之作
  • #我与Java虚拟机的故事#连载12:一本书带我深入Java领域
  • (+3)1.3敏捷宣言与敏捷过程的特点
  • (0)Nginx 功能特性
  • (52)只出现一次的数字III
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (附源码)python旅游推荐系统 毕业设计 250623
  • (附源码)计算机毕业设计ssm-Java网名推荐系统
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • .gitattributes 文件
  • .Mobi域名介绍
  • .NET 将混合了多个不同平台(Windows Mac Linux)的文件 目录的路径格式化成同一个平台下的路径
  • .net反编译的九款神器
  • .NET开源的一个小而快并且功能强大的 Windows 动态桌面软件 - DreamScene2
  • .NET微信公众号开发-2.0创建自定义菜单