底部导航--中间图标突出

底部导航中间图标突出

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nw_guangzhou_bhapp/pages/relay/relayPage.dart';
import 'package:nw_guangzhou_bhapp/pages/remind/remindPage.dart';
import 'package:nw_guangzhou_bhapp/pages/search/searchPage.dart';
import 'package:nw_guangzhou_bhapp/utils/toast.dart';
import 'custom/customPage.dart';
import 'mine/myPage.dart';
import 'package:nw_guangzhou_bhapp/utils/flutter_screenutil.dart';
class IndexPage extends StatefulWidget {
  final int currentIndex;
  @override
  State<StatefulWidget> createState() => new _IndexPage();
  const IndexPage({Key key, @required this.currentIndex}) : super(key: key);
}

class _IndexPage extends State<IndexPage> {
  PageController pageController;
  int page = 2;
  DateTime lastPopTime;
  //添加图片地址,需要动态更换图片
  String bigImg = 'assets/images/jibao-2.png';

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance =
    ScreenUtil(width: 750, height: 1334, allowFontScaling: true)
      ..init(context);
    return WillPopScope(
      child: Container(
        color: Colors.white,
        child: SafeArea(
            top: false,
            child: Stack(
              children: <Widget>[
                Scaffold(
                  body: PageView(
                    physics: new NeverScrollableScrollPhysics(),
                    children: <Widget>[
                      SearchPage(),
                      AlarmPage(),
                      RelayPage(currentIndex: widget.currentIndex),
                      CustomPage(),
                      MyPage()
                    ],
                    controller: pageController,
                    onPageChanged: onPageChanged,
                  ),
                  bottomNavigationBar: BottomNavigationBar(
                    items: [
                      BottomNavigationBarItem(
                          icon: Icon(
                            IconData(0xe615, fontFamily: 'Search'),
                            size: 23,
                          ),
                          title: Text('搜索')),
                      BottomNavigationBarItem(
                          icon: Icon(
                            IconData(0xe61b, fontFamily: 'Alarm'),
                            size: 22,
                          ),
                          title: Text('提醒')),
                      BottomNavigationBarItem(
                          icon: Icon(Icons.brightness_1,color: Colors.white, size: 25,), title: Text('继保')),
                      BottomNavigationBarItem(
                          icon: Icon(
                            IconData(0xe623, fontFamily: 'Customized'),
                            size: 25,
                          ),
                          title: Text('定制')),
                      BottomNavigationBarItem(
                          icon: Icon(
                            IconData(0xe611, fontFamily: 'Mine'),
                            size: 22,
                          ),
                          title: Text('我的')),
                    ],
                    elevation: 0,
                    onTap: onTap,
                    currentIndex: page,
                    type: BottomNavigationBarType.fixed,
                    backgroundColor: Colors.white,
                  ),
                ),
                Align(
                  child: Padding(
                    padding: const EdgeInsets.only(bottom: 27.0),
                    child: FloatingActionButton(
                      mini: true,
                      highlightElevation: 0.0,
                      elevation: 0.0,
                      child: new Image.asset(bigImg),
                      onPressed: onBigImgTap,
                    ),
                  ),
                  alignment: Alignment.bottomCenter,
                ),
              ],
            )),
      ),
        onWillPop: () async {
          // 点击返回键的操作
          if (lastPopTime == null ||
              DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) {
            lastPopTime = DateTime.now();
            Toast.toast(context, msg: '再按一次退出');
          } else {
            lastPopTime = DateTime.now();
            // 退出app
            await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          }
          return null;
        }
    );
  }

  @override
  void initState() {
    super.initState();
    pageController = PageController(initialPage: this.page);
  }

  @override
  void dispose() {
    pageController.dispose();
    super.dispose();
  }

  void onTap(int index) {
    if (index != 2) {
      setState(() {
        this.bigImg = 'assets/images/jibao-1.png';
      });
    } else {
      setState(() {
        this.bigImg = 'assets/images/jibao-2.png';
      });
    }
    pageController.jumpToPage(index);
  }

  //添加图片的点击事件
  void onBigImgTap() {
    setState(() {
      this.page = 2;
      this.bigImg = 'assets/images/jibao-2.png';
      onTap(2);
    });
  }

  void onPageChanged(int page) {
    setState(() {
      this.page = page;
    });
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值