import 'dart:convert';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:provider/provider.dart';
import 'package:repair_app_android/common/ColorsUtil.dart';
import 'package:repair_app_android/common/funs.dart';
import 'package:repair_app_android/common/git_api.dart';
import 'package:repair_app_android/common/global.dart';
import 'package:repair_app_android/i10n/localization_intl.dart';
import 'package:repair_app_android/models/categoryData.dart';
import 'package:repair_app_android/models/listDoPost.dart';
import 'package:repair_app_android/models/listTruePost.dart';
import 'package:repair_app_android/models/mediaUrl.dart';
import 'package:repair_app_android/models/sendListSec.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:repair_app_android/routes/home/bean/MyUnderlineTabIndicator.dart';
import 'package:repair_app_android/states/profile_change_notifier.dart';
import 'package:repair_app_android/widgets/home_selection_route.dart';
import 'package:repair_app_android/widgets/pie_chart_wid.dart';
import 'package:repair_app_android/widgets/repair_add_selection.dart';
import 'home/bean/HomeBean.dart';
import 'login.dart';
import 'dart:ui';
class HomeRoute extends StatefulWidget {
static int count = 0;
@override
_HomeRouteState createState() => _HomeRouteState();
}
class _HomeRouteState extends State<HomeRoute> with TickerProviderStateMixin {
//首页四个listView
List<Color> listColor = [
Color.fromRGBO(64, 224, 208, 1),
Color.fromRGBO(0, 191, 255, 1),
Color.fromRGBO(123, 104, 238, 0.85)
];
List<IconData> listIcon = [
Icons.monetization_on,
Icons.camera_alt,
Icons.phone_iphone,
Icons.lightbulb_outline
];
AudioPlayer advancedPlayer;
AudioCache audioCache;
static int _initAudio = 0;
//四个设备类型
// List categoryHome = ['高速公路','智能楼宇','智慧停车','机房数据'];
//存储高速业务类型列表
List<CategoryList> categoryLists = [];
List<Children> parentList = [];
//存储城市业务类型列表
List<Children> cityParentList = [];
//存首页card内部的四个类型
int _currentIndex = 0;
var _pageController = PageController(initialPage: 0);
JPush jpush = new JPush();
//
int parentListLength = 0;
List<HomeBean> _homeRoadList = [
HomeBean('监控系统', 'imgs/home/home_road_1.png'),
HomeBean('通信系统', 'imgs/home/home_road_2.png'),
HomeBean('收费系统', 'imgs/home/home_road_3.png'),
HomeBean('供配电系统', 'imgs/home/home_road_4.png')
];
List<HomeBean> _homeFloorList = [
HomeBean('会议设备', 'imgs/home/home_road_1.png'),
HomeBean('办公设备', 'imgs/home/home_road_2.png'),
HomeBean('网络设备', 'imgs/home/home_road_3.png'),
HomeBean('机房设备', 'imgs/home/home_road_4.png')
];
List<HomeBean> _homeCarList = [
HomeBean('出口设备', 'imgs/home/home_car_1.png'),
HomeBean('入口设备', 'imgs/home/home_car_2.png'),
HomeBean('停车场设备', 'imgs/home/home_car_3.png'),
HomeBean('管理办公室', 'imgs/home/home_car_4.png')
];
List<HomeBean> _homeIDCList = [
HomeBean('动环设备', 'imgs/home/home_car_1.png'),
HomeBean('消防设备', 'imgs/home/home_car_2.png'),
HomeBean('硬件设备', 'imgs/home/home_car_3.png')
];
List<Widget> _tabBarList = [
Tab(text: '高速公路'),
Tab(text: '智慧楼宇'),
];
List<Widget> _tabBarList2 = [
Tab(text: '智慧停车'),
Tab(text: '机房数据'),
];
//高速公路 & 智慧楼宇
TabController _tabController;
// 智慧停车 & 机房数据
TabController _tabController2;
@override
void initState() {
super.initState();
//获取设备类型信息
getCategoryLists();
// 获取视频、音频、图片访问路径前缀,并给全局变量赋值
getMediaUrl();
//获取人员身份信息
isRole();
// 监听Jpush
jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter 接收到推送: $message");
setState(() {
//获取人员身份信息
isRole();
});
},
onOpenNotification: (Map<String, dynamic> message) async {
// 点击通知栏消息,操作页面跳转等
print("flutter onOpenNotification: $message");
},
);
// 配置jpush
jpush.setup(
appKey: "7ef978fe32f327504876d27d",
channel: "developer",
production: false,
debug: true);
// jpush.setBadge(5);
jpush.applyPushAuthority(
new NotificationSettingsIOS(sound: true, alert: true, badge: true));
print('jpush init');
advancedPlayer = new AudioPlayer();
audioCache = new AudioCache(fixedPlayer: advancedPlayer);
_tabController =
TabController(initialIndex: 0, length: _tabBarList.length, vsync: this);
_tabController2 = TabController(
initialIndex: 0, length: _tabBarList2.length, vsync: this);
}
//获取类型数据
getCategoryLists() async {
Response res = await Git().getCategoryList();
Map<String, Object> map = jsonDecode(res.data);
var obj = CategoryData.fromJson(map);
if (mounted) {
setState(() {
categoryLists = obj.categoryList;
parentList = categoryLists[0].children;
print("parentList========${parentList.length}");
cityParentList = categoryLists[1].children;
});
}
}
//获取视频、音频、图片访问路径前缀,并给全局变量赋值
getMediaUrl() async {
Response res = await Git().getMediaUrl();
Map<String, Object> map = jsonDecode(res.data);
var obj = MediaUrl.fromJson(map);
List<RmuList> mediaList = [];
if (mounted) {
setState(() {
mediaList = obj.data.rmuList;
Global.profile.commonUrl = mediaList[0].commonUrl;
Global.profile.videoUrl = mediaList[0].videoUrl;
});
}
}
//底部导航栏的方法
@override
void dispose() {
super.dispose();
_pageController.dispose();
advancedPlayer.stop();
advancedPlayer.release();
}
void _pageChanged(int index) {
setState(() {
if (_currentIndex != index) _currentIndex = index;
});
}
void onTap(int index) {
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 1), curve: Curves.bounceIn);
}
//获取未读待办消息条数数据
//判断人员身份
isRole() {
if (Global.profile.specialRole == 1) {
return _dispacthing();
} else {
if (Global.profile.roleFlag == 1) {
return _repair();
} else if (Global.profile.roleFlag == 2) {
//张冲或刘凯或专职派单人员为派单
return _dispacthing();
} else if (Global.profile.roleFlag == 3) {
return _do();
} else {
return _repair();
}
}
}
//报修人员显示未读条数:待确认列表长度
_repair() async {
// List<TrueList> sends = [];
Response res = await Git().getRepairTrueList(1);
Map<String, Object> map = jsonDecode(res.data);
var obj = ListTruePost.fromJson(map);
if (mounted) {
setState(() {
HomeRoute.count = obj.trueList.total;
});
}
}
//派工人员显示未读条数:待派工+待确认列表长度
_dispacthing() async {
var count = 0;
Response res;
if (Global.profile.specialRole == 1) {
// 读取专职派工列表数据
res = await Git().getSpecialList(1);
} else {
// 读取普通派工列表数据
res = await Git().getRepairList(1);
}
Map<String, Object> map = jsonDecode(res.data);
var obj = SendListSec.fromJson(map);
if (mounted) {
setState(() {
print("待办conut=======${obj.brokenList.total}");
count = obj.brokenList.total;
});
}
//读取确认列表
Response res1 = await Git().getRepairTrueList(1);
Map<String, Object> map1 = jsonDecode(res1.data);
var obj1 = ListTruePost.fromJson(map1);
var count1 = 0;
if (mounted) {
setState(() {
// count1 = obj1.trueList.length;
count1 = obj1.trueList.total;
HomeRoute.count = count + count1;
});
}
}
//维修人员显示未读条数:待维修+待确认列表长度
_do() async {
Response res = await Git().getRepairDoList(1);
Map<String, Object> map = jsonDecode(res.data);
var obj = ListDoPost.fromJson(map);
var count = 0;
if (mounted) {
setState(() {
count = obj.doList.total;
});
}
//读取确认列表
Response res1 = await Git().getRepairTrueList(1);
Map<String, Object> map1 = jsonDecode(res1.data);
var obj1 = ListTruePost.fromJson(map1);
var count1 = 0;
if (mounted) {
setState(() {
// count1 = obj1.trueList.length;
count1 = obj1.trueList.total;
HomeRoute.count = count + count1;
debugPrint('isAppBadgeSupported =${HomeRoute.count}');
_setBadge(HomeRoute.count);
if (HomeRoute.count > 0) {
_initAudio++;
} else {
_initAudio = 0;
}
});
}
playLocal();
}
_setBadge(int count) {
FlutterAppBadger.isAppBadgeSupported().then((value) {
if (value) {
FlutterAppBadger.updateBadgeCount(count);
} else {
showToast('系统暂不支持桌面角标');
}
});
}
/// 播放音乐
playLocal() {
// 循环播放
debugPrint(_initAudio.toString());
if (_initAudio == 1) {
audioCache.loop('sounds/orderMessage.mp3');
} else {
advancedPlayer.stop();
advancedPlayer.release();
}
}
@override
Widget build(BuildContext context) {
UserModel userModel = Provider.of<UserModel>(context);
if (!userModel.isLogin) {
return Center(
child: LoginRoute(),
);
} else {
//设置别名
jpush.setAlias(Global.profile.user.blog);
// jpush.setAlias(Global.profile.user.blog);
// jpush.setAlias("13678826101aa");
return Scaffold(
body: _buildBody(),
);
}
}
// 创建body内容部分ss
Widget _buildBody() {
return Container(
child: Column(
children: <Widget>[
Expanded(
flex: 3,
child: Container(
padding: EdgeInsets.only(
top: MediaQueryData.fromWindow(window).padding.top,
bottom: 10),
constraints: BoxConstraints.expand(
height: 250.0,
// Theme.of(context).textTheme.display1.fontSize * 1.1 +
// 145.0,
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
ColorsUtil.color215dfe,
ColorsUtil.colorF8F8F8,
],
),
),
//color: Colors.white,
alignment: Alignment.topCenter,
child: PieChartWid(),
),
),
//SizedBox(height: 20),
categoryLists.length > 0
//? Container(child: _getCard())
? Expanded(flex: 1, child: Container(child: _titleContent()))
: Expanded(child: Container()),
//SizedBox(height: 30),
Expanded(
flex: 3,
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(left: 8, right: 8),
child: Row(
children: [
_tabBarContent(),
SizedBox(
width: 6,
),
_tabBarContent2(),
],
),
),
),
// new ListView.builder(
// shrinkWrap: true,
// physics: NeverScrollableScrollPhysics(),
// itemCount: listColor.length,
// itemBuilder: (BuildContext context, int index) {
// return (cityParentList.length != 0 ||
// cityParentList != null)
// ? _getCardList(context, index)
// : Container();
// },
// ),
SizedBox(
height: 50.0,
)
],
),
);
}
_tabBarContent() {
return Expanded(
child: Container(
//height: MediaQuery.of(context).size.height * 0.3,
child: Scaffold(
appBar: PreferredSize(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
color: ColorsUtil.white),
child: TabBar(
indicatorColor: ColorsUtil.color215dfe,
indicatorSize: TabBarIndicatorSize.label,
labelColor: ColorsUtil.black,
labelStyle: TextStyle(fontSize: 12.5),
unselectedLabelColor: ColorsUtil.grey,
indicator: MyUnderlineTabIndicator(),
tabs: _tabBarList,
controller: _tabController,
// 设置多了是否可以滚动
isScrollable: false,
),
),
preferredSize: Size.fromHeight(30),
),
body: TabBarView(
controller: _tabController,
children: [
_tabBarViewItem(_homeRoadList, _homeRoadList.length),
_tabBarViewItem(_homeFloorList, _homeFloorList.length),
],
),
),
),
);
}
_tabBarContent2() {
return Expanded(
child: Container(
//height: MediaQuery.of(context).size.height * 0.3,
child: Scaffold(
appBar: PreferredSize(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10)),
color: ColorsUtil.white),
child: TabBar(
indicatorColor: ColorsUtil.color215dfe,
indicatorSize: TabBarIndicatorSize.label,
labelColor: ColorsUtil.black,
labelStyle: TextStyle(fontSize: 12.5),
unselectedLabelColor: ColorsUtil.grey,
indicator: MyUnderlineTabIndicator(),
tabs: _tabBarList2,
controller: _tabController2,
// 设置多了是否可以滚动
isScrollable: false,
),
),
preferredSize: Size.fromHeight(30),
),
body: TabBarView(
controller: _tabController2,
children: [
_tabBarViewItem(_homeCarList, _homeCarList.length),
_tabBarViewItem(_homeIDCList, _homeIDCList.length),
],
),
),
),
);
}
_tabBarViewItem(List<HomeBean> list, int itemCount) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
color: ColorsUtil.white,
),
padding: EdgeInsets.only(top: 10),
child: GridView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, // 每行两列
childAspectRatio: 0.82, // 显示区域宽高相等
// crossAxisSpacing: 10,
),
itemCount: itemCount,
itemBuilder: (context, index) => _gridViewItem(list, index),
),
);
}
_gridViewItem(List<HomeBean> list, int index) {
return Container(
padding: EdgeInsets.only(top: 30, bottom: 20),
margin: EdgeInsets.only(bottom: 10),
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(list[index].image),
fit: BoxFit.fill,
),
),
child: Container(
child: Text(
'${list[index].name}',
style: TextStyle(fontSize: 12),
),
),
);
}
_titleContent() {
return Container(
child: Row(
children: [
_titleItem('imgs/home/home_road.png', '高速公路'),
_titleItem('imgs/home/home_floor.png', '智慧楼宇'),
_titleItem('imgs/home/home_idc.png', 'IDC机房'),
_titleItem('imgs/home/home_car.png', '智慧停车'),
],
),
);
}
_titleItem(String image, String text) {
return Expanded(
child: GestureDetector(
child: Column(
children: [
Image.asset(
image,
width: 55,
height: 55,
),
Text(
text,
style: TextStyle(fontSize: 14, color: ColorsUtil.black87),
),
],
),
onTap: () {
int flag = 0;
switch (text) {
case '高速公路':
flag = 3;
//统计高速公路机电设备全部设备按钮点击率
if (Global.profile.categoryAllFirstNum == null) {
Global.profile.categoryAllFirstNum = 0;
}
Global.profile.categoryAllFirstNum =
Global.profile.categoryAllFirstNum + 1;
break;
case '智慧楼宇':
flag = 0;
// 分别统计四大设备类型点击次数
if (Global.profile.categoryAllSecondNum == null) {
Global.profile.categoryAllSecondNum = 0;
}
Global.profile.categoryAllSecondNum =
Global.profile.categoryAllSecondNum + 1;
break;
case 'IDC机房':
flag = 2;
if (Global.profile.categoryAllFourthNum == null) {
Global.profile.categoryAllFourthNum = 0;
}
Global.profile.categoryAllFourthNum =
Global.profile.categoryAllFourthNum + 1;
break;
case '智慧停车':
flag = 1;
if (Global.profile.categoryAllThirdNum == null) {
Global.profile.categoryAllThirdNum = 0;
}
Global.profile.categoryAllThirdNum =
Global.profile.categoryAllThirdNum + 1;
break;
}
Navigator.push(context, MaterialPageRoute(builder: (context) {
return HomeSelectionRoute(flag: flag);
}));
},
),
);
}
//第一个card
Widget _getCard() {
return Card(
margin: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Container(
height: 110.0,
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
bottomLeft: Radius.circular(4.0))),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
// width: 100.0,
height: 70.0,
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 7,
child: Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'高速公路',
style: TextStyle(
color: Colors.white, fontSize: 12.0),
),
Text(
'机电设备',
style: TextStyle(
color: Colors.white, fontSize: 12.0),
),
],
)),
),
Expanded(
flex: 4,
child: GestureDetector(
child: Container(
width: 80.0,
alignment: Alignment.center,
margin: EdgeInsets.fromLTRB(4.0, 3.0, 4.0, 2.0),
// padding: EdgeInsets.fromLTRB(4.0,0.0,0.0,4.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular((10.0)),
color: Colors.white54),
child: Text("全部设备 >",
style: TextStyle(
fontSize: 10.0, color: Colors.redAccent)),
),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return HomeSelectionRoute(flag: 3);
}));
//统计高速公路机电设备全部设备按钮点击率
// PersonDbProvider provider = new PersonDbProvider();
// ClickModel clickModel= new ClickModel(0,0,0,0,1,0,0,0);
// provider.insert(clickModel);
if (Global.profile.categoryAllFirstNum == null) {
Global.profile.categoryAllFirstNum = 0;
}
Global.profile.categoryAllFirstNum =
Global.profile.categoryAllFirstNum + 1;
// print("categoryAllFirstNum==========${Global.profile.categoryAllFirstNum}");
},
),
)
],
),
),
Container(
alignment: Alignment.bottomRight,
child: Icon(
listIcon[3],
size: 40.0,
color: Colors.white24,
),
)
],
),
),
),
Expanded(
flex: 6,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
top: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: parentList[parentListLength]
.children
.length >=
1
? ((parentList[parentListLength]
.children[0]
.icon ==
null ||
parentList[parentListLength]
.children[0]
.icon ==
'')
? Icon(
Icons.tv,
color: Colors.redAccent,
)
: Icon(
IconData(
int.parse(parentList[
parentListLength]
.children[0]
.icon),
fontFamily:
'MaterialIcons'),
color: Colors.redAccent,
))
: Container(),
),
Expanded(
flex: 6,
child: Text(
(parentList[parentListLength]
.children
.length >
1 ||
parentList[parentListLength]
.children
.length !=
null)
? parentList[parentListLength]
.children[0]
.name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: parentList[parentListLength]
.children[0]
.id,
type: parentList[parentListLength]
.children[0]
.name,
),
));
} else {
showToast("您没有权限报修哦");
}
},
)),
),
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
top: BorderSide(
color: Colors.black12, width: 0.25)),
),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: parentList[parentListLength]
.children
.length >=
2
? ((parentList[parentListLength]
.children[1]
.icon ==
null ||
parentList[parentListLength]
.children[1]
.icon ==
'')
? Icon(
Icons.tv,
color: Colors.redAccent,
)
: Icon(
IconData(
int.parse(parentList[
parentListLength]
.children[1]
.icon),
fontFamily:
'MaterialIcons'),
color: Colors.redAccent,
))
: Container(),
),
Expanded(
flex: 6,
child: Text(
(parentList[parentListLength]
.children
.length >
2 ||
parentList[parentListLength]
.children
.length !=
null)
? parentList[parentListLength]
.children[1]
.name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: parentList[parentListLength]
.children[1]
.id,
type: parentList[parentListLength]
.children[1]
.name,
),
));
} else {
showToast("您没有权限报修哦");
}
},
)),
),
],
),
),
),
//中线
SizedBox(
child: Container(
height: 0.5,
decoration: BoxDecoration(color: Colors.black12),
),
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
bottom: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: parentList[parentListLength]
.children
.length >=
3
? ((parentList[parentListLength]
.children[2]
.icon ==
null ||
parentList[parentListLength]
.children[2]
.icon ==
'')
? Icon(
Icons.tv,
color: Colors.redAccent,
)
: Icon(
IconData(
int.parse(parentList[
parentListLength]
.children[2]
.icon),
fontFamily:
'MaterialIcons'),
color: Colors.redAccent,
))
: Container(),
),
Expanded(
flex: 6,
child: Text(
(parentList[parentListLength]
.children
.length >
3 ||
parentList[parentListLength]
.children
.length !=
null)
? parentList[parentListLength]
.children[2]
.name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: parentList[parentListLength]
.children[2]
.id,
type: parentList[parentListLength]
.children[2]
.name,
),
));
} else {
showToast("您没有权限报修哦");
}
},
)),
),
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
bottom: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: parentList[parentListLength]
.children
.length >=
4
? ((parentList[parentListLength]
.children[3]
.icon ==
null ||
parentList[parentListLength]
.children[3]
.icon ==
'')
? Icon(
Icons.tv,
color: Colors.redAccent,
)
: Icon(
IconData(
int.parse(parentList[
parentListLength]
.children[3]
.icon),
fontFamily:
'MaterialIcons'),
color: Colors.redAccent,
))
: Container(),
),
Expanded(
flex: 6,
child: Text(
(parentList[parentListLength]
.children
.length >
4 ||
parentList[parentListLength]
.children
.length !=
null)
? parentList[parentListLength]
.children[3]
.name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: parentList[parentListLength]
.children[3]
.id,
type: parentList[parentListLength]
.children[3]
.name,
),
));
} else {
showToast("您没有权限报修哦");
}
},
)),
),
],
),
)
],
),
)
],
),
);
}
//三个card
Widget _getCardList(BuildContext context, int index) {
List<Children> childrenList = [];
if (cityParentList.length != 0)
childrenList = cityParentList[index].children;
// print("childrenList[cityParentList.length-1].name==========${childrenList[cityParentList.length-1].name}");
List<Children> usualList = [];
if (childrenList.length != 0)
usualList = childrenList[childrenList.length - 1].children;
// print('usualList===========$usualList');
return Card(
margin: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Container(
height: 110.0,
decoration: BoxDecoration(
color: listColor[index],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4.0),
bottomLeft: Radius.circular(4.0))),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
// width: 100.0,
height: 70.0,
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 7,
child: Container(
alignment: Alignment.center,
child: index == 1
? Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
cityParentList.length == 0
? Text('')
: Text(
cityParentList[index].name,
style: TextStyle(
color: Colors.white,
fontSize: 12.0),
),
SizedBox(
height: 2.0,
),
Text("(E T C)",
style: TextStyle(
color: Colors.white,
fontSize: 12.0))
],
)
: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
cityParentList.length == 0
? Text('')
: Text(
cityParentList[index].name,
style: TextStyle(
color: Colors.white,
fontSize: 12.0),
),
],
)),
),
Expanded(
flex: 4,
child: GestureDetector(
child: Container(
width: 80.0,
alignment: Alignment.center,
margin: EdgeInsets.fromLTRB(4.0, 3.0, 4.0, 2.0),
// padding: EdgeInsets.fromLTRB(4.0,0.0,0.0,4.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular((10.0)),
color: Colors.white54),
child: Text("全部设备 >",
style: TextStyle(
fontSize: 10.0, color: listColor[index])),
),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return HomeSelectionRoute(flag: index);
}));
// 分别统计四大设备类型点击次数
if (index == 0) {
// PersonDbProvider provider = new PersonDbProvider();
// ClickModel clickModel= new ClickModel(1,0,0,0,0,1,0,0);
// provider.insert(clickModel);
if (Global.profile.categoryAllSecondNum ==
null) {
Global.profile.categoryAllSecondNum = 0;
}
Global.profile.categoryAllSecondNum =
Global.profile.categoryAllSecondNum + 1;
// print("categoryAllSecondNum==========${Global.profile.categoryAllSecondNum}");
} else if (index == 1) {
// PersonDbProvider provider = new PersonDbProvider();
// ClickModel clickModel= new ClickModel(1,0,0,0,0,0,1,0);
// provider.insert(clickModel);
if (Global.profile.categoryAllThirdNum ==
null) {
Global.profile.categoryAllThirdNum = 0;
}
Global.profile.categoryAllThirdNum =
Global.profile.categoryAllThirdNum + 1;
// print("categoryAllThirdNum==========${Global.profile.categoryAllThirdNum}");
} else if (index == 2) {
if (Global.profile.categoryAllFourthNum ==
null) {
Global.profile.categoryAllFourthNum = 0;
}
Global.profile.categoryAllFourthNum =
Global.profile.categoryAllFourthNum + 1;
// print("categoryAllFourthNum=========${Global.profile.categoryAllFourthNum}");
// PersonDbProvider provider = new PersonDbProvider();
// ClickModel clickModel= new ClickModel(1,0,0,0,0,0,0,1);
// provider.insert(clickModel);
}
},
),
)
],
),
),
Container(
alignment: Alignment.bottomRight,
child: Icon(
listIcon[index],
size: 40.0,
color: Colors.white24,
),
)
],
),
),
),
Expanded(
flex: 6,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
top: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: usualList.length >= 1
? ((usualList[0].icon == null ||
usualList[0].icon == '')
? Icon(
Icons.tv,
color: listColor[index],
)
: Icon(
IconData(
int.parse(
usualList[0].icon),
fontFamily:
'MaterialIcons'),
color: listColor[index],
))
: Container()),
Expanded(
flex: 6,
child: Text(
usualList.length >= 1
? usualList[0].name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
if (usualList.length >= 1) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: usualList[0].id,
type: usualList[0].name,
),
));
}
} else {
showToast("您没有权限报修哦");
}
},
)),
),
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
top: BorderSide(
color: Colors.black12, width: 0.25)),
),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: usualList.length >= 2
? ((usualList[1].icon == null ||
usualList[1].icon == '')
? Icon(
Icons.tv,
color: listColor[index],
)
: Icon(
IconData(
int.parse(
usualList[1].icon),
fontFamily:
'MaterialIcons'),
color: listColor[index],
))
: Container()),
Expanded(
flex: 6,
child: Text(
usualList.length >= 2
? usualList[1].name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
if (usualList.length >= 2) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: usualList[1].id,
type: usualList[1].name,
),
));
}
} else {
showToast("您没有权限报修哦");
}
},
)),
),
],
),
),
),
//中线
SizedBox(
child: Container(
height: 0.5,
decoration: BoxDecoration(color: Colors.black12),
),
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
bottom: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: usualList.length >= 3
? ((usualList[2].icon == null ||
usualList[2].icon == '')
? Icon(
Icons.tv,
color: listColor[index],
)
: Icon(
IconData(
int.parse(
usualList[2].icon),
fontFamily:
'MaterialIcons'),
color: listColor[index],
))
: Container()),
Expanded(
flex: 6,
child: Text(
usualList.length >= 3
? usualList[2].name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
if (usualList.length >= 3) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: usualList[2].id,
type: usualList[2].name,
),
));
}
} else {
showToast("您没有权限报修哦");
}
},
)),
),
Expanded(
child: Container(
height: 55.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.black12, width: 0.5),
bottom: BorderSide(
color: Colors.black12, width: 0.25))),
child: GestureDetector(
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: usualList.length >= 4
? ((usualList[3].icon == null ||
usualList[3].icon == '')
? Icon(
Icons.tv,
color: listColor[index],
)
: Icon(
IconData(
int.parse(
usualList[3].icon),
fontFamily:
'MaterialIcons'),
color: listColor[index],
))
: Container()),
Expanded(
flex: 6,
child: Text(
usualList.length >= 4
? usualList[3].name
: '',
style: TextStyle(fontSize: 11.0),
),
)
],
),
onTap: () {
if (Global.profile.roleFlag != 3) {
//传值
if (usualList.length >= 4) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (BuildContext context) =>
RepairAddSelection(
title: '故障报修',
typeId: usualList[3].id,
type: usualList[3].name,
),
));
}
} else {
showToast("您没有权限报修哦");
}
},
)),
),
],
),
)
],
),
)
],
),
);
}
// 登陆提示
Future<void> _neverSatisfied() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Rewind and remember'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('You will never be satisfied.'),
Text('You\’re like me. I’m never satisfied.'),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Regret'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
class MyDrawer extends StatelessWidget {
const MyDrawer({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Drawer(
child: MediaQuery.removePadding(
context: context,
// DrawerHeader consumes top MediaQuery padding.
removeTop: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildHeader(), //构建抽屉菜单头部
Expanded(child: _buildMenus()), //构建功能菜单
],
),
),
);
}
Widget _buildHeader() {
return Consumer<UserModel>(
builder: (BuildContext context, UserModel value, Widget child) {
return GestureDetector(
child: Container(
color: Theme.of(context).primaryColor,
padding: EdgeInsets.only(top: 40, bottom: 20),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ClipOval(
// 如果已登录,则显示用户头像;若未登录,则显示默认头像
child: value.isLogin
? Image.asset(
"imgs/logo_dark.png",
width: 80,
)
: Image.asset(
"imgs/avatar-default.png",
width: 80,
),
),
),
Text(
value.isLogin
? value.user.login
: GmLocalizations.of(context).login,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
),
onTap: () {
if (!value.isLogin) Navigator.of(context).pushNamed("login");
},
);
},
);
}
// 构建菜单项
Widget _buildMenus() {
return Consumer<UserModel>(
builder: (BuildContext context, UserModel userModel, Widget child) {
var gm = GmLocalizations.of(context);
return ListView(
children: <Widget>[
// ListTile(
// leading: const Icon(Icons.color_lens),
// title: Text(gm.theme),
// onTap: () => Navigator.pushNamed(context, "themes"),
// ),
// ListTile(
// leading: const Icon(Icons.language),
// title: Text(gm.language),
// onTap: () => Navigator.pushNamed(context, "language"),
// ),
// ListTile(
// leading: const Icon(Icons.update),
// title: Text(gm.uploadApp),
// onTap: () {
// //检查是否有新版本
// var update = CheckRepairUpdate.checkUpdate(context);
// update.then((value){
// if(value == null){
// //提示已是最新
// CheckRepairUpdate.showAlertDialog(context);
// }else{
// //跳转版本更新页面
// print(value['ver']);
// print(value['url']);
// // CheckRepairUpdate.doUpdate(value['ver'],value['url'],context);
// CheckRepairUpdate.doUpdate(value['ver'],value['url'],context);
// }
// });
// }
// ),
// ListTile(
// leading: const Icon(Icons.edit),
// title: Text(gm.updatePassword),
// onTap: () {
// Navigator.pushNamed(context, "updatePassword");
// },
// ),
// if(userModel.isLogin) ListTile(
// leading: const Icon(Icons.power_settings_new),
// title: Text(gm.logout),
// onTap: () {
// showDialog(
// context: context,
// builder: (ctx) {
// //退出账号前先弹二次确认窗
// return AlertDialog(
// content: Text(gm.logoutTip),
// actions: <Widget>[
// FlatButton(
// child: Text(gm.cancel),
// onPressed: () => Navigator.pop(context),
// ),
// FlatButton(
// child: Text(gm.yes),
// onPressed: () {
// print('-- no erro--');
// //该赋值语句会触发MaterialApp rebuild
// Provider.of<UserModel>(context).user = null;
// print('--error');
// Navigator.pop(context);
// // Navigator.pushNamed(context, "login");
// // Navigator.pop(context);
// Navigator.pushAndRemoveUntil(
// context,
// new MaterialPageRoute(builder: (context) => new LoginRoute()),
// (route) => route == null,
// );
// },
// ),
// ],
// );
// },
// );
// },
// ),
],
);
},
);
}
}
相关文章
- 03-20Flutter TabBar自定义宽度设置圆角
- 03-20六、Flutter自定义Tabbar
- 03-20Flutter系列之设置TabBar的tab紧凑排列
- 03-20自定义view 设置FrameLayout最大宽度比,view最大宽度比
- 03-20自定义PopupWindow 怎么设置PopupWindow的宽度充满全屏宽度
- 03-20flutter 自定义tabbar 给tabbar添加背景功能
- 03-20Flutter ButtonStyle设置圆角
- 03-20bootstrap插件bootbox参数和自定义弹出框宽度设置
- 03-20Flutter移动电商实战 --(49)详细页_自定义TabBar Widget
- 03-20Flutter移动电商实战 --(47)详细页_自定义TabBar Widget