【flutter底部导航栏】

底部导航样式实现

1、普通底部栏

在这里插入图片描述

1、中间凹起

在这里插入图片描述

3、中间悬浮

在这里插入图片描述

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'application_page.dart';
import 'article_page.dart';
import 'home_page.dart';
import 'mine_page.dart';

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

  
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _currentIndex = 0;
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  static final List<Widget> _pagesList = [
    const HomePage(),
    const ApplicationPage(),
    const ArticlePage(),
    const MinePage(),
  ];

  
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      // appBar: AppBar(
      //   title: Text(_titles[_currentIndex]),
      // ),
      body: IndexedStack(
        index: _currentIndex,
        children: _pagesList,
      ),
      //1、普通底部栏
      // bottomNavigationBar: BottomNavigationBar(
      //   backgroundColor: Colors.brown,
      //   currentIndex: _currentIndex,
      //   type: BottomNavigationBarType.fixed,
      //   // items: MyTabBar.items,
      //   items: [
      //     BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
      //     BottomNavigationBarItem(
      //         icon: Icon(Icons.settings_applications), label: '应用'),
      //     BottomNavigationBarItem(icon: Icon(Icons.article), label: '资讯'),
      //     BottomNavigationBarItem(icon: Icon(Icons.person), label: '个人'),
      //   ],
      //   selectedItemColor: Colors.white,
      //   unselectedItemColor: Colors.grey,
      //   selectedFontSize: 14.sp,
      //   unselectedFontSize: 14.sp,
      //   onTap: (value) {
      //     setState(() {
      //       _currentIndex = value;
      //     });
      //   },
      // ),
      // 底部凸起凹陷导航栏
      bottomNavigationBar: BottomAppBar(
        color: Colors.brown,
        shape: const CircularNotchedRectangle(), //凹陷
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            _buildIconButton(0, Icon(Icons.home, size: 24.r)),
            _buildIconButton(1, Icon(Icons.settings_applications, size: 24.r)),
            SizedBox(
              width: 50.w,
            ),
            _buildIconButton(2, Icon(Icons.article, size: 24.r)),
            _buildIconButton(3, Icon(Icons.person, size: 24.r)),
          ],
        ),
      ),

      ///中间图片凸起
      floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: const [Icon(Icons.add)])),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }

  Widget _buildIconButton(int index, Icon icon) {
    return IconButton(
      icon: icon,
      color: _currentIndex == index ? Colors.blue : Colors.grey,
      onPressed: () {
        setState(() {
          _currentIndex = index;
        });
      },
    );
  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值