底部导航中间图标突出
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;
});
}
}