hyzp_ybqx-Commit001:代码刚转换好,编译通过

This commit is contained in:
WinUser01
2021-12-09 20:24:36 +08:00
commit 8c74b14e5c
800 changed files with 66912 additions and 0 deletions
+688
View File
@@ -0,0 +1,688 @@
import 'package:hyzp_ybqx/components/commonFun.dart';
import 'package:hyzp_ybqx/components/dioFun.dart';
import 'package:hyzp_ybqx/components/hyxx_data_handle.dart';
import 'package:hyzp_ybqx/services/EventBus.dart';
///获取车流量日统计数据
bool cllRStatisDataGeting = false; //正在获取车流量日统计数据,禁止重入
bool cllRStatisDataOk = false; //listCllrtjStatis 中的数据是否准备好
//List listCllrtjStatis = [];
// [
// {
// "dwbh": 4,
// "dwmc": "一曼路",
// "dwip": "172.16.3.4"
// "all": "770742",
// "cllmx": [
// {
// "day": "2021-04-12",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "17760",
// "am": "1272",
// "pm": "3153"
// },
// {
// "day": "2021-04-11",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "18005",
// "am": "1677",
// "pm": "2275"
// },
// // ...
// ]
// },
// {
// "dwbh": 5,
// "dwmc": "柏溪收费站",
// "dwip": "172.16.3.5"
// "all": "770742",
// "cllmx": [
// {
// "day": "2021-04-12",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "17760",
// "am": "1272",
// "pm": "3153"
// },
// {
// "day": "2021-04-11",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "18005",
// "am": "1677",
// "pm": "2275"
// },
// // ...
// ]
// },
// ]
///获取抓拍统计数据
List listZptjStatis = [];
///获取审核黑烟车统计数据
List listSh_hyc_tjStatis = [];
///获取审核黑烟车统计数据
List listClltjStatis = [];
///获取车流量日统计数据
List listCllrtjStatis = [];
bool statisDataOk = false; //listCllrtjStatis 中的数据是否准备好
Map mapCllrtjStatis = {};
/*
{
"total": 6635167,
"am": 713074,
"pm": 981656,
"view": [
{
"dwip": "172.16.3.1",
"dw_all": 701120,
"dw_am": 76210,
"dw_pm": 105153,
"cllmx": [
{
"day": "2021-05-25",
"am_order": "0730:0930",
"pm_order": "1730:1930",
"all": "24190",
"am": "2148",
"pm": "5173"
},
{
"day": "2021-05-24",
"am_order": "0730:0930",
"pm_order": "1730:1930",
"all": "20254",
"am": "1825",
"pm": "3975"
},
...
},
{
"dwip": "172.16.3.2",
"dw_all": 533990,
"dw_am": 65276,
"dw_pm": 78055,
"cllmx": [
{
"day": "2021-05-25",
"am_order": "0730:0930",
"pm_order": "1730:1930",
"all": "16355",
"am": "1375",
"pm": "3029"
},
{
"day": "2021-05-24",
"am_order": "0730:0930",
"pm_order": "1730:1930",
"all": "15997",
"am": "1797",
"pm": "2216"
},
...
*/
// [
// {
// "dwbh": 4,
// "dwmc": "一曼路",
// "dwip": "172.16.3.4"
// "all": "770742",
// "cllmx": [
// {
// "day": "2021-04-12",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "17760",
// "am": "1272",
// "pm": "3153"
// },
// {
// "day": "2021-04-11",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "18005",
// "am": "1677",
// "pm": "2275"
// },
// // ...
// ]
// },
// {
// "dwbh": 5,
// "dwmc": "柏溪收费站",
// "dwip": "172.16.3.5"
// "all": "770742",
// "cllmx": [
// {
// "day": "2021-04-12",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "17760",
// "am": "1272",
// "pm": "3153"
// },
// {
// "day": "2021-04-11",
// "am_order": "0730:0930",
// "pm_order": "1730:1930",
// "all": "18005",
// "am": "1677",
// "pm": "2275"
// },
// // ...
// ]
// },
// ]
// 一次性获取所有点位的统计数据存入 listCllrtjStatis
Future getCllrtjStatisNew(String statisType) async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listCllrtjStatis.clear();
mapCllrtjStatis = await getStatisData(statisType: statisType);
listCllrtjStatis = mapCllrtjStatis["view"];
// int len = listDwinfoGetList2.length;
// for (int i = 0; i < len; i++) {
// Map map = await getStatisData(statisType: statisType, ip: listDwinfoGetList2[i]['dwip']);
// map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
// map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
// map['dwip'] = listDwinfoGetList2[i]['dwip'];
// listCllrtjStatis.add(map);
// }
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
//遍历 listDwinfoGetList2 中所有点位,得到对应点位 ip 的统计数据存入 listCllrtjStatis
Future getCllrtjStatis(String statisType) async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listCllrtjStatis.clear();
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map = await getStatisData(statisType: statisType, ip: listDwinfoGetList2[i]['dwip']);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listCllrtjStatis.add(map);
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
//遍历 listDwinfoGetList2 中所有点位,得到对应点位 ip 的统计数据存入 listZptjStatis
Future getZptjStatis(String statisType) async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listZptjStatis.clear();
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map = await getStatisData(statisType: statisType, ip: listDwinfoGetList2[i]['dwip']);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listZptjStatis.add(map);
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
//在Dart语言中,如何通过值获取MAP键?mapTjDataText
String getKey(String value) {
String key = mapTjDataText.keys.firstWhere((k) => mapTjDataText[k] == value, orElse: () => null);
}
Map<String, String> mapTjDataText = {
"dwmc": '点位名称',
"dwbh": '点位编号',
"dwip": '点位IP',
"today": '今日',
"all": '总共',
"total": '已审核',
"sends": '已推送'
};
//////////////////////////////////////////////////////////////////
///独立获取抓拍统计数据
List listZptjStatisAlone = [];
List listTodayZpjl = []; //今日抓拍记录列表
//遍历 listDwinfoGetList2 中所有点位,独立得到对应点位 ip 的统计数据存入 listZptjStatisNew
Future getZptjStatisAlone() async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listZptjStatisAlone.clear();
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map = await getStatisData(statisType: 'zptj', ip: listDwinfoGetList2[i]['dwip']);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listZptjStatisAlone.add(map);
// if (listZptjStatisAlone.length >= dwSum) {
// //发送统计数据已更新广播
// eventBus.fire(StatisDataUpdate('统计数据已更新'));
// }
getAllSum('today', listZptjStatisAlone).then((value) {
//mapStatisInfo['今日抓拍'] = value[1];
listTodayZpjl = value[2];
//try_setState();
});
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
///独立获取今日审核统计数据
List listTodayShtj = [];
List listTodayChjl = []; //今日初审记录列表
List listTodayFhjl = []; //今日复审记录列表
List listTodayTsjl = []; //今日推送记录列表
//遍历 listDwinfoGetList2 中所有点位,独立得到对应点位 ip 的统计数据存入 listShtjStatisNew
Future getTodayShtj() async {
//今日审核统计数据
//{
// "total": 0,"today": 0,
// "sends": 0,"all": 72
// "csnum": 0,"dwbh": 1,
// "fsnum": 0"dwmc": "江北振兴大道",
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listTodayShtj.clear();
DateTime dateTime = DateTime.now();
String _mouth = dateTime.month.toString().trim();
if (_mouth.length == 1) {
_mouth = '0' + _mouth;
}
String _day = dateTime.day.toString().trim();
if (_day.length == 1) {
_day = '0' + _day;
}
String date = '${dateTime.year}-${_mouth}-${_day}';
print('date = $date');
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map =
await getStatisData(statisType: 'sh_hyc_tj', ip: listDwinfoGetList2[i]['dwip'], date: date);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listTodayShtj.add(map);
// if (listTodayShtj.length >= dwSum) {
// print('listTodayShtj = $listTodayShtj');
// //发送统计数据已更新广播
// eventBus.fire(StatisDataUpdate('统计数据已更新'));
// }
getAllSum('csnum', listTodayShtj).then((value) {
//mapStatisInfo['今日初审'] = value[1];
listTodayChjl = value[2];
//try_setState();
});
getAllSum('fsnum', listTodayShtj).then((value) {
//mapStatisInfo['今日复审'] = value[1];
listTodayFhjl = value[2];
//try_setState();
});
getAllSum('sends', listTodayShtj).then((value) {
//mapStatisInfo['今日推送'] = value[1];
listTodayTsjl = value[2];
//try_setState();
});
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
///独立获取审核统计数据
List listShtjStatisAlone = [];
//遍历 listDwinfoGetList2 中所有点位,独立得到对应点位 ip 的统计数据存入 listShtjStatisNew
Future getShtjStatisAlone() async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listShtjStatisAlone.clear();
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map = await getStatisData(statisType: 'sh_hyc_tj', ip: listDwinfoGetList2[i]['dwip']);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listShtjStatisAlone.add(map);
// if (listShtjStatisAlone.length >= dwSum) {
// //发送统计数据已更新广播
// eventBus.fire(StatisDataUpdate('统计数据已更新'));
// }
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
///独立获取车流量统计数据
List listClltjStatisAlone = [];
//遍历 listDwinfoGetList2 中所有点位,独立得到对应点位 ip 的统计数据存入 listShtjStatisNew
Future getClltjStatisAlone() async {
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
///从接口 mapStatisType[statisType]['api'] 获取指定 ip 的 statisType 类型的统计数据,返回 Map
//Future getStatisData({@required String statisType, @required String ip}) async {
listClltjStatisAlone.clear();
int len = listDwinfoGetList2.length;
for (int i = 0; i < len; i++) {
Map map = await getStatisData(statisType: 'clltj', ip: listDwinfoGetList2[i]['dwip']);
map['dwbh'] = listDwinfoGetList2[i]['dwbh'];
map['dwmc'] = listDwinfoGetList2[i]['dwmc'];
map['dwip'] = listDwinfoGetList2[i]['dwip'];
listClltjStatisAlone.add(map);
// if (listClltjStatisAlone.length >= dwSum) {
// //发送统计数据已更新广播
// eventBus.fire(StatisDataUpdate('统计数据已更新'));
// }
}
//print('listZptjStatis = ${listZptjStatis}');
//StorageDataToFile.writeCounter(json_print(listZptjStatis, 1));
}
//////////////////////////////////////////////////////////////////
///获取所有统计数据
List listAllStatisData = [];
///车流量日统计数据类
var trinityData;
// 实现多个基于 Page1_Works 构建的页面共享统计数据
Future startGetStatisDataNew() async {
///获取点位信息数据
//listDwinfoGetList2.clear();
if (listDwinfoGetList2.isEmpty) {
//若没有读取点位数据,便需要先读取
getThePageList(theHyshlx: 'dwxx').then((value) {
listDwinfoGetList2 = value;
print('listDwinfoGetList2 = \n$listDwinfoGetList2');
dwSum = listDwinfoGetList2.length;
//获取记录数据
getZptjStatisAlone();
getTodayShtj();
getClltjStatisAlone();
//获取统计数据
getAllStatisData().then((value) {
listAllStatisData = value;
eventBus.fire(StatisDataUpdate('统计数据已更新'));
});
});
} else {
if (mapStatisInfo['今日抓拍'] < 0) {
//获取记录数据
getZptjStatisAlone();
getTodayShtj();
getClltjStatisAlone();
//获取统计数据
getAllStatisData().then((value) {
listAllStatisData = value;
eventBus.fire(StatisDataUpdate('统计数据已更新'));
});
} else {
//发送统计数据已更新广播
eventBus.fire(StatisDataUpdate('统计数据已更新'));
}
}
}
Map<String, double> mapStatisInfo = {
'今日抓拍': -1,
'今日初审': -1,
'今日复审': -1,
'今日推送': -1,
'今日车流': -1,
};
//得到所有5项统计数据
//适用的字段:抓拍统计的'today'、all;审核统计的"total"、"sends";
Future getAllSumNew() async {
int items = 0;
mapStatisInfo['今日抓拍'] = 0;
mapStatisInfo['今日初审'] = 0;
mapStatisInfo['今日复审'] = 0;
mapStatisInfo['今日推送'] = 0;
mapStatisInfo['今日车流'] = 0;
for (var item in listAllStatisData) {
items++;
if (item["zp_today"] > 0) {
//listRecords.addAll(item[field]["data"]); //将记录详情存入listRecords
mapStatisInfo['今日抓拍'] += item["zp_today"];
}
if (item["csnum"] > 0) {
mapStatisInfo['今日初审'] += item["csnum"];
}
if (item["fsnum"] > 0) {
mapStatisInfo['今日复审'] += item["fsnum"];
}
if (item["sends"] > 0) {
mapStatisInfo['今日推送'] += item["sends"];
}
if (item["cll_today"] > 0) {
mapStatisInfo['今日车流'] += item["cll_today"];
}
}
mapStatisInfo['今日车流'] = mapStatisInfo['今日车流'] / 10000;
// 统计点位数(未用),总计,记录列表
//return [items, sum, listRecords];
}
/*
[
{
"id": 1,
"dwip": "172.16.3.1",
"dwmc": "锦绣花园",
"zp_all": 54,
"hyc_all": 52,
"zp_today": 1,
"sends": 0,
"send_all": 33,
"csnum": 1,
"fsnum": 0,
"cll_today": 6420,
"cll_all": 3225733
},
{
"id": 2,
"dwip": "172.16.3.2",
"dwmc": "石马溪桥",
"zp_all": 377,
"hyc_all": 370,
"zp_today": 1,
"sends": 0,
"send_all": 204,
"csnum": 1,
"fsnum": 0,
"cll_today": 3430,
"cll_all": 2127839
},
...
]
*/
// 实现多个基于 Page1_Works 构建的页面共享统计数据
Future startGetStatisDataOld() async {
///获取点位信息数据
//listDwinfoGetList2.clear();
if (listDwinfoGetList2.isEmpty) {
//若没有读取点位数据,便需要先读取
getThePageList(theHyshlx: 'dwxx').then((value) {
listDwinfoGetList2 = value;
print('listDwinfoGetList2 = \n$listDwinfoGetList2');
dwSum = listDwinfoGetList2.length;
getZptjStatisAlone();
getTodayShtj();
getClltjStatisAlone();
});
} else {
if (mapStatisInfo['今日抓拍'] < 0) {
getZptjStatisAlone();
} else {
//发送统计数据已更新广播
eventBus.fire(StatisDataUpdate('统计数据已更新'));
}
if (mapStatisInfo['今日初审'] < 0) {
getTodayShtj();
} else {
//发送统计数据已更新广播
eventBus.fire(StatisDataUpdate('统计数据已更新'));
}
if (mapStatisInfo['今日车流'] < 0) {
getClltjStatisAlone();
} else {
//发送统计数据已更新广播
eventBus.fire(StatisDataUpdate('统计数据已更新'));
}
}
}
//获取已审核黑烟车统计数据:App.Car_Statis.GetStaHyc
//{
// "ret": 200,
// "data": {
// "total": 40,
// "sends": {
// "total": 0,
// "data": []
// },
// "csnum": {
// "total": 0,
// "data": []
// },
// "fsnum": {
// "total": 0,
// "data": []
// }
// },
// "msg": ""
// }
//获取抓拍统计数据:App.Car_Statis.GetStaYjxx
//{
// "ret": 200,
// "data": {
// "today": {
// "total": 0,
// "data": []
// },
// "all": 40
// },
// "msg": ""
// }
//得到 listStatis[field] 的统计数据,
//适用的字段:抓拍统计的'today'、all;审核统计的"total"、"sends";
Future getAllSum(String field, List listStatis) async {
int items = 0;
int sum = 0;
List listRecords = []; //记录详情存入
for (var item in listStatis) {
if (item[field]["total"] > 0) {
items++;
listRecords.addAll(item[field]["data"]); //将记录详情存入listRecords
sum += item[field]["total"];
}
}
return [items, sum, listRecords];
}
//获取车流量统计数据:App.Car_Statis.GetStaCll
//{
// "ret": 200,
// "data": {
// "today": 7010,
// "all": 1640350
// },
// "msg": ""
//}
//得到 listStatis[field] 的统计数据,
//适用的字段:车流量统计的'today'、all
Future getAllSumCll(String field, List listStatis) async {
int items = 0;
int sum = 0;
for (var item in listStatis) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
//////////////////////////////////////////////////////////////////
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,778 @@
//import '../../../widget/player_pro.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_drag_scale/flutter_drag_scale.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx/widget/my_superplayer.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';
//
import '../../../components/commonFun.dart';
import '../../../components/doJSON.dart';
import '../../../components/hyxx_data_handle.dart';
// "today": {
// "total": 4,
// "data": [
// {
// "id": 428549,
// "car_number": "川15A2563",
// "cpys": "绿色",
// "zpsj": "2021-04-04 11:31:11",
// "dwip": "172.16.3.3",
// "dwms": "岷江南路森林小区附近",
// "cplx": "农用车",
// "lgmzs": 3,
// "pic_url": "/wwwroot/admin/Api/wwwroot/public/uploads/e936524e92f90541cbaeca3b092c95be.jpg",
// "video_url": "video/3_6063_20210404_113111_川15A2563.mp4"
// },
class TodayListZpjlContent extends StatefulWidget {
TodayListZpjlContent({
@required this.hyshlx,
@required this.num,
@required this.text,
@required this.mapZpjl,
this.tsztText = '',
Key key,
}) : super(key: key);
String hyshlx;
String num;
String text;
Map mapZpjl;
String tsztText;
_TodayListZpjlPageState createState() => _TodayListZpjlPageState();
}
//用TabController实现顶部tab切换
class _TodayListZpjlPageState extends State<TodayListZpjlContent> {
//try_setState(); //避免如下异常报错
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
dispose() {
super.dispose();
}
BuildContext _context;
//flutter_screenUtil 4.x 用法,ScreenUtil.screenWidth (sdk>=2.6 : 1.sw) //设备宽度
double _screenWidth = 1.sw;
double _marginLeft = 25;
double _marginCenter = 35;
double _fontSize = 16;
double _widthLeft = 40; // = _screenWidth / 3;
double _iconSize = 18;
double _stampSize = 100;
double _listTileHeight = 30;
Color _iconColor = Colors.blue;
double _marginVer = 10;
Map _mapTsjjGetTsStatus = {};
Map mapName = {};
void initState() {
_context = context;
_widthLeft = _screenWidth / 2.6;
//getListFlields();
//得到字段名称
mapName['plate_id'] = widget.hyshlx == 'jrzp' ? 'car_number' : 'plate_id';
mapName['plate_color'] = widget.hyshlx == 'jrzp' ? 'cpys' : 'plate_color';
imageWztp = getWztp(); //得到违章图片
super.initState();
}
double _radioImage = 9 / 16;
// 使用 cached_network_image 插件实现网络图片缓存
// 使用 flutter_drag_scale 实现可缩放可拖拽双击放大的图片功能。PhotoView插件不好用,有问题
Widget getNetworkImage(String url) {
return CachedNetworkImage(
imageUrl: url,
alignment: Alignment.topCenter,
imageBuilder: (context, imageProvider) => DragScaleContainer(
doubleTapStillScale: true, child: Image(image: imageProvider)
// child: Image(
// image: NetworkImage(
// 'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg'),
// ),
),
// imageBuilder: (context, imageProvider) => PhotoView(
// imageProvider: imageProvider,
// ),
//placeholder: (context, url) => CircularProgressIndicator(),
placeholder: (context, url) =>
getMoreWidget(color: Colors.black38, size: 20.0, strokeWidth: 2.0),
errorWidget: (context, url, error) => Icon(Icons.error),
);
}
// 167 50 3.34
Widget getLgmzs(int lgmzs, {double width = 127, double height = 127}) {
int _rgb = (255 * (5 - lgmzs)) ~/ 5;
return Stack(
children: [
Container(
width: ScreenUtil().setWidth(width),
height: ScreenUtil().setHeight(height),
padding: EdgeInsets.only(
right: ScreenUtil().setWidth(6), left: ScreenUtil().setWidth(6), top: 0, bottom: 4),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text('$lgmzs级${lgmzs * 20}%', style: TextStyle(fontSize: 10)),
//SizedBox(height: 0),
Container(
width: ScreenUtil().setWidth(66),
height: ScreenUtil().setHeight(66),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
color: Color.fromRGBO(_rgb, _rgb, _rgb, 1.0),
borderRadius: new BorderRadius.circular(0),
),
)
],
),
),
Positioned(
top: ScreenUtil().setHeight(4),
child: Container(
width: ScreenUtil().setWidth(width),
height: ScreenUtil().setHeight(height - 8),
padding: EdgeInsets.only(
right: ScreenUtil().setWidth(6), left: ScreenUtil().setWidth(6), top: 0, bottom: 0),
decoration: BoxDecoration(
border: Border.all(
color: (lgmzs == widget.mapZpjl['lgmzs'])
? Colors.red
: Color.fromRGBO(244, 244, 244, 1),
width: 2),
//color: Colors.lightBlue,
borderRadius: new BorderRadius.circular(3.0),
),
),
)
],
);
}
//得到tsjj页面组件
//1、得到格林曼黑度标准和视频播放按钮组件
Widget getHdAndPlay() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getLgmzs(0),
getLgmzs(1),
getLgmzs(2),
getLgmzs(3),
getLgmzs(4),
getLgmzs(5, width: 153),
getIconBtnSizeX(
height: 104,
//getIconBtnSizeX 中已经使用ScreenUtil().setHeight(126),此处不能传 ScreenUtil().setHeight(126) ,否则严重错位
width: 168,
text: "视频",
textSize: 12,
circular: 4,
color: Color.fromRGBO(52, 157, 237, 1),
onTop: () async {
if (Playing) {
//禁止同时启动两次播放器
return;
}
Playing = true; //禁止同时启动两次播放器
urlnew = getMediaUrl(widget.mapZpjl['video_url']);
//获取视频地址失败
if (!isVideoUrl(urlnew)) {
return;
}
Navigator.of(_context).push(MaterialPageRoute(
builder: (context) => SuperPlayerPage(
loop: 0, //设置播放循环,默认播放器的循环次数是1, 即不循环播放。如果设置循环次数0,表示无限循环。
url: urlnew,
title:
'${widget.text}视频${widget.num}\n${widget.mapZpjl[mapName['plate_id']]}(${getDwmc(widget.mapZpjl['dwip'])})')));
// Navigator.of(_context).push(MaterialPageRoute(
// builder: (context) => PlayerProNew(
// loop: 0, //设置播放循环,默认播放器的循环次数是1, 即不循环播放。如果设置循环次数0,表示无限循环。
// url: urlnew,
// title:
// '${widget.text}视频${widget.num}\n${widget.mapZpjl[mapName['plate_id']]}(${getDwmc(widget.mapZpjl['dwip'])})')));
},
),
SizedBox(width: ScreenUtil().setWidth(15)),
],
);
}
Widget imageWztp;
//2、得到违章图片组件
Widget getWztp() {
//ratioList[index] = 0.5714285714285714
return Stack(
children: [
Container(
width: ScreenUtil().setWidth(1022),
//height: ScreenUtil().setHeight(639),
//height: ScreenUtil().setHeight(22 + 1022 * _radioImage),
height: ScreenUtil().setHeight(30 + 1022 * _radioImage),
decoration: BoxDecoration(
//color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
),
Positioned(
//left: ScreenUtil().setWidth(_marginLeft),
top: ScreenUtil().setHeight(_marginLeft),
child: Container(
width: ScreenUtil().setWidth(1022),
height: ScreenUtil().setHeight(30 + 1022 * _radioImage),
child: getNetworkImage(getMediaUrl(widget.mapZpjl['pic_url'])),
),
)
],
);
}
// void printScreenInformation() {
// print('Device width dp:${1.sw}dp');
// print('Device height dp:${1.sh}dp');
// print('Device pixel density:${ScreenUtil().pixelRatio}');
// print('Bottom safe zone distance dp:${ScreenUtil().bottomBarHeight}dp');
// print('Status bar height dp:${ScreenUtil().statusBarHeight}dp');
// print('The ratio of actual width to UI design:${ScreenUtil().scaleWidth}');
// print(
// 'The ratio of actual height to UI design:${ScreenUtil().scaleHeight}');
// print('System font scaling:${ScreenUtil().textScaleFactor}');
// print('0.5 times the screen width:${0.5.sw}dp');
// print('0.5 times the screen height:${0.5.sh}dp');
// }
void printScreenInformation() {
print('ScreenUtil().screenWidth = ${ScreenUtil().screenWidth}');
print('设备宽度:${1.sw}dp');
print('"1.w" = ${1.w}');
print('"1.sw" = ${1.sw}');
print('设备高度:${1.sh}dp');
print('设备的像素密度:${ScreenUtil().pixelRatio}');
print('底部安全区距离:${ScreenUtil().bottomBarHeight}dp');
print('状态栏高度:${ScreenUtil().statusBarHeight}dp');
print('实际宽度的dp与设计稿px的比例:${ScreenUtil().scaleWidth}');
print('实际高度的dp与设计稿px的比例:${ScreenUtil().scaleHeight}');
print('宽度和字体相对于设计稿放大的比例:${ScreenUtil().scaleWidth * ScreenUtil().pixelRatio}');
print('高度相对于设计稿放大的比例:${ScreenUtil().scaleHeight * ScreenUtil().pixelRatio}');
print('系统的字体缩放比例:${ScreenUtil().textScaleFactor}');
print('屏幕宽度的0.5:${0.5.sw}dp');
print('屏幕高度的0.5:${0.5.sh}dp');
}
//3、得到违章图片说明信息组件
Widget getWztpSmxx() {
return Container(
width: ScreenUtil().setWidth(1022),
height: ScreenUtil().setHeight(390),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//违章信息组件1:车牌号码、车牌颜色
getWzxxPart1(),
//违章信息组件2:抓拍时间组件
getWzxxText('抓拍时间:' + widget.mapZpjl['zpsj']),
//违章信息组件3:车牌类型 + 黑度
getWzxxPart3(),
//违章信息组件4:抓拍地点(简称)
getWzxxText('抓拍地点:' + getDwmc(widget.mapZpjl['dwip']) + ' (简称)'),
//违章信息组件5:抓拍地点
getWzxxText('抓拍地点:' + widget.mapZpjl['dwms']),
],
),
);
}
// I/flutter (22989): ScreenUtil().screenWidth = 360.0
// I/flutter (22989): 设备宽度:360.0dp
// I/flutter (22989): "1.w" = 0.3333333333333333
// I/flutter (22989): "1.sw" = 360.0
// I/flutter (22989): 设备高度:640.0dp
// I/flutter (22989): 设备的像素密度:3.0
// I/flutter (22989): 底部安全区距离:0.0dp
// I/flutter (22989): 状态栏高度:24.0dp
// I/flutter (22989): 实际宽度的dp与设计稿px的比例:0.3333333333333333
// I/flutter (22989): 实际高度的dp与设计稿px的比例:0.3333333333333333
// I/flutter (22989): 宽度和字体相对于设计稿放大的比例:1.0
// I/flutter (22989): 高度相对于设计稿放大的比例:1.0
// I/flutter (22989): 系统的字体缩放比例:1.0
// I/flutter (22989): 屏幕宽度的0.5:180.0dp
// I/flutter (22989): 屏幕高度的0.5:320.0dp
//3、得到违章信息组件1:车牌号码、车牌颜色
//车牌颜色Map cpysMap = {
// '蓝色': cpysItem(
// cpysText: '蓝色',
// cpysBackground: Colors.blue,
// cpysFont: Colors.white,
// cpysBorder: Colors.orange),
// }
Widget getWzxxPart1() {
//printScreenInformation();
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
getTitleText('车牌号码:'),
getBoderText(widget.mapZpjl[mapName['plate_id']].toString(),
width: ScreenUtil().setWidth(1022 / 3.2)),
Expanded(child: SizedBox.shrink()),
getTitleText('颜色:'),
getBoderText(widget.mapZpjl[mapName['plate_color']],
width: ScreenUtil().setWidth(1022 / 4.8)),
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
],
);
}
Widget getTitleRichText(String text1, {String text2 = '', double fontSize = 16}) {
return RichText(
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.left,
text: TextSpan(
text: text1,
style: TextStyle(fontSize: fontSize, color: Colors.black),
children: [
TextSpan(
text: text2,
style: TextStyle(fontSize: fontSize, color: Colors.blue, fontWeight: FontWeight.w500),
),
],
),
);
}
Widget getTitleText(String text, {double fontSize = 16}) {
return Text(text,
style: TextStyle(fontSize: fontSize),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis);
}
Widget getTrailText(String text, {double fontSize = 16, double off = 0}) {
return Container(
width: _screenWidth - _widthLeft - off - (2 * ScreenUtil().setWidth(_marginLeft)),
child: Text(text,
style: TextStyle(fontSize: fontSize),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis),
);
}
Widget getBoderText(String text, {double width = 40}) {
cpysItem _cpysItem = cpysMap[widget.mapZpjl[mapName['plate_color']]];
return Container(
//color: _cpysItem.cpysBackground,
alignment: Alignment(0, -1),
width: width,
decoration: BoxDecoration(
border: Border.all(color: _cpysItem.cpysBorder, width: 2),
color: _cpysItem.cpysBackground,
borderRadius: BorderRadius.circular(3),
),
child: Padding(
padding: EdgeInsets.only(bottom: 3),
child: Text(text,
style: TextStyle(fontSize: _fontSize, color: _cpysItem.cpysFont),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis),
),
);
}
//I/flutter (17555): mapZpjl = {
// id: 1222, plate_id: 川Q736X2, plate_color: 蓝色, zpsj: 1612857077, yjxx_id: 1399, workflow: 999,
// video_url: video/9_6063_20210209_155117_川Q736X2.mp4,
// pic_url: /wwwroot/admin/Api/wwwroot/public/uploads/9d2f45fd24b41f2b94abe42b30970d75.jpg,
// clfl: 集装箱卡车, dwip: 172.16.3.9, dwms: 宜长路出城方向, lgmzs: 3, jczxd: 994, sfhy: 黑烟车
// }
Widget getIcon(IconData _iconData) {
return Container(
width: _iconSize - 2,
height: _iconSize,
child: Padding(
padding: EdgeInsets.only(top: 2),
child: Icon(_iconData, size: _iconSize, color: _iconColor),
),
);
}
Widget getWzxxText(String _text, {double fontSize = 16}) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Container(
alignment: Alignment(-1, 0),
width: ScreenUtil().setWidth(1022) - ScreenUtil().setWidth(_marginLeft),
child: Text(_text,
style: TextStyle(fontSize: fontSize),
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis),
),
],
);
}
Widget getWzxxPart3() {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Container(
alignment: Alignment(-1, 0),
//width: ScreenUtil().setWidth(1022) - ScreenUtil().setWidth(_marginLeft),
child: getTitleText('车牌类型:' + widget.mapZpjl['cplx']),
),
Expanded(child: SizedBox.shrink()),
//getTitleText('黑度: ${widget.mapZpjl['lgmzs']}'),
getTitleRichText('黑度:', text2: '${widget.mapZpjl['lgmzs']} '),
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
],
);
}
Widget getText(String text, {Color color}) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment(-1, 0),
width: ScreenUtil().setWidth(1022 - 2 * _marginLeft),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Text(text,
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: color))
],
),
),
],
);
}
Widget getText2(String text1, String text2, String text3, {Color color}) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment(-1, 0),
width: ScreenUtil().setWidth(1022 - 2 * _marginLeft),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Text(text1, textAlign: TextAlign.left),
Text(text2,
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: color, fontWeight: FontWeight.w500)),
Text(text3, textAlign: TextAlign.left),
],
),
),
],
);
}
//5、得到黑烟初审'hycsInfo'、或者黑烟'hyfhInfo'複核信息组件
//style: TextStyle(fontSize: _fontSize),
Widget getHyshInfo(String _hyshInfo) {
String _hyshLx = (_hyshInfo == 'hycsInfo' ? '初审' : '复审'); //黑烟审核类型
String _hyshYh = (_hyshInfo == 'hycsInfo' ? 'cs_username' : 'fs_username'); //黑烟审核用户
String _hyshSj = (_hyshInfo == 'hycsInfo' ? 'cs_time' : 'fs_time'); //黑烟审核时间
String _hyshJg = (_hyshInfo == 'hycsInfo' ? 'cs_tile' : 'fs_tile'); //黑烟审核结果
String _hyshYj = (_hyshInfo == 'hycsInfo' ? 'cs_shuoming' : 'fs_shuoming'); //黑烟审核意见
double _height = _hyshInfo == 'hyfhInfo' && widget.hyshlx == 'tsjj' ? 315 : 265;
return Column(
children: [
Container(
width: ScreenUtil().setWidth(1022),
height: ScreenUtil().setHeight(_height),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(12),
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
alignment: Alignment(-1, 0),
width: ScreenUtil().setWidth(1022 - 2 * _marginLeft),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Text('${_hyshLx}结果:' + widget.mapZpjl[_hyshJg],
textAlign: TextAlign.left, overflow: TextOverflow.ellipsis),
SizedBox(width: ScreenUtil().setWidth(20)),
Container(
width: my_iconSize,
height: my_iconSize,
decoration: widget.mapZpjl[_hyshJg] == ''
? null
: BoxDecoration(
//color: Colors.white,
image: DecorationImage(
image: AssetImage(widget.mapZpjl[_hyshJg] == "黑烟车"
? "assets/images/hyc.png"
: "assets/images/fhyc.png"),
fit: BoxFit.contain),
),
alignment: Alignment.center,
//child:
),
],
),
),
],
),
getText('${_hyshLx}意见:' + widget.mapZpjl[_hyshYj]),
getText('${_hyshLx}用户:' + widget.mapZpjl[_hyshYh]),
getText('${_hyshLx}时间:' + widget.mapZpjl[_hyshSj]),
_hyshInfo == 'hyfhInfo' && widget.hyshlx == 'tsjj'
? (getText2('推送状态:', widget.tsztText, ' (${getDate(widget.mapZpjl['ts_time'])})',
color:
widget.tsztText.indexOf('成功') >= 0 ? Colors.blueAccent : Colors.black26))
: SizedBox.shrink(),
],
),
),
SizedBox(height: ScreenUtil().setHeight(_marginVer)),
],
);
}
//9、得到推送交警状态信息组件7:推送状态
// tszt 整型 推送状态:0-未推送 | 1-推送失败 | 3-推送成功
//_mapTsjjGetTsStatus['tszt']
Widget getWzxxPart7() {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: ScreenUtil().setWidth(_marginLeft)),
Container(
alignment: Alignment(-1, 0),
width: _screenWidth - ScreenUtil().setWidth(_marginLeft),
child: getTitleText('推送状态:' + mapTsztText[_mapTsjjGetTsStatus['tszt']]),
),
],
);
}
//10、得到推送交警确认组件
Widget getTsjjQr() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "返回",
onPressedFun: () async {
Navigator.pop(context);
},
width: 90.0),
],
);
}
bool showMoreWidget = false;
@override
Widget build(BuildContext context) {
return Scaffold(
//resizeToAvoidBottomPadding: false,
appBar: PreferredSize(
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
// 设置appBar高度
child: AppBar(
automaticallyImplyLeading: false,
centerTitle: true,
titleSpacing: 0.0,
//设置title的左边距
flexibleSpace: Container(
//SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
// SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
child: Container(
//height: ScreenUtil().setHeight(173),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(12, 186, 156, 1),
Color.fromRGBO(39, 127, 235, 1),
],
),
),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [
// Color(0xFF0018EB),
// Color(0xFF01C1D9),
// ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
// ),
),
),
title: Padding(
padding: EdgeInsets.only(left: 0, right: 0),
child: Row(
//mainAxisAlignment: MainAxisAlignment.start,
children: [
getIconAndTextButton(
iconColor: Colors.white,
iconData: Icons.chevron_left_outlined,
onPress: showMoreWidget
? null
: () {
Navigator.pop(context);
},
),
Expanded(
child: Text(widget.text + '记录' + widget.num,
style: TextStyle(color: Colors.white, fontSize: 20),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis),
),
SizedBox(width: 30),
],
),
),
),
),
body: null == imageWztp
// 显示加载中的圈圈
? getMoreWidget(color: Colors.black38, size: 20.0, strokeWidth: 2.0)
: Stack(
children: [
//SizedBox.shrink() 创建父类允许最小尺寸的约束Box
showMoreWidget
? Align(
alignment: Alignment(0, 0.8),
child: Container(
height: 200,
width: 200,
child: getMoreWidget2(
text: '加载中...',
color: Colors.red,
size: 40.0,
strokeWidth: 3.0), //显示加载中的圈圈,
),
)
: SizedBox.shrink(),
KeyboardAvoider(
autoScroll: true,
child: Container(
color: Color.fromRGBO(244, 244, 244, 1),
child: Column(
children: <Widget>[
//1、得到格林曼黑度标准和视频播放按钮组件
getHdAndPlay(),
//2、得到违章图片组件
imageWztp,
SizedBox(height: ScreenUtil().setHeight(_marginVer)),
//3、得到违章图片说明信息组件
getWztpSmxx(),
SizedBox(height: ScreenUtil().setHeight(_marginVer)),
//7、得到黑烟初审信息组件
widget.hyshlx == 'hycs' ||
widget.hyshlx == 'hyfh' ||
widget.hyshlx == 'tsjj'
? getHyshInfo('hycsInfo')
: SizedBox.shrink(),
//8、得到黑烟复审信息组件
widget.hyshlx == 'hyfh' || widget.hyshlx == 'tsjj'
? getHyshInfo('hyfhInfo')
: SizedBox.shrink(),
SizedBox(height: widget.hyshlx == 'tsjj' ? 0 : 15),
//9、得到推送交警确认组件
getTsjjQr(),
//SizedBox(height: 10),
],
),
),
),
widget.hyshlx == 'tsjj'
? Positioned(
//alignment: Alignment(0.9, 0.35),
//alignment: Alignment(0.8, 0.45),
right: ScreenUtil().setWidth(50),
top: ScreenUtil().setHeight(1423),
child: Container(
//alignment: Alignment(0.5, -0.5),
width: _stampSize,
height: _stampSize,
//color: Colors.black12,
decoration: BoxDecoration(
//color: Colors.white,
image: DecorationImage(
//image: AssetImage("assets/images/jkzx_stamp.png"), fit: BoxFit.contain),
image: AssetImage(widget.mapZpjl['fs_tile'] == '黑烟车'
? "assets/images/hyc.png"
: "assets/images/fhyc.png"),
fit: BoxFit.contain),
),
//child:
),
)
: SizedBox.shrink(),
],
),
);
}
Widget getBtnSizeX({@required text, width = 70.0, height = 35.0, onPressedFun}) {
return Container(
color: Colors.white12, //onPressedFun为null时无效
width: width,
height: height,
child: RaisedButton(
padding: EdgeInsets.all(0),
textColor: Colors.black,
child: Text(text),
onPressed: onPressedFun,
),
);
}
}
+629
View File
@@ -0,0 +1,629 @@
import 'package:fl_chart/fl_chart.dart';
//import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx/components/commonFun.dart';
import 'package:hyzp_ybqx/components/dioFun.dart';
import 'package:hyzp_ybqx/components/hyxx_data_handle.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/tj_data.dart';
class ZptjBarChart extends StatefulWidget {
ZptjBarChart({this.statisType, this.data_ok = false, Key key}) : super(key: key);
String statisType; //统计类型
bool data_ok; //listZptjStatis 中的数据是否准备好
@override
State<StatefulWidget> createState() => ZptjBarChartState();
}
class ZptjBarChartState extends State<ZptjBarChart> {
static const Color red = const Color(0xffff5182);
static const Color blue = const Color(0xff0000ff);
static const Color leftBarColor = const Color(0xffff5182);
static const Color rightBarColor = const Color(0xff0000ff);
static const Color bottomBarColor = const Color(0xff939393);
static const Color gridColor = const Color(0xffe7e8ec);
static const double width = 7;
String _textBottom1;
String _textBottom2;
String _textTop1;
String _textTop2;
int _rate = 10; // today 字段放大倍率
int _rateCoord = 10000; // 坐标压缩倍率
int _interval = 20; // 坐标间隔
int _maxY = -1;
List<BarChartGroupData> _listBarData = [];
//try_setState(); //避免异常报错
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
@override
void initState() {
super.initState();
getDataNew().then((value) {
_listBarData = value;
try_setState();
});
// ///获取点位信息数据
// if (!widget.data_ok) {
// //listZptjStatis 中的数据未准备好
// listZptjStatis.clear(); //最后需要显示的数据
// }
//
// if (listZptjStatis.isEmpty) {
// if (listDwinfoGetList2.isEmpty) {
// //若没有读取了点位数据,便需要先读取
// getThePageList(theHyshlx: 'dwxx').then((value) {
// listDwinfoGetList2 = value;
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// //按 sortField 升序排序
// listZptjStatis.sort((a, b) => (a['dwbh']).compareTo(b['dwbh']));
//
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// });
// });
// } else {
// //若已经读取了点位数据,便直接使用
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// //按 sortField 升序排序
// listZptjStatis.sort((a, b) => (a['dwbh']).compareTo(b['dwbh']));
//
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// });
// }
// } else {
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// }
}
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// title: Text(mapStatisType[widget.statisType]['text']),
// centerTitle: true,
// ),
appBar: PreferredSize(
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
// 设置appBar高度
child: AppBar(
automaticallyImplyLeading: false,
centerTitle: true,
titleSpacing: 0.0,
flexibleSpace: Container(
//SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
// SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
child: Container(
//height: ScreenUtil().setHeight(173),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(12, 186, 156, 1),
Color.fromRGBO(39, 127, 235, 1),
],
),
),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [
// Color(0xFF0018EB),
// Color(0xFF01C1D9),
// ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
// ),
),
),
title: Padding(
padding: EdgeInsets.only(left: 0, right: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getIconAndTextButton(
iconColor: Colors.white,
iconData: Icons.chevron_left_outlined,
onPress: () {
Navigator.pop(context);
},
),
Expanded(
child: Text(mapStatisType[widget.statisType]['text'],
style: TextStyle(color: Colors.white, fontSize: 20),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis),
),
SizedBox(width: 50),
],
),
),
),
),
body: Container(
alignment: Alignment(0, -0.85),
child: AspectRatio(
aspectRatio: 0.94, //宽高比
child: Card(
elevation: 4, //阴影高度
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
color: Colors.white,
child: Container(
padding: const EdgeInsets.only(top: 20),
child: (listAllStatisData.isEmpty || _listBarData.isEmpty)
? getMoreWidget(color: Colors.black38)
: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: 3),
Text(_textTop1, style: TextStyle(color: leftBarColor, fontSize: 12)),
Expanded(
child: Text(''),
),
Text(_textTop2, style: TextStyle(color: rightBarColor, fontSize: 12)),
SizedBox(width: 3),
],
),
SizedBox(
height: 10,
),
BarChart(
BarChartData(
maxY: _maxY.toDouble() * 1.1,
groupsSpace: 6,
alignment: BarChartAlignment.spaceEvenly,
barTouchData: BarTouchData(
enabled: false,
),
//坐标数据
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
rotateAngle: 45,
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: bottomBarColor, fontSize: 10),
margin: 10,
getTitles: (double value) {
int i = value.toInt() - 1;
return '${listAllStatisData[i]['id']}. ${listAllStatisData[i]['dwmc']}';
},
),
leftTitles: SideTitles(
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: leftBarColor, fontSize: 10),
margin: 4, //边距
getTitles: (double value) {
value = value / _rateCoord; //坐标压缩别率
if (value.toInt() % _interval == 0) {
return '${(value / _rate).toInt()}'; //将左侧坐标放大 _rate 倍
} else {
return '';
}
},
),
rightTitles: SideTitles(
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: rightBarColor, fontSize: 10),
margin: 4,
getTitles: (double value) {
value = value / _rateCoord; //坐标压缩别率
if (value.toInt() % _interval == 0) {
return '${value.toInt()}';
} else {
return '';
}
},
),
),
//栅格线
gridData: FlGridData(
show: true,
checkToShowHorizontalLine: (value) => value % _rate == 0,
getDrawingHorizontalLine: (value) => FlLine(
color: gridColor,
strokeWidth: 1,
),
),
//边线
borderData: FlBorderData(
show: true,
border: const Border(
bottom: BorderSide(
color: gridColor,
width: 2,
),
left: BorderSide(
color: leftBarColor,
width: 2,
),
right: BorderSide(
color: rightBarColor,
width: 2,
),
top: BorderSide(
color: Colors.transparent,
),
),
),
//图标数据
barGroups: _listBarData,
//barGroups: showingBarGroups,
),
),
SizedBox(height: 30),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: 3),
Text(_textBottom1,
style: TextStyle(color: leftBarColor, fontSize: 12)),
Expanded(
child: Container(
alignment: Alignment.center,
child: Text('点位编号',
style: TextStyle(color: bottomBarColor, fontSize: 12)),
),
),
Text(_textBottom2,
style: TextStyle(color: rightBarColor, fontSize: 12)),
SizedBox(width: 3),
],
),
]),
),
),
),
),
);
}
List<int> bar_getAllSumNew(String field) {
int items = 0;
int sum = 0;
for (var item in listAllStatisData) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
Future<List<BarChartGroupData>> getDataNew() async {
String _field1 = '';
String _field2 = '';
_maxY = -1;
int len = listAllStatisData.length;
List<BarChartGroupData> listBarData = [];
switch (widget.statisType) {
case 'zptj':
_field1 = 'zp_today';
_field2 = 'zp_all';
_rate = 10; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSumNew(_field1)[1]}';
_textBottom2 = '总共 ${bar_getAllSumNew(_field2)[1]}'; // 'all' 字段没有记录详情,所以用bar_getAllSumCll()
_textTop1 = '今日(次)';
_textTop2 = '(次)合计';
_rateCoord = 1;
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listAllStatisData[i]['id'],
(listAllStatisData[i][_field1] * _rate).toDouble(),
listAllStatisData[i][_field2].toDouble()),
);
//得到最大值
_maxY = listAllStatisData[i][_field1] * _rate > _maxY
? listAllStatisData[i][_field1] * _rate
: _maxY;
_maxY = listAllStatisData[i][_field2] > _maxY ? listAllStatisData[i][_field2] : _maxY;
}
break;
case 'sh_hyc_tj':
_field1 = 'hyc_all';
_field2 = 'send_all';
_rate = 1; // today 字段放大倍率
_rateCoord = 1; //坐标压缩倍率
_interval = 2; // 坐标间隔
_textBottom1 = '已审核 ${bar_getAllSumNew(_field1)[1]}';
_textBottom2 = '已推送 ${bar_getAllSumNew(_field2)[1]}';
_textTop1 = '审核(次)';
_textTop2 = '(次)推送';
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listAllStatisData[i]['id'],
(listAllStatisData[i][_field1] * _rate).toDouble(),
listAllStatisData[i][_field2].toDouble()),
);
//得到最大值
_maxY = listAllStatisData[i][_field1] * _rate > _maxY
? listAllStatisData[i][_field1] * _rate
: _maxY;
_maxY = listAllStatisData[i][_field2] > _maxY ? listAllStatisData[i][_field2] : _maxY;
}
break;
/*
listAllStatisData =
[
{
"id": 1,
"dwip": "172.16.3.1",
"dwmc": "锦绣花园",
"zp_all": 54,
"hyc_all": 53,
"zp_today": 1,
"sends": 1,
"send_all": 34,
"csnum": 1,
"fsnum": 1,
"cll_today": 23200,
"cll_all": 3242513
},
...
]
*/
case 'clltj':
_field1 = 'cll_today';
_field2 = 'cll_all';
_rate = 10; // today 字段放大倍率
_rateCoord = 10000; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSumNew(_field1)[1] ~/ _rateCoord} 万辆';
_textBottom2 = '总共 ${bar_getAllSumNew(_field2)[1] ~/ _rateCoord} 万辆';
_textTop1 = '今日(万辆)';
_textTop2 = '(万辆)合计';
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listAllStatisData[i]['id'],
(listAllStatisData[i][_field1] * _rate).toDouble(),
listAllStatisData[i][_field2].toDouble()),
);
//得到最大值
_maxY = listAllStatisData[i][_field1] * _rate > _maxY
? listAllStatisData[i][_field1] * _rate
: _maxY;
_maxY = listAllStatisData[i][_field2] > _maxY ? listAllStatisData[i][_field2] : _maxY;
}
break;
default:
break;
}
return listBarData;
}
Future<List<BarChartGroupData>> getData() async {
String _field1 = '';
String _field2 = '';
_maxY = -1;
int len = listZptjStatis.length;
List<BarChartGroupData> listBarData = [];
switch (widget.statisType) {
case 'zptj':
_field1 = 'today';
_field2 = 'all';
_rate = 10; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSum('today')[1]}';
_textBottom2 = '总共 ${bar_getAllSumCll('all')[1]}'; // 'all' 字段没有记录详情,所以用bar_getAllSumCll()
_textTop1 = '今日(次)';
_textTop2 = '(次)合计';
_rateCoord = 1;
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listZptjStatis[i]['dwbh'],
(listZptjStatis[i][_field1]["total"] * _rate).toDouble(),
listZptjStatis[i][_field2].toDouble()),
);
//得到最大值
_maxY = listZptjStatis[i][_field1]["total"] * _rate > _maxY
? listZptjStatis[i][_field1]["total"] * _rate
: _maxY;
_maxY = listZptjStatis[i][_field2] > _maxY ? listZptjStatis[i][_field2] : _maxY;
}
break;
case 'sh_hyc_tj':
_field1 = 'total';
_field2 = 'sends';
_rate = 1; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 2; // 坐标间隔
_textBottom1 =
'已审核 ${bar_getAllSumCll('total')[1]}'; // 'total' 字段没有记录详情,所以用bar_getAllSumCll()
_textBottom2 = '已推送 ${bar_getAllSum('sends')[1]}';
_textTop1 = '审核(次)';
_textTop2 = '(次)推送';
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listZptjStatis[i]['dwbh'],
(listZptjStatis[i][_field1] * _rate).toDouble(),
listZptjStatis[i][_field2]["total"].toDouble()),
);
//得到最大值
_maxY = listZptjStatis[i][_field1] * _rate > _maxY
? listZptjStatis[i][_field1] * _rate
: _maxY;
_maxY = listZptjStatis[i][_field2]["total"] > _maxY
? listZptjStatis[i][_field2]["total"]
: _maxY;
}
break;
case 'clltj':
_field1 = 'today';
_field2 = 'all';
_rate = 10; // today 字段放大倍率
_rateCoord = 10000; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSumCll('today')[1] ~/ _rateCoord} 万辆';
_textBottom2 = '总共 ${bar_getAllSumCll('all')[1] ~/ _rateCoord} 万辆';
_textTop1 = '今日(万辆)';
_textTop2 = '(万辆)合计';
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listZptjStatis[i]['dwbh'],
(listZptjStatis[i][_field1] * _rate).toDouble(),
listZptjStatis[i][_field2].toDouble()),
);
//得到最大值
_maxY = listZptjStatis[i][_field1] * _rate > _maxY
? listZptjStatis[i][_field1] * _rate
: _maxY;
_maxY = listZptjStatis[i][_field2] > _maxY ? listZptjStatis[i][_field2] : _maxY;
}
break;
default:
break;
}
return listBarData;
}
BarChartGroupData makeGroupData(int x, double y1, double y2) {
return BarChartGroupData(barsSpace: 0, x: x, barRods: [
BarChartRodData(
y: y1,
colors: [leftBarColor],
width: width,
borderRadius: const BorderRadius.all(Radius.zero),
),
BarChartRodData(
y: y2,
colors: [rightBarColor],
width: width,
borderRadius: const BorderRadius.all(Radius.zero),
),
]);
}
//获取已审核黑烟车统计数据:App.Car_Statis.GetStaHyc
//{
// "ret": 200,
// "data": {
// "total": 40,
// "sends": {
// "total": 0,
// "data": []
// },
// "csnum": {
// "total": 0,
// "data": []
// },
// "fsnum": {
// "total": 0,
// "data": []
// }
// },
// "msg": ""
// }
//获取抓拍统计数据:App.Car_Statis.GetStaYjxx
//{
// "ret": 200,
// "data": {
// "today": {
// "total": 0,
// "data": []
// },
// "all": 40
// },
// "msg": ""
// }
//得到 listZptjStatis[field] 的统计数据,
//适用的字段:抓拍统计的'today'、all;审核统计的"total"、"sends";
List<int> bar_getAllSum(String field) {
int items = 0;
int sum = 0;
for (var item in listZptjStatis) {
if (item[field]["total"] > 0) {
items++;
sum += item[field]["total"];
}
}
return [items, sum];
}
//获取车流量统计数据:App.Car_Statis.GetStaCll
//{
// "ret": 200,
// "data": {
// "today": 7010,
// "all": 1640350
// },
// "msg": ""
//}
//得到 listZptjStatis[field] 的统计数据,
//适用的字段:车流量统计的'today'、all
List<int> bar_getAllSumCll(String field) {
int items = 0;
int sum = 0;
for (var item in listZptjStatis) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
}
@@ -0,0 +1,508 @@
import 'package:fl_chart/fl_chart.dart';
//import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx/components/commonFun.dart';
import 'package:hyzp_ybqx/components/dioFun.dart';
import 'package:hyzp_ybqx/components/hyxx_data_handle.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/tj_data.dart';
class ZptjBarChartOne extends StatefulWidget {
ZptjBarChartOne({this.statisType, this.data_ok = false, Key key}) : super(key: key);
String statisType; //统计类型
bool data_ok; //listZptjStatis 中的数据是否准备好
@override
State<StatefulWidget> createState() => ZptjBarChartOneState();
}
class ZptjBarChartOneState extends State<ZptjBarChartOne> {
static const Color red = const Color(0xffff5182);
static const Color blue = const Color(0xff0000ff);
static const Color leftBarColor = const Color(0xffff5182);
static const Color rightBarColor = const Color(0xff0000ff);
static const Color bottomBarColor = const Color(0xff939393);
static const Color gridColor = const Color(0xffe7e8ec);
static const double width = 7;
String _textBottom1;
String _textBottom2;
String _textTop1;
String _textTop2;
int _rate = 10; // today 字段放大倍率
int _rateCoord = 10000; // 坐标压缩倍率
int _interval = 20; // 坐标间隔
int _maxY = -1;
List<BarChartGroupData> _listBarData = [];
//try_setState(); //避免异常报错
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
@override
void initState() {
super.initState();
print('ZptjBarChartOne');
getDataNew().then((value) {
_listBarData = value;
try_setState();
});
// ///获取点位信息数据
// if (!widget.data_ok) {
// //listZptjStatis 中的数据未准备好
// listZptjStatis.clear(); //最后需要显示的数据
// }
//
// if (listZptjStatis.isEmpty) {
// if (listDwinfoGetList2.isEmpty) {
// //若没有读取了点位数据,便需要先读取
// getThePageList(theHyshlx: 'dwxx').then((value) {
// listDwinfoGetList2 = value;
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// //按 sortField 升序排序
// listZptjStatis.sort((a, b) => (a['dwbh']).compareTo(b['dwbh']));
//
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// });
// });
// } else {
// //若已经读取了点位数据,便直接使用
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// //按 sortField 升序排序
// listZptjStatis.sort((a, b) => (a['dwbh']).compareTo(b['dwbh']));
//
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// });
// }
// } else {
// getData().then((value) {
// _listBarData = value;
// try_setState();
// });
// }
}
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// title: Text(mapStatisType[widget.statisType]['text']),
// centerTitle: true,
// ),
appBar: PreferredSize(
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)),
// 设置appBar高度
// 设置appBar高度
child: AppBar(
automaticallyImplyLeading: false,
centerTitle: true,
titleSpacing: 0.0,
flexibleSpace: Container(
//SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
// SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight),
//留出顶部状态栏高度
child: Container(
//height: ScreenUtil().setHeight(173),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(12, 186, 156, 1),
Color.fromRGBO(39, 127, 235, 1),
],
),
),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [
// Color(0xFF0018EB),
// Color(0xFF01C1D9),
// ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
// ),
),
),
title: Padding(
padding: EdgeInsets.only(left: 0, right: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getIconAndTextButton(
iconColor: Colors.white,
iconData: Icons.chevron_left_outlined,
onPress: () {
Navigator.pop(context);
},
),
Expanded(
child: Text(mapStatisType[widget.statisType]['text'],
style: TextStyle(color: Colors.white, fontSize: 20),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis),
),
SizedBox(width: 50),
],
),
),
),
),
body: Container(
alignment: Alignment(0, -0.85),
child: AspectRatio(
aspectRatio: 0.94, //宽高比
child: Card(
elevation: 4, //阴影高度
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
color: Colors.white,
child: Container(
padding: const EdgeInsets.only(top: 20),
child: (listAllStatisData.isEmpty || _listBarData.isEmpty)
? getMoreWidget(color: Colors.black38)
: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: 3),
Text(_textTop1, style: TextStyle(color: leftBarColor, fontSize: 12)),
Expanded(
child: Text(''),
),
Text(_textTop2, style: TextStyle(color: rightBarColor, fontSize: 12)),
SizedBox(width: 3),
],
),
SizedBox(
height: 10,
),
BarChart(
BarChartData(
maxY: _maxY.toDouble() * 1.1,
groupsSpace: 6,
alignment: BarChartAlignment.spaceEvenly,
barTouchData: BarTouchData(
enabled: false,
),
//坐标数据
titlesData: FlTitlesData(
show: true,
bottomTitles: SideTitles(
rotateAngle: 45,
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: bottomBarColor, fontSize: 10),
margin: 10,
getTitles: (double value) {
int i = value.toInt() - 1;
return '${listAllStatisData[i]['id']}. ${listAllStatisData[i]['dwmc']}';
},
),
leftTitles: SideTitles(
showTitles: true,
getTextStyles: (value) =>
const TextStyle(color: leftBarColor, fontSize: 10),
margin: 4, //边距
getTitles: (double value) {
//value = value / 1000; //坐标压缩别率
if (value.toInt() % 20000 == 0) {
return '${value / 100000}'; //将左侧坐标放大 _rate 倍
} else {
return '';
}
// if (value.toInt() % _interval == 0) {
// return '${(value / _rate).toInt()}'; //将左侧坐标放大 _rate 倍
// } else {
// return '';
// }
},
),
rightTitles: SideTitles(
showTitles: true,
// getTextStyles: (value) => const TextStyle(color: rightBarColor, fontSize: 10),
getTextStyles: (value) =>
const TextStyle(color: leftBarColor, fontSize: 10),
margin: 4,
getTitles: (double value) {
if (value.toInt() % 20000 == 0) {
return '${value / 100000}'; //将左侧坐标放大 _rate 倍
//return '';
} else {
return '';
}
},
),
),
//栅格线
gridData: FlGridData(
show: true,
checkToShowHorizontalLine: (value) => value % _rate == 0,
getDrawingHorizontalLine: (value) => FlLine(
color: gridColor,
strokeWidth: 1,
),
),
//边线
borderData: FlBorderData(
show: true,
border: const Border(
bottom: BorderSide(
color: gridColor,
width: 2,
),
left: BorderSide(
color: leftBarColor,
width: 2,
),
right: BorderSide(
// color: rightBarColor,
color: leftBarColor,
width: 2,
),
top: BorderSide(
color: Colors.transparent,
),
),
),
//图表数据
barGroups: _listBarData,
//barGroups: showingBarGroups,
),
),
SizedBox(height: 30),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(width: 3),
Text(_textBottom1,
style: TextStyle(color: leftBarColor, fontSize: 12)),
SizedBox(width: 60),
Text('点位编号', style: TextStyle(color: bottomBarColor, fontSize: 12)),
// Text(_textBottom2,
// style: TextStyle(color: rightBarColor, fontSize: 12)),
//SizedBox(width: 73),
],
),
]),
),
),
),
),
);
}
List<int> bar_getAllSumNew(String field) {
int items = 0;
int sum = 0;
for (var item in listAllStatisData) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
Future<List<BarChartGroupData>> getDataNew() async {
String _field1 = '';
String _field2 = '';
switch (widget.statisType) {
case 'zptj':
_field1 = 'zp_today';
_field2 = 'zp_all';
_rate = 10; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSumNew(_field1)[1]}';
_textBottom2 = '总共 ${bar_getAllSumNew(_field2)[1]}'; // 'all' 字段没有记录详情,所以用bar_getAllSumCll()
_textTop1 = '今日(次)';
_textTop2 = '(次)合计';
_rateCoord = 1;
break;
case 'sh_hyc_tj':
_field1 = 'hyc_all';
_field2 = 'send_all';
_rate = 1; // today 字段放大倍率
_rateCoord = 1; //坐标压缩倍率
_interval = 2; // 坐标间隔
_textBottom1 = '已审核 ${bar_getAllSumNew(_field1)[1]}';
_textBottom2 = '已推送 ${bar_getAllSumNew(_field2)[1]}';
_textTop1 = '审核(次)';
_textTop2 = '(次)推送';
break;
/*
listAllStatisData =
[
{
"id": 1,
"dwip": "172.16.3.1",
"dwmc": "锦绣花园",
"zp_all": 54,
"hyc_all": 53,
"zp_today": 1,
"sends": 1,
"send_all": 34,
"csnum": 1,
"fsnum": 1,
"cll_today": 23200,
"cll_all": 3242513
},
...
]
*/
case 'clltj':
_field1 = 'cll_today';
_field2 = 'cll_all';
_rate = 10; // today 字段放大倍率
_rateCoord = 10000; //坐标压缩别率
_interval = 5; // 坐标间隔
_textBottom1 = '今日合计 ${bar_getAllSumNew(_field1)[1] ~/ _rateCoord} 万辆';
//_textBottom2 = '总共 ${bar_getAllSumNew(_field2)[1] ~/ _rateCoord} 万辆';
_textBottom2 = '';
_textTop1 = '今日(万辆)';
//_textTop2 = '(万辆)合计';
_textTop2 = '';
break;
default:
break;
}
_maxY = -1;
int len = listAllStatisData.length;
List<BarChartGroupData> listBarData = [];
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(
listAllStatisData[i]['id'],
(listAllStatisData[i][_field1] * _rate).toDouble(),
listAllStatisData[i][_field2].toDouble()),
);
//得到最大值,只显示今日车流量
_maxY = listAllStatisData[i][_field1] * _rate > _maxY
? listAllStatisData[i][_field1] * _rate
: _maxY;
// _maxY = listZptjStatis[i][_field2] > _maxY ? listZptjStatis[i][_field2] : _maxY;
}
return listBarData;
}
Future<List<BarChartGroupData>> getData() async {
String _field1 = '';
String _field2 = '';
switch (widget.statisType) {
case 'zptj':
_field1 = 'today';
_field2 = 'all';
_rate = 10; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 20; // 坐标间隔
_textBottom1 = '今日合计 ${getAllSum('today')[1]}';
_textBottom2 = '总共 ${getAllSum('all')[1]}';
_textTop1 = '今日(次)';
_textTop2 = '(次)合计';
_rateCoord = 1;
break;
case 'sh_hyc_tj':
_field1 = 'total';
_field2 = 'sends';
_rate = 1; // today 字段放大倍率
_rateCoord = 1; //坐标压缩别率
_interval = 2; // 坐标间隔
_textBottom1 = '今日审核 ${getAllSum('total')[1]}';
_textBottom2 = '今日推送 ${getAllSum('sends')[1]}';
_textTop1 = '审核(次)';
_textTop2 = '(次)推送';
break;
case 'clltj':
_field1 = 'today';
_field2 = 'all';
_rate = 10; // today 字段放大倍率
_rateCoord = 10000; //坐标压缩别率
_interval = 5; // 坐标间隔
_textBottom1 = '今日合计 ${getAllSum('today')[1] ~/ (_rateCoord)} 万辆';
//_textBottom2 = '总共 ${getAllSum('all')[1] ~/ _rateCoord} 千辆';
_textBottom2 = '';
_textTop1 = '今日(万辆)';
//_textTop2 = '(千辆)合计';
_textTop2 = '';
break;
default:
break;
}
_maxY = -1;
int len = listZptjStatis.length;
List<BarChartGroupData> listBarData = [];
for (int i = 0; i < len; i++) {
//将 today 字段放大 _rate 倍
listBarData.add(
makeGroupData(listZptjStatis[i]['dwbh'], (listZptjStatis[i][_field1] * _rate).toDouble(),
listZptjStatis[i][_field2].toDouble()),
);
//得到最大值,只显示今日车流量
_maxY =
listZptjStatis[i][_field1] * _rate > _maxY ? listZptjStatis[i][_field1] * _rate : _maxY;
// _maxY = listZptjStatis[i][_field2] > _maxY ? listZptjStatis[i][_field2] : _maxY;
}
return listBarData;
}
BarChartGroupData makeGroupData(int x, double y1, double y2) {
return BarChartGroupData(barsSpace: 0, x: x, barRods: [
BarChartRodData(
y: y1,
colors: [leftBarColor],
width: width,
borderRadius: const BorderRadius.all(Radius.zero),
),
// BarChartRodData(
// y: y2,
// colors: [rightBarColor],
// width: width,
// borderRadius: const BorderRadius.all(Radius.zero),
// ),
]);
}
//得到 listZptjStatis[field] 的统计数据,
//适用的字段:抓拍统计和车流量统计的'today'、all;审核统计的"total"、"sends";
List<int> getAllSum(String field) {
int items = 0;
int sum = 0;
for (var item in listZptjStatis) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
}
+835
View File
@@ -0,0 +1,835 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hyzp_ybqx/components/save_data_to_file.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/zptj_bar_chart.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/zptj_bar_chart_one.dart';
import '../../../components/commonFun.dart';
import '../../../components/hyxx_data_handle.dart';
import 'tj_data.dart';
//zptj 是本项目中“抓拍统计”的统一缩写
//sh_hyc_tj 是本项目中“审核黑烟车统计”的统一缩写
//clltj 是本项目中“车流量统计”的统一缩写
class ZptjPage extends StatefulWidget {
//mapStatisType 为统计数据类型数据结构。用于在同一套代码中,处理相似类型的多种统计数据
//statisType 为统计类型。mapStatisType[statisType] 为各种相似类型的设置数据
ZptjPage({@required this.statisType, Key key}) : super(key: key);
String statisType;
_ZptjPageState createState() => _ZptjPageState();
}
class _ZptjPageState extends State<ZptjPage> {
//try_setState(); //避免异常报错
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
@override
void dispose() {
super.dispose();
}
@override
void initState() {
// ///获取点位信息数据
// listZptjStatis.clear(); //最后需要显示的数据
//
// if (listDwinfoGetList2.isEmpty) {
// //若没有读取了点位数据,便需要先读取
// getThePageList(theHyshlx: 'dwxx').then((value) {
// listDwinfoGetList2 = value;
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// _listSort(sortField: 'dwbh');
// });
// });
// } else {
// //若已经读取了点位数据,便直接使用
// print('listDwinfoGetList2 = \n$listDwinfoGetList2');
// getZptjStatis(widget.statisType).then((value) {
// _listSort(sortField: 'dwbh');
// });
// }
super.initState();
}
///获取点位信息数据
// List listDwinfoGetList2 = [
// {
// "id": 1,
// "dwip": "172.16.3.1",
// "dwmc": "江北振兴大道",
// "dwbh": 1,
// "dwinfo": "江北振兴大道入城方向",
// "dwzb": "104.607091|28.807061",
// "dwms": "江北振兴大道入城方向,识别孜岩、红坝路入城排放黑烟车辆"
// },
// ];
//listZptjStatis = [
// {today: 832, all: 4479, dwip: 172.16.3.1},
// {today: 0, all: 185, dwip: 172.16.3.2},
// {today: 0, all: 131, dwip: 172.16.3.3},
// {today: 0, all: 72, dwip: 172.16.3.4},
// {today: 0, all: 30, dwip: 172.16.3.5},
// {today: 0, all: 26, dwip: 172.16.3.6},
// {today: 0, all: 0, dwip: 172.16.3.7},
// {today: 0, all: 135, dwip: 172.16.3.8},
// {today: 0, all: 65, dwip: 172.16.3.9},
// {today: 0, all: 36, dwip: 172.16.3.10},
// {today: 0, all: 44, dwip: 172.16.3.11},
// {today: 0, all: 76, dwip: 172.16.3.12},
// {today: 0, all: 83, dwip: 172.16.3.13}
//]
Widget _getListTile(BuildContext context, int indexRecord, {double width = 520}) {
switch (widget.statisType) {
case 'zptj':
return _getZptjListTile(context, indexRecord, 520);
break;
case 'clltj':
return _getClltjListTile(context, indexRecord, 520);
break;
case 'sh_hyc_tj':
return _getSh_hyc_tjListTile(context, indexRecord, 510);
break;
default:
return Container();
break;
}
}
//抓拍统计数据
//{
// "today": 0,
// "all": 72
// "dwbh": 1,
// "dwmc": "江北振兴大道",
// "dwip": "172.16.3.1"
//}
Widget _getSh_hyc_tjListTile(BuildContext context, int indexRecord, double width) {
return Column(
children: <Widget>[
ListTile(
//leading: new Icon(Icons.phone),
title: getDwmcField(indexRecord, 40),
// subtitle:
// Text('今日:${listZptjStatis[indexRecord]['today']}', style: TextStyle(fontSize: 10)),
trailing: Container(
width: ScreenUtil().setWidth(width),
child: Row(
children: [
getText(
text: listAllStatisData[indexRecord]['hyc_all'].toString(),
width: 260,
fontSize: 16),
getText(
text: listAllStatisData[indexRecord]['send_all'].toString(),
width: 240,
fontSize: 16),
],
),
),
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
enabled: true,
onTap: () async {},
),
Divider(height: 1.0),
],
);
}
Widget getText({String text = '', double width = 100, double fontSize = 16}) {
return SizedBox(
width: ScreenUtil().setWidth(width),
child: Text(
text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
//textAlign: TextAlign.right,
style: TextStyle(fontSize: fontSize),
),
);
}
///获取点位信息数据
// List listDwinfoGetList2 = [
// {
// "id": 1,
// "dwip": "172.16.3.1",
// "dwmc": "江北振兴大道",
// "dwbh": 1,
// "dwinfo": "江北振兴大道入城方向",
// "dwzb": "104.607091|28.807061",
// "dwms": "江北振兴大道入城方向,识别孜岩、红坝路入城排放黑烟车辆"
// },
// ];
Widget getDwmcField(int indexRecord, double width) {
return SizedBox(
width: ScreenUtil().setWidth(width),
child: Text(
'${listAllStatisData[indexRecord]["id"].toString()}. ${listAllStatisData[indexRecord]["dwmc"]}',
style: TextStyle(fontSize: 16),
),
);
}
/*
listAllStatisData =
[
{
"id": 1,
"dwip": "172.16.3.1",
"dwmc": "锦绣花园",
"zp_all": 54,
"hyc_all": 53,
"zp_today": 1,
"sends": 1,
"send_all": 34,
"csnum": 1,
"fsnum": 1,
"cll_today": 23200,
"cll_all": 3242513
},
...
]
*/
Widget _getZptjListTile(BuildContext context, int indexRecord, double width) {
return Column(
children: <Widget>[
ListTile(
//leading: new Icon(Icons.phone),
title: getDwmcField(indexRecord, 40),
// subtitle:
// Text('今日:${listAllStatisData[indexRecord]['today']}', style: TextStyle(fontSize: 10)),
trailing: Container(
width: ScreenUtil().setWidth(width),
child: Row(
children: [
getText(
text: listAllStatisData[indexRecord]['zp_today'].toString(),
width: 260,
fontSize: 16),
getText(
text: listAllStatisData[indexRecord]['zp_all'].toString(),
width: 260,
fontSize: 16),
],
),
),
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
enabled: true,
onTap: () async {},
),
Divider(height: 1.0),
],
);
}
Widget _getClltjListTile(BuildContext context, int indexRecord, double width) {
return Column(
children: <Widget>[
ListTile(
//leading: new Icon(Icons.phone),
title: getDwmcField(indexRecord, 40),
// subtitle:
// Text('今日:${listAllStatisData[indexRecord]['today']}', style: TextStyle(fontSize: 10)),
trailing: Container(
width: ScreenUtil().setWidth(width),
child: Row(
children: [
// getText(
// text: listAllStatisData[indexRecord]['today'].toString(),
// width: 260,
// fontSize: 16),
// getText(
// text: (listAllStatisData[indexRecord]['all'] / 10000).toString(),
// width: 260,
// fontSize: 16),
getText(text: '', width: 260, fontSize: 16),
getText(
text: listAllStatisData[indexRecord]['cll_today'].toString(),
width: 260,
fontSize: 16),
],
),
),
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
enabled: true,
onTap: () async {},
),
Divider(height: 1.0),
],
);
}
bool isLoading = false; //正在处理下载数据、跳转到首项、跳转到尾项等操作
//Map<String, String> mapTjDataText = {
// "dwip": '点位IP',
// "today": '今日',
// "all": '总共',
// "total": '总共2',
// "sends": '推送'
// };
//抓拍统计数据
//{
// "today": 5,
// "all": 77
//},
//审核统计数据
//{
// "total": 6,
// "sends": 5
// },
//车流量统计数据
//{
// "today": 0,
// "all": 675338
//}
//得到表头行
Widget getHeadRow() {
Widget _headRow;
switch (widget.statisType) {
case 'zptj':
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(475),
child: _getSortBtn(sortField: 'dwmc', left: 78),
),
SizedBox(
width: ScreenUtil().setWidth(285),
child: _getSortBtn(sortField: 'today', left: 10),
),
SizedBox(
width: ScreenUtil().setWidth(280),
child: _getSortBtn(sortField: 'all', left: 10),
),
],
);
break;
case 'sh_hyc_tj':
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(495),
child: _getSortBtn(sortField: 'dwmc', left: 78),
),
SizedBox(
width: ScreenUtil().setWidth(265),
child: _getSortBtn(sortField: 'total', left: 10),
),
SizedBox(
width: ScreenUtil().setWidth(300),
child: _getSortBtn(sortField: 'sends', left: 20),
),
],
);
break;
case 'clltj':
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(465),
child: _getSortBtn(sortField: 'dwmc', left: 78),
),
// SizedBox(
// width: ScreenUtil().setWidth(265),
// child: _getSortBtn(sortField: 'today', left: 20),
// ),
// SizedBox(
// width: ScreenUtil().setWidth(300),
// child: _getSortBtn(sortField: 'all', left: 50),
// ),
SizedBox(
width: ScreenUtil().setWidth(265),
child: Text(''),
),
SizedBox(
width: ScreenUtil().setWidth(300),
child: _getSortBtn(sortField: 'today', left: 20),
),
],
);
break;
default:
return Container();
break;
}
return _headRow;
}
/*
listAllStatisData =
[
{
"id": 1,
"dwip": "172.16.3.1",
"dwmc": "锦绣花园",
"zp_all": 54,
"hyc_all": 53,
"zp_today": 1,
"sends": 1,
"send_all": 34,
"csnum": 1,
"fsnum": 1,
"cll_today": 23200,
"cll_all": 3242513
},
...
]
*/
//得到统计行
Widget getStatisRow() {
Widget _headRow;
switch (widget.statisType) {
case 'zptj':
List _listSum = tj_getAllSum('zp_today');
List _listAll = tj_getAllSum('zp_all');
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(455),
//xx个点位正常\n(共xx个点位)
child: _getStatisText(
//text: '${getOKdw().toString()}个点位正常\n(共${listDwinfoGetList2.length.toString()}个点位)',
text: '共 ${listDwinfoGetList2.length.toString()} 个点位',
left: ScreenUtil().setWidth(170)),
),
SizedBox(
width: ScreenUtil().setWidth(270),
//xx个点位,今日共抓拍xx
child: _getStatisText(
//text: '${_listSum[0].toString()}个点位,今日共抓拍${_listSum[1].toString()}',
text: '今日 ${_listSum[1].toString()} 次',
width: ScreenUtil().setWidth(245)),
),
SizedBox(
width: ScreenUtil().setWidth(300),
//xx个点位,总共抓拍xx
child: _getStatisText(
//text: '${_listAll[0].toString()}个点位,总共抓拍${_listAll[1].toString()}',
text: '总共 ${_listAll[1].toString()} 次',
width: ScreenUtil().setWidth(260)),
),
],
);
break;
case 'sh_hyc_tj':
List _listSum = tj_getAllSum('send_all');
//List _listAll = tj_getAllSumCll('total'); // 'total' 字段没有记录详情,所以用tj_getAllSumCll()
List _listAll = tj_getAllSum('hyc_all');
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(475),
//xx正常(共13)
child: _getStatisText(
//text: '${getOKdw().toString()}个点位正常\n(共${listDwinfoGetList2.length.toString()}个点位)',
text: '共 ${listDwinfoGetList2.length.toString()} 个点位',
left: ScreenUtil().setWidth(170)),
),
SizedBox(
width: ScreenUtil().setWidth(260),
//xx个点位,总共审核xx
child: _getStatisText(
//text: '${_listAll[0].toString()}个点位,总共审核${_listAll[1].toString()}',
text: '共审核 ${_listAll[1].toString()} 次',
width: ScreenUtil().setWidth(225)),
),
SizedBox(
//xx个点位,总共推送xx
child: _getStatisText(
//text: '${_listSum[0].toString()}个点位,总共推送${_listSum[1].toString()}',
text: '共推送 ${_listSum[1].toString()} 次',
width: ScreenUtil().setWidth(260)),
),
],
);
break;
case 'clltj':
List _listSum = tj_getAllSum('cll_today');
List _listAll = tj_getAllSum('cll_all');
_headRow = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: ScreenUtil().setWidth(445),
//xx个点位正常\n(共xx个点位)
child: _getStatisText(
//text: '${getOKdw().toString()}个点位正常\n(共${listDwinfoGetList2.length.toString()}个点位)',
text: '共 ${listDwinfoGetList2.length.toString()} 个点位',
left: ScreenUtil().setWidth(150)),
),
// SizedBox(
// width: ScreenUtil().setWidth(280),
// //xx个点位,今日共抓拍xx
// child: _getStatisText(
// //text: '${_listSum[0].toString()}个点位,今日车流量${_listSum[1].toString()}',
// text: '今日 ${_listSum[1].toString()}',
// width: ScreenUtil().setWidth(265)),
// ),
// SizedBox(
// width: ScreenUtil().setWidth(280),
// //xx个点位,总共抓拍xx
// child: _getStatisText(
// //text: '${_listAll[0].toString()}个点位,总共车流量${_listAll[1].toString()}',
// text: '总共 ${(_listAll[1] ~/ 10000).toString()} 万',
// width: ScreenUtil().setWidth(280)),
// ),
SizedBox(
width: ScreenUtil().setWidth(280),
//xx个点位,今日共抓拍xx
child: _getStatisText(
//text: '${_listSum[0].toString()}个点位,今日车流量${_listSum[1].toString()}',
text: '',
width: ScreenUtil().setWidth(265)),
),
SizedBox(
width: ScreenUtil().setWidth(280),
//xx个点位,今日共抓拍xx
child: _getStatisText(
//text: '${_listSum[0].toString()}个点位,今日车流量${_listSum[1].toString()}',
text: '今日 ${_listSum[1].toString()}',
width: ScreenUtil().setWidth(205)),
),
],
);
break;
default:
return Container();
break;
}
return _headRow;
}
//获取已审核黑烟车统计数据:App.Car_Statis.GetStaHyc
//{
// "ret": 200,
// "data": {
// "total": 40,
// "sends": {
// "total": 0,
// "data": []
// },
// "csnum": {
// "total": 0,
// "data": []
// },
// "fsnum": {
// "total": 0,
// "data": []
// }
// },
// "msg": ""
// }
//获取抓拍统计数据:App.Car_Statis.GetStaYjxx
//{
// "ret": 200,
// "data": {
// "today": {
// "total": 0,
// "data": []
// },
// "all": 40
// },
// "msg": ""
// }
//得到 listAllStatisData[field] 的统计数据,
//适用的字段:抓拍统计的'today'、all;审核统计的"total"、"sends";
List<int> tj_getAllSum(String field) {
int items = 0;
int sum = 0;
for (var item in listAllStatisData) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
//获取车流量统计数据:App.Car_Statis.GetStaCll
//{
// "ret": 200,
// "data": {
// "today": 7010,
// "all": 1640350
// },
// "msg": ""
//}
//得到 listZptjStatis[field] 的统计数据,
//适用的字段:车流量统计的'today'、all
List<int> tj_getAllSumCll(String field) {
int items = 0;
int sum = 0;
for (var item in listZptjStatis) {
if (item[field] > 0) {
items++;
sum += item[field];
}
}
return [items, sum];
}
Widget _getStatisText({@required String text, double left = 0, double width = 100}) {
return Row(
children: [
SizedBox(width: ScreenUtil().setWidth(left)),
Container(
width: width,
child:
Text(text, style: TextStyle(fontSize: 12), maxLines: 2, textAlign: TextAlign.center),
),
//SizedBox(width: ScreenUtil().setWidth(20)),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
// 设置appBar高度
child: AppBar(
automaticallyImplyLeading: false,
centerTitle: true,
titleSpacing: 0.0,
flexibleSpace: Container(
//SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
// SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
child: Container(
//height: ScreenUtil().setHeight(173),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(12, 186, 156, 1),
Color.fromRGBO(39, 127, 235, 1),
],
),
),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [
// Color(0xFF0018EB),
// Color(0xFF01C1D9),
// ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
// ),
),
),
title: Padding(
padding: EdgeInsets.only(left: 0, right: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
getIconAndTextButton(
iconColor: Colors.white,
iconData: Icons.chevron_left_outlined,
onPress: () {
Navigator.pop(context);
},
),
Expanded(
child: Text(mapStatisType[widget.statisType]['text'],
style: TextStyle(color: Colors.white, fontSize: 20),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis),
),
SizedBox(width: 10),
],
),
),
actions: [
InkWell(
child: Image.asset(
widget.statisType == 'zptj'
? 'assets/images/statis_blue.png'
: widget.statisType == 'sh_hyc_tj'
? 'assets/images/statis_red.png'
: 'assets/images/statis_green.png',
width: 32,
height: 32,
color: Colors.white),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) {
if (widget.statisType == 'clltj') {
return ZptjBarChartOne(
data_ok: true, //listAllStatisData 中的数据已经准备好
statisType: widget.statisType,
);
} else {
return ZptjBarChart(
data_ok: true, //listAllStatisData 中的数据已经准备好
statisType: widget.statisType,
);
}
}),
);
},
),
SizedBox(width: 15),
],
),
),
body: (listAllStatisData.isEmpty)
? getMoreWidget(color: Colors.black38)
: Column(
children: [
SizedBox(height: ScreenUtil().setHeight(20)),
getHeadRow(), //得到表头行
SizedBox(height: ScreenUtil().setHeight(20)),
Divider(height: 1.0, color: Colors.blue),
SizedBox(height: ScreenUtil().setHeight(10)),
getStatisRow(), //得到统计行
SizedBox(height: ScreenUtil().setHeight(10)),
Divider(height: 1.0, color: Colors.blue),
Expanded(
child: ListView.builder(
itemCount: listAllStatisData.length,
itemBuilder: (BuildContext context, index) {
return Column(
children: <Widget>[
_getListTile(context, index),
Divider(height: 1.0),
],
);
},
),
),
],
),
);
}
Widget _getImage(String sortField) {
sortField = (sortField == 'dwmc' ? 'id' : sortField);
String _image = _sortField != sortField
? 'assets/images/sort.png'
: _descending
? 'assets/images/descending.png'
: 'assets/images/ascending.png';
return Container(
margin: EdgeInsets.only(top: 4),
height: ScreenUtil().setWidth(38),
width: ScreenUtil().setWidth(38),
//child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
child: Image.asset(_image,
fit: BoxFit.cover,
color: isLoading
? Theme.of(context).disabledColor
: (_sortField == sortField ? Colors.blue : null)));
}
String _sortField = 'dwmc';
bool _descending = false; //默认升序排列
Widget _getSortBtn({@required String sortField, double left = 0}) {
return InkWell(
// color: Colors.white,
// padding: EdgeInsets.all(0),
//iconSize: this.iconSize,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: ScreenUtil().setWidth(left)),
Text(mapTjDataText[sortField],
style: TextStyle(
fontSize: 18,
color: Colors.blue,
fontWeight: _sortField == sortField || (_sortField == 'id' && sortField == 'dwmc')
? FontWeight.bold
: null)),
SizedBox(width: ScreenUtil().setWidth(20)),
_getImage(sortField),
],
),
onTap: () {
if (isLoading) {
return;
}
print('sortField = $sortField,_descending = $_descending');
//按照用户选择的 sortField、_descending对listSbbjGetList2进行排序,并延时更新
_listSort(sortField: sortField == 'dwmc' ? 'id' : sortField);
},
);
}
// Map<String, String> mapTjDataText = {
// "dwip": '点位IP',
// "today": '今日',
// "all": '总共',
// "total": '总共2',
// "sends": '推送'
// };
//按照用户选择的 sortField、_descending对listZptjStatis进行排序,并延时更新
Future _listSort({@required String sortField, bool bShowToast = false}) {
if (!isLoading && listAllStatisData.length > 0) {
isLoading = true;
try_setState();
if (_sortField == sortField) {
_descending = !_descending; //若是与上一次按同一个自动排序,则切换升序降序
} else {
_descending = false; //默认升序排列
}
switch (sortField) {
default:
if (_descending) {
//按 sortField 降序排序
listAllStatisData.sort((a, b) => (b[sortField]).compareTo(a[sortField]));
} else {
//按 sortField 升序排序
listAllStatisData.sort((a, b) => (a[sortField]).compareTo(b[sortField]));
}
break;
}
Future.delayed(const Duration(milliseconds: 1000), () {
if (bShowToast) {
Fluttertoast.showToast(
msg:
'按“${mapTjDataText[sortField == 'id' ? 'dwmc' : sortField]}”${_descending ? '降序' : '升序'}排列完成!',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
_sortField = sortField;
isLoading = false;
try_setState(); //避免如下异常报错
});
}
}
}