zoukankan      html  css  js  c++  java
  • flutter 导航栏 BottomNavigationBar底部导航栏相当于iOS tabbar

    //main.dart文件
    import 'package:flutter/material.dart';
    import 'package:myapp/Tabbar.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Tabbar(),
        );
      }
    }
    //Tabbar.dart文件
    import 'package:flutter/material.dart';
    import './Home.dart';
    import './Category.dart';
    import './Setting.dart';
    
    class Tabbar extends StatefulWidget {
      Tabbar({Key key}) : super(key: key);
    
      _TabbarState createState() => _TabbarState();
    }
    
    class _TabbarState extends State<Tabbar> {
      int _tabbarIndex = 0;//用于记录当前选中第几个item
      List _tabPages = [//装载底部tabbar的item所对应的页面
        HomePage(),
        CategoryPage(),
        SettingPage()
      ];
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("appbarTitle"),
          ),
          body: this._tabPages[this._tabbarIndex],//显示当前选中的tabbatItem所对应的页面
          bottomNavigationBar: BottomNavigationBar(
            iconSize: 36,
            fixedColor: Colors.pink,
            type: BottomNavigationBarType.fixed,
            currentIndex: this._tabbarIndex,//当前选中第几个item
            onTap: (index){//点击回调
              setState(() {//当需要改变页面中的参数值的时候,需要在该方法中更新数据,否则不会刷新页面
                this._tabbarIndex = index;
              });
            },
            items: [//配置底部导航栏的按钮列表
              BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首页")),
              BottomNavigationBarItem(
                  icon: Icon(Icons.category), title: Text("分类")),
              BottomNavigationBarItem(
                  icon: Icon(Icons.settings), title: Text("设置")),
            ],
          ),
        );
      }
    }
    //首页  Home.dart
    import 'package:flutter/material.dart';
    
    class HomePage extends StatelessWidget {
      const HomePage({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Container(
          child: Text('首页'),
        );
      }
    }
    //分类 Category.dart
    import 'package:flutter/material.dart';
    
    class CategoryPage extends StatelessWidget {
      const CategoryPage({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Container(
            child: Text('分类')
        );
      }
    }
    //设置 Setting.dart
    import 'package:flutter/material.dart';
    
    class CategoryPage extends StatelessWidget {
      const CategoryPage({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Container(
            child: Text('分类')
        );
      }
    }

    还有参考同行大神的

    https://blog.csdn.net/qq_16247851/article/details/81172628

  • 相关阅读:
    入门金融学(1)
    递归之八皇后
    新手Oracle安装及使用入门
    RegExp正则校验之Java及R测试
    Mysql实现行列转换
    R语言之RCurl实现文件批量下载
    Consumer clientId=consumer-1, groupId=console-consumer-950] Connection to node -1 could not be
    线程池拒绝策略
    spring较为常用注解
    idea springboot启动报SLF4J:Failed to load class “org.slf4j.impl.StaticLoggerBinder”
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/11957701.html
Copyright © 2011-2022 走看看