首页 > 其他 > 详细

底部导航栏设置

时间:2021-08-01 22:26:18      阅读:21      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

 

 

import ‘package:flutter/material.dart‘;
import ‘tabs/Home.dart‘;
import ‘tabs/Setting.dart‘;
import ‘tabs/Category.dart‘;

class Tabs extends StatefulWidget {
  Tabs({Key? key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;

  List _pageList = [
    HomePage(),
    CategoryPage(),
    SeetingPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("flutter  Demo")),
      body: this._pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex, // 配置选中的索引
        onTap: (int index) {
          print(index);
          setState(() {
            this._currentIndex = index;
          });
        },
        iconSize: 36.0, // 设置图标大小
        fixedColor: Colors.red, // 选中的颜色
        type: BottomNavigationBarType.fixed, // 配置底部tabs 可以有多个按钮
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text("首页"),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.category),
            title: Text("分类"),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            title: Text("设置"),
          ),
        ],
      ),
    );
  }
}
----------------
import ‘package:flutter/material.dart‘;

class HomePage extends StatefulWidget {
  HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("我是首页组件"),
    );
  }
}

底部导航栏设置

原文:https://www.cnblogs.com/eric-share/p/15087576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!