You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
7.2 KiB
Dart

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx511505_sanjiang_new_area_launche/pages/tabs/page4_myMsics_new.dart';
//import '../../widget/player_pro.dart';
import '../../components/commonFun.dart';
//import 'package:fijkplayer/fijkplayer.dart';
import '../../services/ServiceLocator.dart';
import '../../services/Storage.dart';
import 'page1_work.dart';
class Tabs extends StatefulWidget {
Tabs({Key key, this.arguments = 0}) : super(key: key);
int arguments;
_TabsState createState() => _TabsState();
}
class _TabsState extends State<Tabs> {
//try_setState(); //避免如下异常报错
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
int _currentIndex = 0;
String sAppBar0 = 'Flutter Demo';
String sAppBar = 'Flutter Demo';
PageController _pageController;
@override
void initState() {
getlistItems().then((value) => try_setState());
print('widget.arguments = ${widget.arguments}');
//_currentIndex = 3 == widget.arguments ? 0 : widget.arguments; //解决"我的"页面根据用户所属组及时刷新问题
_currentIndex = widget.arguments;
this._pageController = PageController(initialPage: _currentIndex);
// 注册服务
setupLocator();
// 解决登录按钮再次变换文字的问题
Future.delayed(const Duration(milliseconds: 1000), () {
//重新初始化处理延时登录的变量
//bMayLogin = false; //这句必须注释掉,否则“退出登录”后,无法再次进行用户名登录
bPreLoading = false;
bLoginVerify = false; //处理延时登录,判断用户名登录是否验证通过
});
super.initState();
}
double _activeIconWidth = 68;
Future getlistItems() async {
listItems.addAll([
BottomNavigationBarItem(
icon: getImageItem('assets/images/矢量智能对象.png'),
label: "首页",
activeIcon: getImageItem('assets/images/矢量智能对象.png',
width: _activeIconWidth, color: Colors.blue)),
BottomNavigationBarItem(
icon: getImageItem('assets/images/矢量智能对象(1).png'),
label: "统计",
activeIcon: getImageItem('assets/images/矢量智能对象(1).png',
width: _activeIconWidth, color: Colors.blue)),
BottomNavigationBarItem(
icon: getImageItem('assets/images/矩形 1 拷贝 39.png'),
label: "设备",
activeIcon: getImageItem('assets/images/矩形 1 拷贝 39.png',
width: _activeIconWidth, color: Colors.blue)),
//bNewVer是否发现新版本
BottomNavigationBarItem(
icon: getImageItem('assets/images/我的.png', bBadge: bNewVer),
label: "我的",
activeIcon: getImageItem('assets/images/我的.png',
width: _activeIconWidth, color: Colors.blue, bBadge: bNewVer)),
]);
}
// 添加底部导航栏图标的小红点
Widget getImageItem(String imagePath,
{double width = 56,
Color color = const Color.fromRGBO(131, 131, 131, 1),
bool bBadge = false}) {
return bBadge
? Badge(
position: BadgePosition.topEnd(top: -4, end: -9),
badgeContent: null,
child: Image.asset(imagePath,
width: ScreenUtil().setWidth(width), fit: BoxFit.cover, color: color))
: Image.asset(imagePath,
width: ScreenUtil().setWidth(width), fit: BoxFit.cover, color: color);
}
List<BottomNavigationBarItem> listItems = [];
//该美工优化的页面 Page1_Works是供多个页面共享的代码框架。不同的页面以 PageType 字段进行区分
//String pageType = ''; //'home_page'、'statis_page'、'device_page'
List<Widget> _pageList = [
Page1_Works(pageType: 'home_page', title: '黑烟车抓拍系统'),
Page1_Works(pageType: 'statis_page', title: ' 统计信息'),
Page1_Works(pageType: 'device_page', title: ' 设备管理'),
//Page2_StatisticsNew(),
//Page3_Device(),
//Page4_MyMsics(),
Page4_MyMsicsNew(pageType: 'my_page', title: ' 我的'),
];
Text _getName(index) {
return Text(this.sAppBar0 + ' - ' + this.listItems[_currentIndex].label);
}
@override
Widget build(BuildContext context) {
sizeWindowPhysicalSize = MediaQuery.of(context).size;
return Scaffold(
// appBar: _currentIndex!=3?:AppBar(
// title: Text("用户中心"),
// ),
resizeToAvoidBottomPadding: false, //解决输入法键盘弹出越界问题-OK
appBar: PreferredSize(
child: AppBar(
//title: Text("Flutter Demo"),
title: listItems.isEmpty ? Text('') : _getName(this._currentIndex),
),
preferredSize: Size.fromHeight(0) //Flutter——设置appBar的高度
),
//底部导航栏使用PageView方式在App启动时只加载显示页面启动时没有警告报错。可以配置每个页面的是否保持状态更为灵活也更复杂一些
body: PageView(
controller: this._pageController,
children: this._pageList,
onPageChanged: (index) {
setState(() {
this._currentIndex = index;
//label: "我的"
//eventBus.fire(GroupIdUpdateEvent('g_userInfo.userGroupIDlist 数据已更新')); //这样刷新有效
// if (3 == index) {
// }
});
},
physics: NeverScrollableScrollPhysics(), //禁止pageView滑动
),
//底部导航栏使用IndexedStack方式是在App启动时便一次性加载所有页面启动时有警告报错。所有页面的状态都会保持
// body: IndexedStack(
// index: _currentIndex,
// children: this._pageList,
// ),
bottomNavigationBar: listItems.isEmpty
? Text('')
: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
//eventBus.fire(GroupIdUpdateEvent('g_userInfo.userGroupIDlist 数据已更新')); //这样刷新有效
g_iIndex = index;
Storage.setString('tabs_index', g_iIndex.toString());
setState(() {
this._currentIndex = index;
this._pageController.jumpToPage(index);
// if (1 == index && bPlaying) {
// if (player.value.videoRenderStart && player.state == FijkState.paused) {
// player.start();
// }
// } else {
// //若player并未初始化播放调用会报错The method 'changePlayerState' was called on null.
// if (player.value.videoRenderStart && player.state == FijkState.started) {
// bPlaying = true;
// player.pause();
// }
// }
});
},
iconSize: ScreenUtil().setSp(70),
//icon的大小
fixedColor: Colors.blueAccent,
type: BottomNavigationBarType.fixed,
items: listItems,
),
);
}
}