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
+77
View File
@@ -0,0 +1,77 @@
import 'dart:convert';
import 'package:encrypt/encrypt.dart';
class EncryptUtil {
static const List<int> intList16 = [
3,
8,
7,
8,
3,
7,
8,
9,
1,
8,
6,
8,
2,
8,
7,
8
];
//aes加密
static String aesEncode0(String content) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted =
encrypter.encrypt(content, iv: IV.fromBase64(base64Encode(intList16)));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//aes加密
static String aesEncode(String content) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted =
encrypter.encrypt(content, iv: IV.fromBase64(base64Encode(intList16)));
return encrypted.base64;
} catch (err) {
print("aes encode error:$err");
return content;
}
}
//aes解密
static String aesDecode(String base64) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
return encrypter.decrypt64(base64,
iv: IV.fromBase64(base64Encode(intList16)));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
//aes解密-dynamic
static dynamic aesDecodeDynamic(dynamic base64) {
try {
final key = Key.fromBase64(base64Encode(intList16));
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
return encrypter.decrypt64(base64,
iv: IV.fromBase64(base64Encode(intList16)));
} catch (err) {
print("aes decode error:$err");
return base64;
}
}
}
+150
View File
@@ -0,0 +1,150 @@
import 'package:flutter/cupertino.dart';
void segmentPrint(String msg, {int len = 600}) {
var outStr = StringBuffer();
for (var index = 0; index < msg.length; index++) {
outStr.write(msg[index]);
if (index % len == 0 && index != 0) {
print(outStr);
outStr.clear();
var lastIndex = index + 1;
if (msg.length - lastIndex < len) {
var remainderStr = msg.substring(lastIndex, msg.length);
print(remainderStr);
break;
}
}
}
}
// ///是否在生产环境
// ///const bool isDebug = !const bool.fromEnvironment("dart.vm.product");
//
// //参数可选 isDebug默认true limitLength默认800
// LogUtil.init(title: "来自LogUtil", isDebug: isDebug,limitLength:800);
//
// var log = "我是日志";
// //仅在Debug时打印
// LogUtil.d(log);
// LogUtil.d("我是日志");
//
// //在所有环境中打印
// LogUtil.v(log);
// LogUtil.v("我是日志");
// ————————————————
// 版权声明:本文为CSDN博主「懒散的阿乐」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
// 原文链接:https://blog.csdn.net/zylvip/article/details/102608256
class LogUtil {
static var _separator = "=";
static var _split =
"$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator";
static var _title = "Yl-Log";
static var _isDebug = true;
static int _limitLength = 1200;
static String _startLine = "$_split$_title$_split";
static String _endLine = "$_split$_separator$_separator$_separator$_split";
static void init({String title, @required bool isDebug, int limitLength}) {
_title = title;
_isDebug = isDebug;
_limitLength = limitLength ??= _limitLength;
_startLine = "$_split$_title$_split";
var endLineStr = StringBuffer();
var cnCharReg = RegExp("[\u4e00-\u9fa5]");
for (int i = 0; i < _startLine.length; i++) {
if (cnCharReg.stringMatch(_startLine[i]) != null) {
endLineStr.write(_separator);
}
endLineStr.write(_separator);
}
_endLine = endLineStr.toString();
}
//仅Debug模式可见
static void d(dynamic obj) {
if (_isDebug) {
_log(obj.toString());
}
}
static void v(dynamic obj) {
_log(obj.toString());
}
static void _log(String msg) {
print("$_startLine");
_logEmpyLine();
if (msg.length < _limitLength) {
print(msg);
} else {
segmentationLog(msg);
}
_logEmpyLine();
print("$_endLine");
}
static void segmentationLog(String msg) {
var outStr = StringBuffer();
for (var index = 0; index < msg.length; index++) {
outStr.write(msg[index]);
if (index % _limitLength == 0 && index != 0) {
print(outStr);
outStr.clear();
var lastIndex = index + 1;
if (msg.length - lastIndex < _limitLength) {
var remainderStr = msg.substring(lastIndex, msg.length);
print(remainderStr);
break;
}
}
}
}
static void _logEmpyLine() {
print("");
}
}
//common_utils 工具类已经将pring 封装为工具类
//
// common_utils: ^1.1.1
// 使用common_utils工具类中的LogUtil
//
// //初始化设置 LogUtil
// LogUtil.init(true);
// //输出日志
// LogUtil.v("test");
// 当然 LogUtil 的 init 方法可根据是否是生产环境来配置 true 与 false ,如果是 false ,则不输出日志,这样的一个优化也是应用在发版本后可以节省向控制台输出日志信息的消耗。
//
// 封装源码如下
class LogUtil2 {
static const String _TAG_DEF = "###common_utils###";
static bool debuggable = false; //是否是debug模式,true: log v 不输出.
static String TAG = _TAG_DEF;
static void init({bool isDebug = false, String tag = _TAG_DEF}) {
debuggable = isDebug;
TAG = tag;
}
static void e(Object object, {String tag}) {
_printLog(tag, ' e ', object);
}
static void v(Object object, {String tag}) {
if (debuggable) {
_printLog(tag, ' v ', object);
}
}
static void _printLog(String tag, String stag, Object object) {
StringBuffer sb = new StringBuffer();
sb.write((tag == null || tag.isEmpty) ? TAG : tag);
sb.write(stag);
sb.write(object);
print(sb.toString());
}
}
+549
View File
@@ -0,0 +1,549 @@
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hyzp_ybqx/config/service_url.dart';
import 'package:hyzp_ybqx/services/EventBus.dart';
import 'commonFun.dart';
///用户权限管理
// static const String getUserAccessUrl = ServiceUrl + '?s=App.User_User.GetAccess'; //1、根据用户ID获取用户所属角色
// static const String getUserGroupUrl = ServiceUrl + '?s=App.User_User.GetGroup'; //2、获取后台用户角色分组数据
// static const String getUserGroupListUrl = ServiceUrl + '?s=App.User_User.GetGroupList'; //3、获取后台用户角色分组分页列表数据
// static const String getUserAuthUrl = ServiceUrl + '?s=App.User_User.GetAuth'; //4、获取后台功能分类数据
// static const String getUserAuthListUrl = ServiceUrl + '?s=App.User_User.GetAuthList'; //5、获取后台功能分类分页列表数据
//2.2、获取后台用户全部角色分组数据
Future getUserGroupAll({int user_id = -1}) async {
if (user_id < 0) {
user_id = g_userInfo.mapUserInfo['user_id'];
}
//1、根据用户ID获取用户所属角色(用户组)
getUserAccess(user_id: user_id).then((value) {
// I/flutter (15540): g_userInfo.userGroupIDlist = [31, 27]
int len = g_userInfo.userGroupIDlist.length;
for (int i = 0; i < len; i++) {
getUserGroup(group_id: g_userInfo.userGroupIDlist[i]);
}
print('g_userInfo.userRulesMap = ${g_userInfo.userRulesMap}');
});
}
//2.1、获取后台用户指定 group_id 角色分组数据
Future getUserGroup({@required int group_id}) async {
var api = ServicePath.getUserGroupUrl;
print(api);
//I/flutter (15540): http://125.64.218.67:9904/?s=App.User_User.GetGroup
String random = RandomBit(6);
Map map = {
'random': random,
'sign': GenerateMd5(APPkey + random),
'id': group_id,
};
print('开始处理登录请求...');
Response response;
Dio dio = Dio();
//返回结果
// 返回字段 类型 说明
// id 整型 角色分组ID
// type 整型 角色分组类型:1普通角色
// level 整型 角色分组级次(1-顶级,2-次级)
// pid 整型 上级角色分组ID(为0则表示为顶级)
// rules 字符串 授权功能ID(如:5,7,112,331),表示此角色拥有相应ID的功能权限
//{
// "ret": 200,
// "data": {
// "id": 31,
// "jgid": 2,
// "type": 0,
// "title": "监控室",
// "level": 0,
// "pid": 0,
// "sort": 2,
// "status": 1,
// "rules": ""
// },
// "msg": ""
// }
try {
print('response = ${response}');
// I/flutter (15540): response = null
response = await dio.post(api, data: map);
print('response = ${response}');
//I/flutter (15540): response = {"ret":200,"data":{"id":31,"jgid":2,"type":0,"title":"监控室","level":0,"pid":0,"sort":2,"status":1,"rules":""},"msg":""}
if (response.statusCode == 200) {
Map _mapRet = await getMapFromJson(response.data);
print('_mapRet = ${_mapRet}');
// I/flutter (15540): _mapRet = {ret: 200, data: {id: 31, jgid: 2, type: 0, title: 监控室, level: 0, pid: 0, sort: 2, status: 1, rules: }, msg: }
//print('_mapRet[\'data\']["rules"] is a = ${_mapRet['data']["rules"] is String}');
//_mapRet['data']["rules"] is a = true
//I/flutter (15540): _mapRet = {ret: 200, data: false, msg: }
//I/flutter (15540): 网络请求过程异常e = NoSuchMethodError: Class 'bool' has no instance method '[]'.
if (_mapRet['data'] is Map) {
String _rules = _mapRet['data']["rules"].trim();
//print('_rules = ${_rules}');
print('_rules.length = ${_rules.length}');
//_rules.length = 0
List<int> _list = [];
if (_rules.isNotEmpty) {
List _list2 = _rules.split(',');
print('_list2 = $_list2');
//I/flutter (15540): _list2 = [1968, 1972, 1973, 1969, 1976, 1977, 2008, 2009, 2011, 2014,
// 2015, 2018, 2029, 2030, 2031, 2054, 2055, 2035, 2036, 2037, 2041, 2042, 2043, 2047, 2048,
// 2049, 2053, 1970, 1980, 1981, 1971, 1984, 1985, 1992, 1993, 2000, 2001, 2020, 2022]
int len = _list2.length;
List<int> _list3 = [];
for (int i = 0; i < len; i++) {
_list3.add(int.parse(_list2[i].trim()));
}
_list = _list3;
}
print('_list = $_list');
//I/flutter (15540): _list = [{uid: 135, group_id: 31}, {uid: 135, group_id: 27}]
g_userInfo.userRulesMap[_mapRet['data']['id']] = _list;
print('g_userInfo.userRulesMap = ${g_userInfo.userRulesMap}');
// I/flutter (15540): g_userInfo.userGroupIDlist = [31, 27]
} else {
print('获取数据失败!');
}
print('网络请求过程正常完成');
} else {
throw Exception('后端接口出现异常,请检测代码和服务器情况.........');
}
} catch (e) {
print('网络请求过程异常e = ${e}');
Fluttertoast.showToast(
msg: 'ERROR:======>${e}',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
}
//1、根据用户ID获取用户所属角色(用户组)
Future getUserAccess({int user_id = -1}) async {
if (user_id < 0) {
user_id = g_userInfo.mapUserInfo['user_id'];
}
var api = ServicePath.getUserAccessUrl;
print(api);
//I/flutter (15540): http://125.64.218.67:9904/?s=App.User_User.GetAccess
String random = RandomBit(6);
Map map = {
'random': random,
'sign': GenerateMd5(APPkey + random),
'uid': user_id,
};
print('开始处理登录请求...');
Response response;
Dio dio = Dio();
//{
// "ret": 200,
// "data": [
// {
// "uid": 136,
// "group_id": 32
// },
// {
// "uid": 136,
// "group_id": 33
// }
// ],
// "msg": ""
// }
try {
print('response = ${response}');
// I/flutter (15540): response = null
response = await dio.post(api, data: map);
print('response = ${response}');
// I/flutter (15540): response = {"ret":200,"data":[{"uid":135,"group_id":31},{"uid":135,"group_id":27}],"msg":""}
if (response.statusCode == 200) {
Map _mapRet = await getMapFromJson(response.data);
print('_mapRet = ${_mapRet}');
// I/flutter (15540): _mapRet = {ret: 200, data: [{uid: 135, group_id: 31}, {uid: 135, group_id: 27}], msg: }
List _list = _mapRet['data'];
print('_list = $_list');
//I/flutter (15540): _list = []
if (_list.isNotEmpty) {
g_userInfo.userGroupIDlist.clear();
int len = _list.length;
for (int i = 0; i < len; i++) {
g_userInfo.userGroupIDlist.add(_list[i]["group_id"]);
eventBus.fire(GroupIdUpdateEvent('g_userInfo.userGroupIDlist 数据已更新')); //这样刷新有效
}
}
print('g_userInfo.userGroupIDlist = ${g_userInfo.userGroupIDlist}');
//I/flutter (15540): g_userInfo.userRulesMap = {31: []}
print('网络请求过程正常完成');
} else {
throw Exception('后端接口出现异常,请检测代码和服务器情况.........');
}
} catch (e) {
print('网络请求过程异常e = ${e}');
Fluttertoast.showToast(
msg: 'ERROR:======>${e}',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
}
//3、获取后台用户角色分组分页列表数据 ServicePath.getUserGroupListUrl
//5、获取后台功能分类分页列表数据 ServicePath.getUserAuthListUrl
//x、获取后台 x 分类分页列表数据
// int pages 为获取的页数, -1 为 All;int perpage 为每页记录数
// 返回:
// mapRecordList = {
// 'mapRecordListRet': {},
// 'listRecordList': [],
// };
Future getRecordList({@required String api, int pages = 3, int perpage = 20}) async {
print(api);
int _total = 0; //第一页时保存数据库中记录总数
int _counter = 0; //已读取的记录数计数器
int _page = 0;
String random = RandomBit(6);
Map map = {
'random': random,
'sign': GenerateMd5(APPkey + random),
'page': _page,
'perpage': perpage,
};
print('开始处理登录请求...');
Response response;
Dio dio = Dio();
Map mapRecordList = {
'mapRecordListRet': {},
'listRecordList': [],
};
try {
while (pages < 0 ? true : _page < pages) {
map['page']++;
response = await dio.post(api, data: map);
print('response = ${response.toString()}');
if (response.statusCode == 200) {
mapRecordList['mapRecordListRet'] = await getMapFromJson(response.data);
print('mapRecordList[\'mapRecordListRet\'] = ${mapRecordList['mapRecordListRet']}');
//第一页时保存数据库中记录总数
if (1 == map['page']) {
_total = mapRecordList['mapRecordListRet']['data']['total'];
}
mapRecordList['listRecordList'].addAll(mapRecordList['mapRecordListRet']['data']['items']);
//print('mapRecordList[\'listRecordList\'] = ${mapRecordList['listRecordList']}');
print('map[\'page\'] = ${map['page']}');
_counter = mapRecordList['listRecordList'].length; //已读取的记录数计数器
print('_counter = $_counter');
//I/flutter (23648): _counter = 8
print('_total = $_total');
// I/flutter (23648): _total = 8
//已读取的记录数计数器,超过或等于数据库中记录总数时,则终止循环
if (_counter >= _total) {
return mapRecordList;
}
print('第 ${map['page']} 次网络请求过程正常完成');
} else {
throw Exception('后端接口出现异常,请检测代码和服务器情况.........');
}
}
} catch (e) {
print('网络请求过程异常e = ${e}');
Fluttertoast.showToast(
msg: 'ERROR:======>${e}',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
return mapRecordList;
}
Map mapUserGroupList = {
'mapRecordListRet': {
"ret": 200,
"data": {
"items": [
{
"id": 35,
"jgid": 2,
"type": 0,
"title": "局领导",
"level": 0,
"pid": 0,
"sort": 1,
"status": 1,
"rules": ""
},
{
"id": 34,
"jgid": 2,
"type": 0,
"title": "系统管理",
"level": 0,
"pid": 0,
"sort": 1,
"status": 1,
"rules": ""
},
{
"id": 33,
"jgid": 2,
"type": 1,
"title": "参观者",
"level": 0,
"pid": 0,
"sort": 4,
"status": 1,
"rules":
"1968,1972,1973,1969,1976,1977,2008,2009,2011,2014,2015,2018,2029,2030,2031,2054,2055,2035,2036,2037,2041,2042,2043,2047,2048,2049,2053,1970,1980,1981,1971,1984,1985,1992,1993,2000,2001,2019,2020,2022"
},
{
"id": 32,
"jgid": 2,
"type": 0,
"title": "演示账户",
"level": 0,
"pid": 0,
"sort": 3,
"status": 1,
"rules":
"1968,1972,1973,1969,1976,1977,2008,2009,2011,2014,2015,2018,2029,2030,2031,2054,2055,2035,2036,2037,2041,2042,2043,2047,2048,2049,2053,1970,1980,1981,1971,1984,1985,1992,1993,2000,2001,2020,2022"
},
{
"id": 31,
"jgid": 2,
"type": 0,
"title": "监控室",
"level": 0,
"pid": 0,
"sort": 2,
"status": 1,
"rules": ""
},
{
"id": 30,
"jgid": 2,
"type": 0,
"title": "中心领导",
"level": 0,
"pid": 0,
"sort": 1,
"status": 1,
"rules":
"1968,1972,1973,1974,1975,1969,1976,1977,1978,1979,1970,1980,1981,1982,1983,1971,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007"
},
{
"id": 28,
"jgid": 2,
"type": 1,
"title": "审核操作员",
"level": 0,
"pid": 0,
"sort": 3,
"status": 1,
"rules":
"1968,1972,1973,1974,1975,1969,1976,1977,1978,1979,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2029,2030,2031,2054,2055,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050,2051,2052,2053,1970,1980,1981,1982,1983"
},
{
"id": 26,
"jgid": 2,
"type": 1,
"title": "管理员",
"level": 0,
"pid": 0,
"sort": 2,
"status": 1,
"rules":
"1968,1972,1973,1974,1975,1969,1976,1977,1978,1979,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2029,2030,2031,2054,2055,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050,2051,2052,2053,1970,1980,1981,1982,1983,1971,1984,1985,1986,1987,1988,1989,1990,1991,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028"
}
],
"total": 8,
"page": 1,
"perpage": 20
},
"msg": ""
},
'listRecordList': [],
};
Map mapUserAuthList = {
'mapRecordListRet': {},
'listRecordList': [],
};
Map mapRecordList = {
'mapRecordListRet': {},
'listRecordList': [],
};
//用户功能权限索引map,便于直观理解和处理。map_UserAuth.length = 78;1968 - 2069,中间有许多ID没有
Map map_UserAuth = {
1968: '黑烟车初审',
1969: '黑烟车复审',
1970: '推送交警',
1971: '设备管理',
1972: '信息审核',
1973: '查看',
1975: '审核',
1976: '信息审核',
1977: '查看',
1979: '审核',
1980: '推送交警',
1981: '查看',
1983: '审核',
1984: 'LED显示设置',
1985: '查看',
1986: '新增',
1987: '编辑',
1988: '锁定',
1989: '删除',
1990: '导出',
1991: '导入',
1992: '设备管理',
1993: '查看',
1994: '新增',
1995: '编辑',
1996: '锁定',
1997: '删除',
1998: '导出',
1999: '导入',
2000: '点位管理',
2001: '查看',
2002: '新增',
2003: '编辑',
2004: '锁定',
2005: '删除',
2006: '导出',
2007: '导入',
2008: '历史数据',
2009: '查看',
2010: '新增',
2014: '审核',
2015: '打印',
2016: '导出',
2019: '报警信息管理',
2020: '查看',
2023: '锁定',
2025: '审核',
2027: '导出',
2028: '分析',
2029: '查询与统计',
2030: '历史数据查询',
2031: '查看',
2034: '导出',
2035: '分析',
2036: '车辆点位频率分析',
2037: '查看',
2041: '分析',
2042: '车辆轨迹查询',
2043: '查看',
2047: '分析',
2048: '年度数据统计',
2049: '查看',
2053: '分析',
2054: '实时统计',
2055: '实时统计今日抓拍数量',
2056: '历史数据',
2057: '查看',
2059: '审核',
2060: '导出',
2061: '监测点位状态',
2062: '查看',
2063: '分析',
2064: '监测点位状态详情',
2065: '查看',
2066: '分析',
2067: '车流量统计',
2068: '查看',
2069: '分析',
};
Future getUserAuthMap({@required String value, String key = 'id'}) {
int len = mapUserAuthList['listRecordList'].length;
map_UserAuth.clear();
for (int i = 0; i < len; i++) {
map_UserAuth[mapUserAuthList['listRecordList'][i][key]] =
mapUserAuthList['listRecordList'][i][value];
}
map_UserAuth = mapSort(map_UserAuth);
print('map_UserAuth.length = ${map_UserAuth.length}');
//print('map_UserAuth = $map_UserAuth'); //输出不全
my_segmentPrint(json_print(map_UserAuth, 1));
}
Future getUserAuth() {
int len = mapUserAuthList['listRecordList'].length;
map_UserAuth.clear();
for (int i = 0; i < len; i++) {
map_UserAuth[mapUserAuthList['listRecordList'][i]["id"]] =
mapUserAuthList['listRecordList'][i]["title"];
}
//按抓拍次数排序,升序
// listHycsGetList2.sort((a, b) =>
// (a[mapWzxxDataText[_selectedValue]].split(',').length.toString())
// .compareTo(b[mapWzxxDataText[_selectedValue]].split(',').length.toString()));
//print('map_UserAuth = $map_UserAuth'); //输出不全
print('map_UserAuth.length = ${map_UserAuth.length}');
my_segmentPrint('map_UserAuth = ${map_UserAuth}');
map_UserAuth = mapSort(map_UserAuth);
my_segmentPrint('map_UserAuth = ${map_UserAuth}');
//I/flutter ( 5140): map_UserAuth = {1968: 黑烟车初审, 1969: 黑烟车复审, 1970: 推送交警, 1971: 设备管理, 1972: 信息审核, 1973: 查看, 1975: 审核, 1976: 信息审核, 1977: 查看, 197
// 9: 审核, 1980: 推送交警, 1981: 查看, 1983: 审核, 1984: LED显示设置, 1985: 查看, 1986: 新增, 1987: 编辑, 1988: 锁定, 1989: 删除, 1990: 导出, 1991: 导入, 1992: 设备管理, 1993:
// 查看, 1994: 新增, 1995: 编辑, 1996: 锁定, 1997: 删除, 1998: 导出, 1999: 导入, 2000: 点位管理, 2001: 查看, 2002: 新增, 2003: 编辑, 2004: 锁定, 2005: 删除, 2006: 导出, 2007: 导
// 入, 2008: 历史数据, 2009: 查看, 2010: 新增, 2014: 审核, 2015: 打印, 2016: 导出, 2019: 报警信息管理, 2020: 查看, 2023: 锁定, 2025: 审核, 2027: 导出, 2028: 分析, 2029: 查询与统
// 计, 2030: 历史数据查询, 2031: 查看, 2034: 导出, 2035: 分析, 2036: 车
// I/flutter ( 5140): 辆点位频率分析, 2037: 查看, 2041: 分析, 2042: 车辆轨迹查询, 2043: 查看, 2047: 分析, 2048: 年度数据统计, 2049: 查看, 2053: 分析, 2054: 实时统计, 2055: 实时
// 统计今日抓拍数量, 2056: 历史数据, 2057: 查看, 2059: 审核, 2060: 导出, 2061: 监测点位状态, 2062: 查看, 2063: 分析, 2064: 监测点位状态详情, 2065: 查看, 2066: 分析, 2067: 车流量
// 统计, 2068: 查看, 2069: 分析}
}
mapSort(Map map) {
// List<String> keys = map.keys.toList();
// // key排序
// keys.sort((a, b) {
// List<int> al = a.codeUnits;
// List<int> bl = b.codeUnits;
// for (int i = 0; i < al.length; i++) {
// if (bl.length <= i) return 1;
// if (al[i] > bl[i]) {
// return 1;
// } else if (al[i] < bl[i]) return -1;
// }
// return 0;
// });
var sortedKeys = map_UserAuth.keys.toList()..sort();
//print('sortedKeys = $sortedKeys'); //输出不全
//segmentPrint('sortedKeys = ${sortedKeys}');
//I/flutter ( 5140): sortedKeys = [1968, 1969, 1970, 1971, 1972, 1973, 1975, 1976, 1977, 1979, 1980, 1981, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 199
// 4, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2014, 2015, 2016, 2019, 2020, 2023, 2025, 2027, 2028, 2029, 2030, 2031, 203
// 4, 2035, 2036, 2037, 2041, 2042, 2043, 2047, 2048, 2049, 2053, 2054, 2055, 2056, 2057, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069]
//new一个map按照keys的顺序将原先的map数据取出来就可以了。
Map sortedMap = {};
sortedKeys.forEach((element) {
sortedMap[element] = map[element];
});
return sortedMap;
}
+72
View File
@@ -0,0 +1,72 @@
import 'EncryptUtil.dart';
import 'dart:convert';
class UserInfo {
UserInfo({this.mapUserInfoRet}) {
setUserInfo(theMapUserInfoRet: mapUserInfoRet);
}
setUserInfo({Map theMapUserInfoRet}) {
if (200 == theMapUserInfoRet["ret"]) {
mapUserInfoRet = theMapUserInfoRet;
mapUserInfo = theMapUserInfoRet["data"];
print('mapUserInfo = ${mapUserInfo.toString()}');
}
}
//_mapGetData = {is_login: true, user_id: 135, token: 4C5B3F93FEACAEF4B6CAA7296F22CC67825D7E48B867614383D19E3F23DFE510}
setUserInfoFaceLogin(Map _mapGetData) {
mapUserInfo['user_id'] = _mapGetData['user_id'];
mapUserInfo['token'] = _mapGetData['token'];
}
Map mapUserInfoRet = {
"ret": 200,
"data": {
"is_login": true,
"user_id": 1,
"token": "B93EC91FA2FE293B7077162D4527FC4BB228CD6C0A4F24A882B9A8BBE6C3FB47"
},
"msg": ""
};
Map mapUserInfo = {
"is_login": false,
"user_id": -1,
"token": ""
};
//若list[i]为'',解密时会报错:aes decode error:RangeError: Value not in range: -16
String thisAndroidId = ''; //每个手机唯一的设备号
String username = '';
String password = '';
String userLoginInfo = '';
List<int> userGroupIDlist = []; //用户所属组列表
Map userRulesMap = {}; //用户所属组的权限列表
String getUserinfoEncrypted2() {
String userinfoEncrypted1 = EncryptUtil.aesEncode(thisAndroidId) +
'\n' +
EncryptUtil.aesEncode(username) +
'\n' +
EncryptUtil.aesEncode(password) +
'\n' +
EncryptUtil.aesEncode(userLoginInfo);
String userinfoEncrypted2 = EncryptUtil.aesEncode(userinfoEncrypted1);
return userinfoEncrypted2;
}
String getUserinfoDencrypted2(String userinfoEncrypted2) {
String userinfoDencrypted1 = EncryptUtil.aesDecode(userinfoEncrypted2);
List<String> list = userinfoDencrypted1.split('\n');
int len = list.length;
String userinfoDencrypted2 = '';
print('len = $len');
for (int i = 0; i < len; i++) {
list[i] = EncryptUtil.aesDecode(list[i]);
userinfoDencrypted2 += ('' == userinfoDencrypted2 ? '' : '\n') + list[i];
}
return userinfoDencrypted2;
}
}
+678
View File
@@ -0,0 +1,678 @@
import 'dart:convert';
import 'dart:developer' as developer;
import 'dart:io';
import 'dart:math';
import 'package:camera/camera.dart';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart' as crypto;
import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
//import '../my_wechat_assets_picker_fix/my_asset_picker_1.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hyzp_ybqx/provider/player_region.dart';
import 'UserInfo.dart';
//LED字幕信息
//String g_ledMessage = '绿水青山就是金山银山 宜宾市生态环境局宣。';
// 是否已经调用 FlutterDownloader.initialize(debug: true)
bool bFlutterDownloader_initialize = false;
bool bNewVer = false; //是否发现新版本
//处理延时登录,判断从网络获取三种统计数据是否完成
bool bMayLogin = false;
//处理延时登录,判断是否已经点击登录按钮
bool bPreLoading = false;
//处理延时登录,判断用户名登录是否验证通过
bool bLoginVerify = false;
bool bHasMore = true;
//part library
//dart中,通过使用part、part of、library来实现拆分库,这样,就可以将一个庞大的库拆分成各种小库,只要引用主库即可
//点位总数
int dwSum = -1;
Size sizeWindowPhysicalSize;
//String dateAppCompile = '2020.12.30'; //1.0.1+1
//String dateAppCompile = '2021.02.20'; //1.2.5+1
//String dateAppCompile = '2021.03.18'; //1.2.6+1
//String dateAppCompile = '2021.05.18'; //1.2.7
List<String> g_list = [];
//正在获取点位视频标志,禁止重入
bool getingDwVideo = false;
int getCount = 1; //获取点位视频地址尝试次数
int getSumTime = 0; //获取点位视频地址耗时(秒)
int getingIndex = -1; //正在获取视频的点位的索引号
String getingDwmc = ''; //正在获取视频的点位名称
String urlnew =
"http://www.yibinu.edu.cn/__local/5/35/DF/264049B7E978EEE2F5849688986_05D4A6FE_152CDB8C.mp4?e=.mp4";
bool isVideoUrl(String url, {bool showToast = false}) {
print('url = $url');
String prefix = url.substring(0, 4);
List list = ['http', 'rtmp', 'rstp'];
for (String item in list) {
if (prefix == item) {
return true;
}
}
if (showToast) {
Fluttertoast.showToast(
msg: '获取视频地址失败',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
return false;
}
final TextEditingController myController = TextEditingController();
bool Playing = false; //禁止同时启动两次播放器
//final FijkPlayer player = FijkPlayer();
int g_iIndex = 0;
PlayerRegionProvide playerRegionProvide;
Future<void> sysPop() async {
// currentPos = player.currentPos.inMilliseconds; //seekto方法的参数是毫秒
// await writeCurrentPosFile();
// await player.stop();
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
//人脸注册和人脸识别登录成功标志
int faceReg = -1; //1 成功,0 失败,-1 处理中
int faceLogin = -1; //1 成功,0 失败,-1 处理中
//人脸注册时所需用户ID
int faceRegUserID = -1; //人脸注册时所需用户ID,-1 非法
List<CameraDescription> cameras;
UserInfo g_userInfo = UserInfo(mapUserInfoRet: {
"ret": 200,
"data": {
"is_login": true,
"user_id": 1,
"token": "B93EC91FA2FE293B7077162D4527FC4BB228CD6C0A4F24A882B9A8BBE6C3FB47"
},
"msg": ""
});
Future<Map> getMapFromJson(var response) async {
String _str = json.encode(response);
Map _map = json.decode(_str);
return _map;
}
// Future<void> getVideoList(BuildContext context) async {
// List<AssetEntity> assets = <AssetEntity>[];
// return await MyAssetPicker.pickAssets(
// context,
// maxAssets: 1,
// selectedAssets: assets,
// requestType: RequestType.video,
// );
// }
Future<String> getAndroidId() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
//print('每个手机唯一的设备号:${androidInfo.androidId}'); // e.g. "Moto G (4)"
g_userInfo.thisAndroidId = androidInfo.androidId;
return g_userInfo.thisAndroidId;
}
// void playOrPause() {
// playerRegionProvide.changePlayerState(bPlaying);
//
// if (bPlaying) {
// player.start();
// } else {
// player.pause();
// }
//
// Storage.setString('bFirstPlay', bFirstPlay ? 'true' : 'false');
// Storage.setString('bPlaying', bPlaying ? 'true' : 'false');
//
// //updateFile();
// }
//
// void playAndPause() {
// if (player.state == FijkState.started) {
// bPlaying = false;
// player.pause();
// } else if (player.state == FijkState.paused) {
// bPlaying = true;
// player.start();
// }
// //setState(() {});
// playerRegionProvide.changePlayerState(bPlaying);
// Storage.setString('bPlaying', bPlaying ? 'true' : 'false');
// }
Alignment getAlignment(Offset offset, Size size) {
// final double centerX = offset.dx / 2.0;
// final double centerY = offset.dy / 2.0;
//offset.dx = centerX + alignment.x * centerX;
//double alignmentX = (0.0 == centerX) ? 0.0 : ((offset.dx - centerX) / centerX);
double alignmentX = (offset.dx / size.width).clamp(-1.0, 1.0);
//offset.dy = centerY + alignment.y * centerY;
//double alignmentY = (0.0 == centerY) ? 0.0 : ((offset.dy - centerY) / centerY);
double alignmentY = (offset.dy / size.height).clamp(-1.0, 1.0);
// print('offset.dx = ${offset.dx}, offset.dy = ${offset.dy}');
print('Alignment.X = $alignmentX, Alignment.Y = $alignmentY');
return Alignment(alignmentX, alignmentY);
}
//flutter (dart)生成N位随机数
//https://blog.csdn.net/qq_36071410/article/details/101268640
// 庄童 2019-09-24 10:24:58 10271 收藏
String RandomBit(int len) {
String scopeF = '123456789'; //首位
String scopeC = '0123456789'; //中间
String result = '';
for (int i = 0; i < len; i++) {
if (i == 0) {
result = scopeF[Random().nextInt(scopeF.length)];
} else {
result = result + scopeC[Random().nextInt(scopeC.length)];
}
}
return result;
}
// sign=md5(ijddvzgEGaxbzsbmCtpdohxHyrAArwJB1003)
// =3967eaebec0eed0642a1d395ac9293dd
String APPkey = 'ijddvzgEGaxbzsbmCtpdohxHyrAArwJB';
//Flutter对字符串进行MD5运算 发表于 2019-03-26 更新于 2020-12-04 分类于 Flutter 阅读次
String GenerateMd5(String str) {
var content = new Utf8Encoder().convert(str);
var md5 = crypto.md5;
var digest = md5.convert(content);
return hex.encode(digest.bytes);
}
//加载中的圈圈
Widget getMoreWidget2({
Color color = Colors.white,
String text = '加载中...',
double size = 30.0,
double strokeWidth = 3.0,
FontWeight fontWeight,
double edge = 10.0,
double height = 34,
}) {
return Center(
child: Padding(
padding: EdgeInsets.all(edge),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: size,
width: size,
child: CircularProgressIndicator(
strokeWidth: strokeWidth,
valueColor: AlwaysStoppedAnimation<Color>(color),
),
),
SizedBox(
height: ScreenUtil().setHeight(height),
),
Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: size, // 文字大小
color: color,
fontWeight: fontWeight, // 文字颜色
),
),
],
),
),
);
}
//加载中的圈圈
Widget getMoreWidget({
String text = '加载中...',
Color color = Colors.white,
double size = 30.0,
double strokeWidth = 3.0,
TextAlign textAlign = TextAlign.left,
}) {
return Center(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: size,
width: size,
child: CircularProgressIndicator(
strokeWidth: strokeWidth,
valueColor: AlwaysStoppedAnimation<Color>(color),
),
),
SizedBox(
height: 10,
),
Text(
text,
textAlign: textAlign,
style: TextStyle(
fontSize: size, // 文字大小
color: color,
),
),
],
),
),
);
}
//自定义带说明图标按钮函数。点击说明文字有反应
Widget getIconAndTextButton(
{IconData iconData, Color iconColor = Colors.black, var onPress = null}) {
return Container(
width: 50,
height: 50,
alignment: const Alignment(0, 0),
child: FlatButton(
padding: EdgeInsets.all(0),
onPressed: onPress,
//color: Colors.blue,
color: Colors.transparent,
//解决报错问题:FittedBox ← Expanded ← ConstrainedBox ← Container ← Center ← Padding ←
// Container ← IconTheme ← Builder ← _PointerListener
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 36, //最大高度
maxWidth: 36, //最大宽度
),
child: Padding(
padding: EdgeInsets.only(top: 1),
child: Icon(iconData, color: iconColor, size: 32),
// child: Image.asset(
// 'assets/images/left_arrow.png',
// fit: BoxFit.fitWidth,
// color: iconColor,
// //fit: BoxFit.cover,
// ),
),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.end,
// children: [
// Image.asset('assets/images/left_arrow.png', fit: BoxFit.cover),
// // Expanded(
// // //child: Icon(iconData, color: iconColor, size: 24),
// // child: Image.asset('assets/images/left_arrow.png', fit: BoxFit.cover),
// // ),
// ],
// ),
),
//The offending Expanded is currently placed inside a ConstrainedBox widget.
//The ownership chain for the RenderObject that received the incompatible parent data was:
// FittedBox ← Expanded ← ConstrainedBox ← Container ← Center ← Padding ← Container ← IconTheme ←
//Builder ← _PointerListener
//The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
//RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
//Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically,
//Expanded widgets are placed directly inside Flex widgets.
//The offending Expanded is currently placed inside a FittedBox widget.
//The ownership chain for the RenderObject that received the incompatible parent data was:
// ConstrainedBox ← Container ← Expanded ← FittedBox ← Center ← Padding ← Container ← IconTheme ←
//Builder ← _PointerListener ← ⋯
// child: ConstrainedBox(
// constraints: BoxConstraints(
// maxHeight: 20, //最大高度
// maxWidth: 28, //最大宽度
// ),
// child: Container(
// child: Expanded(
// child: new Icon(iconData, color: iconColor),
// ),
// ),
// ),
// child: ConstrainedBox(
// constraints: BoxConstraints(
// maxHeight: 30, //最大高度
// maxWidth: 38, //最大宽度
// minWidth: 38, //最大宽度
// ),
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Expanded(
// child: Icon(iconData, color: iconColor, size: 24),
// ),
// ],
// ),
// ),
// child: Container(
// width: 28,
// height: 20,
// child: Expanded(
// child: new FittedBox(
// fit: BoxFit.fill,
// child: new Icon(iconData, color: iconColor),
// ),
// ),
// ),
// child: FittedBox(
// fit: BoxFit.fitWidth,
// alignment: Alignment.topLeft,
// child: Container(
// width: 28,
// height: 20,
// child: Expanded(
// child: new FittedBox(
// fit: BoxFit.fill,
// child: new Icon(iconData, color: iconColor),
// ),
// ),
// ),
// ),
),
);
}
///获取缩进空白符
String getDeepSpace(int deep) {
var tab = StringBuffer();
for (int i = 0; i < deep; i++) {
tab.write("\t");
}
return tab.toString();
}
// List map2list(Map _map) {
// List _list = [];
// _list = List.generate(listContacts2[widget.contactIndex].length, (index) {
// String key = listContacts2[widget.contactIndex].keys.elementAt(index);
// //return TextEditingController(text: listContacts2[widget.contactIndex][key]);
// return TextEditingController(text: getUserText3(widget.contactIndex, key));
// });
//
// }
/// [object] 解析的对象
/// [deep] 递归的深度,用来获取缩进的空白长度
/// [isObject] 用来区分当前map或list是不是来自某个字段,则不用显示缩进。单纯的map或list需要添加缩进
String json_print(dynamic object, int deep, {bool isObject = false}) {
var buffer = StringBuffer();
var nextDeep = deep + 1;
if (object is Map) {
var list = object.keys.toList();
if (!isObject) {
//如果map来自某个字段,则不需要显示缩进
buffer.write("${getDeepSpace(deep)}");
}
buffer.write("{");
if (list.isEmpty) {
//当map为空,直接返回‘}’
buffer.write("}");
} else {
buffer.write("\n");
for (int i = 0; i < list.length; i++) {
buffer.write("${getDeepSpace(nextDeep)}\"${list[i]}\":");
buffer.write(json_print(object[list[i]], nextDeep, isObject: true));
if (i < list.length - 1) {
buffer.write(",");
buffer.write("\n");
}
}
buffer.write("\n");
buffer.write("${getDeepSpace(deep)}}");
}
} else if (object is List) {
if (!isObject) {
//如果list来自某个字段,则不需要显示缩进
buffer.write("${getDeepSpace(deep)}");
}
buffer.write("[");
if (object.isEmpty) {
//当list为空,直接返回‘]’
buffer.write("]");
} else {
buffer.write("\n");
for (int i = 0; i < object.length; i++) {
buffer.write(json_print(object[i], nextDeep));
if (i < object.length - 1) {
buffer.write(",");
buffer.write("\n");
}
}
buffer.write("\n");
buffer.write("${getDeepSpace(deep)}]");
}
} else if (object is String) {
//为字符串时,需要添加双引号并返回当前内容
buffer.write("\"$object\"");
} else if (object is num || object is bool) {
//为数字或者布尔值时,返回当前内容
buffer.write(object);
} else {
//如果对象为空,则返回null字符串
buffer.write("null");
}
return buffer.toString();
}
//人脸识别和上传的图片,都需要转换为 Base64 格式的字符串提交
//通过图片路径将图片转换成 Base64 字符串
Future image2Base64(String imagePath) async {
File file = File(imagePath);
List<int> imageBytes = await file.readAsBytes();
String bs64 = base64Encode(imageBytes);
String ext = getFileExtension(imagePath);
print('imagePath = $imagePath, ext = $ext');
//String bs64Image = "data:image/png;base64," + bs64;
String bs64Image = "data:image/${ext};base64," + bs64;
return bs64Image;
}
//从字符路径 path 获取扩展名,不含点号
getFileExtension(String path) {
//return path.substring(path.lastIndexOf('.'));
//imagePath = /data/user/0/com.flutter.hyzp_ybqx/app_flutter/Pictures/flutter_test/1614662209478.jpg, ext = .jpg
return path.substring(path.lastIndexOf('.') + 1); //不含点号
}
//从字符路径 path 获取文件名(含扩展名)
getFileName(String path) {
//return path.substring(path.lastIndexOf('.'));
//imagePath = /data/user/0/com.flutter.hyzp_ybqx/app_flutter/Pictures/flutter_test/1614662209478.jpg, ext = .jpg
return path.substring(path.lastIndexOf('/') + 1); //不含点号
}
Widget getBtnSizeX({@required text, double width = 70.0, double height = 40.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,
),
);
}
//返回主页ashamp
// 博客园首页新随笔联系管理订阅订阅随笔 - 33 文章 - 0 评论 - 51 阅读 - 55018
// 在debug时使Flutter中的print打印json数据时更美观易读
// 为了避免deubg信息在生产环境打印,只在测试时打印,在main函数中,改变debugPrint的指向
//
// 复制代码
// main(){
// if (Api.isDebug) {
// debugPrint = (String message, {int wrapWidth}) {
// try {
// var object = json.decode(message);
// message = JsonEncoder.withIndent(' ').convert(object);
// } catch (e) {}
// printWrapped(message);
// };
// } else {
// debugPrint = (String message, {int wrapWidth}) {};
// }
// }
// 复制代码
// 将printWrapped方法放入工具类或你需要的地方
//
// void printWrapped(String text) {
// final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
// pattern.allMatches(text).forEach((match) => developer.log(match.group(0)));
// }
// log方法需要引入
//
// import 'dart:developer' as developer;
//
//在debug时使 Flutter 中的 print 打印 json 数据时更美观易读
void jsonPrint(String message, {int len = 800}) {
//是否在生产环境
const bool isDebug = !const bool.fromEnvironment("dart.vm.product");
// if (!isDebug) {
// return;
// }
try {
var object = json.decode(message);
message = JsonEncoder.withIndent(' ').convert(object);
} catch (e) {
print('e = $e');
}
printWrapped(message);
}
// 打印长字符串
void printWrapped(String text, {int len = 800}) {
final pattern = RegExp('.{1,$len}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((match) => developer.log(match.group(0)));
}
//OK
void my_segmentPrint(String str, {int len = 800}) {
//是否在生产环境
const bool isDebug = !const bool.fromEnvironment("dart.vm.product");
if (!isDebug) {
return;
}
List list = strToList(str);
for (int i = 0; i < list.length; i++) {
print('${list[i]}');
}
}
//OK
List strToList(String str, {int len = 800}) {
List<String> strList = [];
if (str.length <= len) {
strList.add(str);
} else {
int splitCount = str.length ~/ len; //应该切割的次数
for (int i = 0; i < splitCount; i++) {
strList.add(str.substring(len * i, len * (i + 1)));
}
//处理最后一段
if (str.length % len != 0) {
strList.add(str.substring(len * splitCount));
}
}
print('strList:${strList.toString}');
return strList;
}
Widget getImageWidget() {
return Container(
alignment: Alignment(0, 0),
height: ScreenUtil().setHeight(346),
width: ScreenUtil().setWidth(942),
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('assets/images/装饰图片10.png'), fit: BoxFit.cover),
),
child: Column(
children: [
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(top: ScreenUtil().setWidth(30), left: ScreenUtil().setWidth(55)),
child: Text('改善城市空气质量', style: TextStyle(fontSize: 17, color: Colors.white)),
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(left: ScreenUtil().setWidth(55)),
child: Text('建设长江生态第一城',
style: TextStyle(
fontSize: 19,
color: Color.fromRGBO(49, 216, 123, 1),
fontWeight: FontWeight.bold)),
),
],
),
// child: Image.asset(
// 'assets/images/装饰图片10.png',
// fit: BoxFit.cover,
// ),
);
}
Widget getIconBtnSizeX(
{@required text,
width = 233,
height = 116,
onTop,
Color color = Colors.black,
double circular = 10,
double textSize = 18}) {
return InkWell(
onTap: onTop,
child: Container(
alignment: Alignment(0, 0),
margin: EdgeInsets.all(0),
padding: EdgeInsets.all(0),
width: ScreenUtil().setWidth(width),
height: ScreenUtil().setHeight(height),
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(circular)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: ScreenUtil().setWidth(12)),
Icon(Icons.play_arrow, color: Colors.white, size: ScreenUtil().setWidth(56)),
Text(
text,
style: TextStyle(color: Colors.white, fontSize: textSize),
)
],
),
),
);
}
+166
View File
@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'customDialogC.dart';
import 'commonFun.dart';
//视频列表對話框
class customDialogA extends Dialog {
String title;
String content;
String url;
customDialogA({this.title = "", this.content = "", this.url = ''});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
// TODO: implement build
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, 0),
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.85,
width: mediaSize.width * 0.95,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text("${this.title}",
style: TextStyle(
fontSize: 18.0,
)),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, url);
},
),
)
],
),
),
Divider(),
//addDialoadContainer4(context, g_list, url),
//MyDialogContent(countries: ['china', 'England']),
MyDialogContent(list: g_list, url: url),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: () {
Navigator.pop(context, url);
},
child: Text("取消"),
),
RaisedButton(
child: Text("确认"),
onPressed: () async {
Navigator.pop(context, url); //关闭弹框,播放输入视频地址
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context, url);
},
);
}
}
class MyDialogContent extends StatefulWidget {
List<String> list;
String url;
MyDialogContent({this.list, this.url});
@override
_MyDialogContentState createState() => new _MyDialogContentState();
}
class _MyDialogContentState extends State<MyDialogContent> {
@override
Widget build(BuildContext context) {
return addDialoadContainer4(context, widget.list, widget.url);
}
Widget addDialoadContainer4(
BuildContext context, List<String> list, String url) {
Size mediaSize = MediaQuery.of(context).size;
int i = 0;
print('\ng_list start =========================================\n');
for (var s in list) {
print('$i - ' + s + '\n');
i++;
}
print('g_list start =========================================\n\n');
return Container(
height: mediaSize.height * 0.65, //0.75越界,0.7不越界。需要0.2 = 0.9 - 0.7
width: mediaSize.width * 0.9,
child: ListView.builder(
shrinkWrap: true,
itemCount: list.length,
itemBuilder: (BuildContext context, int index) {
int index2 = index + 1;
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(20, 0, 10, 0),
child: InkWell(
child: Text('$index2 : ' + list[index],
style: TextStyle(fontSize: 15.0)),
onTap: () {
print('index : $index');
Navigator.pop(context, list[index]);
},
onLongPress: () async {
await showDialog(
context: context,
builder: (context) {
myController.text = '';
return CustomDialogC(
title: "选择操作",
url: g_list[index],
index: index,
);
});
setState(() {});
},
),
),
Divider(),
],
);
},
),
);
}
}
+188
View File
@@ -0,0 +1,188 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
import 'package:flutter/services.dart';
//输入视频地址对话框
class customDialogB extends Dialog {
String title;
String content;
String url;
customDialogB({this.title = "", this.content = "", this.url = ''});
// Widget getButton({double width = 60.0, double height = 30.0, RaisedButton raisedButton}) {
// return ButtonTheme(
// minWidth: width, //设置最小宽度
// height: height,
// //colorScheme: ,
// buttonColor: Colors.white60,
// child: raisedButton,
// );
// }
Widget getBtnSizeX({@required text, width = 60.0, height = 30.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,
),
);
}
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
// TODO: implement build
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, -0.7),
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.4,
width: mediaSize.width * 0.95,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, url);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: TextField(
maxLines: 4,
controller: myController,
autofocus: false, //不会自动打开输入键盘
decoration: InputDecoration(
fillColor: Theme.of(context).hoverColor,
filled: true,
hintText: 'Media Url',
border: OutlineInputBorder()
//labelText: 'Media Url',
),
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "粘贴",
onPressedFun: () async {
ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
myController.text = data.text;
},
),
// getButton(
// raisedButton: RaisedButton(
// onPressed: () async {
// ClipboardData data =
// await Clipboard.getData(Clipboard.kTextPlain);
// myController.text = data.text;
// },
// child: Text("粘贴"),
// ),
// ),
getBtnSizeX(
text: "获取",
onPressedFun: () async {
myController.text = url;
},
),
// getButton(
// raisedButton: RaisedButton(
// onPressed: () async {
// myController.text = url;
// },
// child: Text("获取"),
// ),
// ),
getBtnSizeX(
text: "清除",
onPressedFun: () {
myController.clear();
},
),
// getButton(
// raisedButton: RaisedButton(
// onPressed: () {
// myController.clear();
// },
// child: Text("清除"),
// ),
// ),
getBtnSizeX(
text: "播放",
onPressedFun: () {
//Navigator.of(context).pop() //关闭弹框,这样关闭会导致视频播放停止,无法开始
if ("" != myController.text) {
urlnew = url = myController.text;
}
Navigator.pop(context, url); //关闭弹框,播放输入视频地址
},
),
// getButton(
// raisedButton: RaisedButton(
// onPressed: () {
// //Navigator.of(context).pop() //关闭弹框,这样关闭会导致视频播放停止,无法开始
// if ("" != myController.text) {
// urlnew = url = myController.text;
// }
// Navigator.pop(context, url); //关闭弹框,播放输入视频地址
// },
// child: Text("播放"),
// ),
// ),
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context, url);
},
);
}
}
+124
View File
@@ -0,0 +1,124 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
//删除确认对话框
class CustomDialogC extends Dialog {
String title;
String url;
int index;
CustomDialogC({this.title = "", this.url = "", this.index});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, -0.7),
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.35,
width: mediaSize.width * 0.85,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, url);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
height: mediaSize.height * 0.15,
child: SingleChildScrollView(
child: Text(index.toString() + ' : ' + url),
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
// RaisedButton(
// onPressed: () async {
// await showDialog(
// context: context,
// builder: (context) {
// myController.text = g_list[index].trim();
// return CustomDialogD(
// title: "修改视频地址",
// content: g_list[index].trim(),
// url: urlnew);
// });
// String url0 = g_list[index].trim().toLowerCase();
// String url2 = myController.text.trim().toLowerCase();
// if (url2.isNotEmpty && 0 != url0.compareTo(url2)) {
// g_list.removeAt(index);
// g_list.add(url2);
// await updateFile();
// }
// Navigator.pop(context, url); //关闭弹框,返回sRet
// },
// child: Text("修改"),
// ),
RaisedButton(
onPressed: () async {
g_list.removeAt(index);
//await updateFile();
//writeUrlFile2();
Navigator.pop(context, url); //关闭弹框,返回sRet
},
child: Text("删除"),
),
RaisedButton(
child: Text("取消"),
onPressed: () async {
Navigator.pop(context, url); //关闭弹框,返回sRet
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context, url);
},
);
}
}
+115
View File
@@ -0,0 +1,115 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
//修改视频地址对话框
class CustomDialogD extends Dialog {
String title;
String content;
String url;
CustomDialogD({this.title = "", this.content = "", this.url = ''});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
myController.text = content; //为TextField赋初始值
// TODO: implement build
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, -0.7),
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.4,
width: mediaSize.width * 0.85,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, url);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: TextField(
maxLines: 4,
controller: myController,
autofocus: false, //不会自动打开输入键盘
decoration: InputDecoration(
fillColor: Theme.of(context).hoverColor,
filled: true,
hintText: 'Media Url',
border: OutlineInputBorder()
//labelText: 'Media Url',
),
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: () {
myController.text = url;
},
child: Text("获取"),
),
RaisedButton(
onPressed: () {
myController.clear();
},
child: Text("清除"),
),
RaisedButton(
child: Text("确认"),
onPressed: () async {
Navigator.pop(context, url); //关闭弹框,播放输入视频地址
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context, url);
},
);
}
}
+177
View File
@@ -0,0 +1,177 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'doJSON.dart';
import 'hyxx_data_handle.dart';
import 'dart:convert';
import '../pages/MyMsics/03_personal/ContactModify.dart';
import '../pages/MyMsics/03_personal/ContactAdd.dart';
//添加、修改、删除联系人对话框
class customDialogE extends Dialog {
String title;
String content;
int index;
customDialogE({this.title = "", this.content = "", this.index = -1});
// String getTitle(int index) {
// return listContacts2[index]["姓名"] +
// ', ' +
// listContacts2[index]["部门"] +
// ', ' +
// listContacts2[index]["职务"] +
// '\n' +
// listContacts2[index]["手机"] +
// ', ' +
// listContacts2[index]["邮箱"];
// }
Widget getBtnSizeX({@required text, width = 60.0, height = 30.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,
),
);
}
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
//myController.text = getTitle(this.index);
myController.text = content;
// TODO: implement build
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, -0.7),
child: Container(
height: mediaSize.height * 0.4,
width: mediaSize.width * 0.95,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
//Navigator.pop(context, index);
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: TextField(
maxLines: 4,
controller: myController,
autofocus: false,
//不会自动打开输入键盘
decoration: InputDecoration(
fillColor: Theme.of(context).hoverColor,
filled: true,
hintText: 'Media Url',
border: OutlineInputBorder(),
),
enableInteractiveSelection: false,
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
},
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "添加",
onPressedFun: () async {
//跳转到修改对话框
Navigator.of(context)
.push(MaterialPageRoute(
builder: (context) => ContactAdd(contactIndex: index)))
.then((value) => Navigator.pop(context));
},
),
getBtnSizeX(
text: "修改",
onPressedFun: () async {
//跳转到修改对话框
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ContactModify(contactIndex: index)));
await Navigator.pop(context); //先关闭“选择操作”对话框
//跳转并关闭当前页面
// Navigator.pushAndRemoveUntil(
// context,
// MaterialPageRoute(
// builder: (context) => ContactModify(contactIndex: index)),
// (route) => route == null,
// );
},
),
getBtnSizeX(
text: "删除",
onPressedFun: () {
listContacts2.removeAt(index);
bFlash = true;
print("ContactDel bFlash = $bFlash");
writeJSON(json.encode(listContacts2), 'listContacts2.json');
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
getBtnSizeX(
text: "复制",
onPressedFun: () {
// Flutter 复制文本到剪贴板
Clipboard.setData(ClipboardData(text: myController.text));
//showToast('帮助信息已复制到剪贴板', textAlign: TextAlign.left);
Fluttertoast.showToast(msg: '联系人信息已复制到剪贴板', gravity: ToastGravity.BOTTOM);
},
),
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
//Navigator.pop(context, index);
},
);
}
}
+102
View File
@@ -0,0 +1,102 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
//确认对话框
class CustomDialogF extends Dialog {
String title;
String content;
bool ret = false;
CustomDialogF({this.title = "", this.content});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
padding: EdgeInsets.only(top: 126),
alignment: Alignment(0, -1),
color: Colors.black12,
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.315,
width: mediaSize.width * 0.9,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 20.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, ret);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
height: mediaSize.height * 0.1,
child: SingleChildScrollView(
child: Text(content, style: TextStyle(fontSize: 18.0, color: Colors.blue)),
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: () async {
ret = true;
Navigator.pop(context, ret); //关闭弹框,返回sRet
},
child: Text("确认"),
),
RaisedButton(
child: Text("取消"),
onPressed: () async {
Navigator.pop(context, ret); //关闭弹框,返回sRet
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
Navigator.pop(context, ret);
},
);
}
}
+143
View File
@@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import 'package:flutter_drag_scale/core/drag_scale_widget.dart';
import 'dart:io';
//确认对话框
class CustomDialogFaceReg extends Dialog {
String title;
String username;
String imagePath;
Size imageSize;
CustomDialogFaceReg(
{@required this.username,
@required this.imagePath,
@required this.imageSize,
this.title = ""});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
padding: EdgeInsets.only(top: 45),
alignment: Alignment(0, -1),
color: Colors.black12,
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.9,
width: mediaSize.width * 0.98,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
title,
style: TextStyle(
fontSize: 20.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, false);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 5, 20, 10),
width: double.infinity,
height: mediaSize.height * 0.1,
child: SingleChildScrollView(
child: RichText(
text: TextSpan(children: [
TextSpan(
text: '是否确定为用户 ', style: TextStyle(fontSize: 18.0, color: Colors.blue)),
TextSpan(
text: username,
style: TextStyle(
fontSize: 18.0, fontWeight: FontWeight.bold, color: Colors.red)),
TextSpan(
text: ' 注册或更新以下人脸图片?',
style: TextStyle(fontSize: 18.0, color: Colors.blue)),
]),
),
),
),
//SizedBox(height: 10),
//480*720
Text('宽高:${imageSize.width}x${imageSize.height}', style: TextStyle(fontSize: 18)),
SizedBox(height: 5),
SingleChildScrollView(
//滑动的方向 Axis.vertical为垂直方向滑动,Axis.horizontal 为水平方向
scrollDirection: Axis.vertical,
reverse: false,
padding: EdgeInsets.all(0.0),
//滑动到底部回弹效果
physics: BouncingScrollPhysics(),
child: Container(
alignment: Alignment(0, 0),
height: mediaSize.height * 0.52,
width: mediaSize.width * 0.95,
decoration: BoxDecoration(
border: Border.all(color: Colors.orange, width: 1.0),
borderRadius: BorderRadius.circular(5),
),
//DragScaleContainer 插件只能放大,不能缩小到比原始尺寸小
child: DragScaleContainer(
doubleTapStillScale: true,
child: Image.file(File(imagePath), fit: BoxFit.fitHeight)),
),
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: () async {
Navigator.pop(context, true); //关闭弹框,返回 true
},
child: Text("确认"),
),
RaisedButton(
child: Text("取消"),
onPressed: () async {
Navigator.pop(context, false); //关闭弹框,返回 false
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
Navigator.pop(context, false);
},
);
}
}
+323
View File
@@ -0,0 +1,323 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
import '../res/listContacts.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'doJSON.dart';
import 'hyxx_data_handle.dart';
import 'dart:convert';
import '../pages/MyMsics/03_personal/ContactModify.dart';
import '../pages/MyMsics/03_personal/ContactAdd.dart';
//删除消息对话框。自定义透明背景窗口,类似对话框
class customDialogG extends StatefulWidget {
customDialogG({Key key, this.title = "", this.index = -1}) : super(key: key);
String title;
int index;
_CheckBoxDemoState createState() => _CheckBoxDemoState();
}
class _CheckBoxDemoState extends State<customDialogG> {
String getTitle(int index) {
// return listContacts2[index]["姓名"] +
// ', ' +
// listContacts2[index]["部门"] +
// ', ' +
// listContacts2[index]["职务"] +
// '\n' +
// listContacts2[index]["手机"] +
// ', ' +
// listContacts2[index]["邮箱"];
}
@override
void initState() {
// TODO: implement initState
super.initState();
bFlash = false;
getContent();
}
String strContent = '';
getContent() async {
if (0 == widget.title.compareTo('收到的消息')) {
strContent = "第 ${widget.index + 1} 条(共 ${listMessagesInbox2.length} 条)" +
"\n" +
"时间:" +
listMessagesInbox2[widget.index]['date'] +
", " +
listMessagesInbox2[widget.index]['time'] +
"\n\n" +
"内容:" +
listMessagesInbox2[widget.index]['content'];
} else if (0 == widget.title.compareTo('发送的消息')) {
strContent = "第 ${widget.index + 1} 条(共 ${listMessagesOutbox2.length} 条)" +
"\n" +
"时间:" +
listMessagesOutbox2[widget.index]['date'] +
", " +
listMessagesOutbox2[widget.index]['time'] +
"\n\n" +
"内容:" +
listMessagesOutbox2[widget.index]['content'];
}
setState(() {});
}
bool flagSelect = false;
bool flagInbox = false;
bool flagOutbox = false;
Widget getCheckBoxs() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(children: <Widget>[
SizedBox(width: 10),
Checkbox(
value: flagInbox || flagOutbox ? false : flagSelect,
onChanged: flagInbox || flagOutbox
? null
: (v) {
setState(() {
flagSelect = v;
});
},
),
Text('删除当前选择的消息'),
]),
Row(children: <Widget>[
SizedBox(width: 10),
Checkbox(
value: flagInbox,
onChanged: (v) {
setState(() {
flagInbox = v;
});
},
),
Text('删除所有收到的消息'),
]),
Row(children: <Widget>[
SizedBox(width: 10),
Checkbox(
value: flagOutbox,
onChanged: (v) {
setState(() {
flagOutbox = v;
});
},
),
Text('删除所有发送的消息'),
]),
],
);
}
Widget getBtnSizeX({@required text, width = 60.0, height = 30.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,
),
);
}
Future<bool> alertDialog(String title, String content, var onPresse) async {
return await showDialog(
barrierDismissible: false, //表示点击灰色背景的时候是否消失弹出框
context: context,
builder: (context) {
return AlertDialog(
title: Text(title),
content: Text(content),
actions: <Widget>[
FlatButton(
child: Text("确定"),
onPressed: onPresse,
),
FlatButton(
child: Text("取消"),
onPressed: () {
Navigator.pop(context, false);
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
Size mediaSize = MediaQuery.of(context).size;
myController.text = getTitle(widget.index);
// TODO: implement build
return WillPopScope(
child: Scaffold(
//type: MaterialType.transparency,
//color: Colors.transparent,
//backgroundColor: Colors.transparent,
//color: Colors.blue,
backgroundColor: Color.fromRGBO(212, 212, 212, 0.6),
body: SafeArea(
child: Stack(
children: <Widget>[
Container(
alignment: Alignment(0, -0.4),
child: Container(
height: mediaSize.height * 0.7,
width: mediaSize.width * 0.95,
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(width: 1.0, color: Colors.black),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${widget.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
//Navigator.pop(context, index);
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
)
],
),
),
Divider(),
// Container(
// padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
// width: double.infinity,
// child: SingleChildScrollView(
// child: Container(
// child: Text(strContent),
// ),
// ),
// ),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(width: 1.0, color: Colors.blue),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
height: mediaSize.height * 0.2,
child: SingleChildScrollView(
child: Container(
child: Text(strContent),
),
),
),
),
SizedBox(height: 10),
getCheckBoxs(),
SizedBox(height: 10),
Expanded(
child: Container(),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "删除",
onPressedFun: () async {
// listContacts2.removeAt(widget.index);
// bFlash = true;
// print("ContactDel bFlash = $bFlash");
// writeJSON(json.encode(listContacts2), 'listContacts2.json');
bool ret = await alertDialog('删除确认', '是否确定要删除选中的项目?', () {
print("flagInbox = $flagInbox");
print("flagOutbox = $flagOutbox");
print("flagSelect = $flagSelect");
if (flagInbox || flagOutbox) {
bFlash = true;
if (flagInbox) {
listMessagesInbox2.clear();
writeJSON(json.encode(listMessagesInbox2),
'listMessagesInbox02.json');
}
if (flagOutbox) {
listMessagesOutbox2.clear();
writeJSON(json.encode(listMessagesOutbox2),
'listMessagesOutbox02.json');
}
} else if (flagSelect) {
bFlash = true;
if (0 == widget.title.compareTo('收到的消息')) {
listMessagesInbox2.removeAt(widget.index);
writeJSON(json.encode(listMessagesInbox2),
'listMessagesInbox02.json');
} else if (0 == widget.title.compareTo('发送的消息')) {
listMessagesOutbox2.removeAt(widget.index);
writeJSON(json.encode(listMessagesOutbox2),
'listMessagesOutbox02.json');
}
}
print("bFlash = $bFlash");
Navigator.pop(context, true);
});
if (ret) {
Navigator.pop(context); //关闭弹框,播放输入视频地址
}
},
),
getBtnSizeX(
text: "取消",
onPressedFun: () {
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
],
),
SizedBox(height: 50),
],
),
),
),
],
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context);
},
);
}
}
+160
View File
@@ -0,0 +1,160 @@
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:dio/dio.dart';
import '../config/service_url.dart';
//拍照、选择相册图片对话框
class customDialogH extends Dialog {
String title;
String content;
int index;
customDialogH({this.title = "", this.content = "", this.index = -1});
Widget getBtnSizeX({@required text, width = 60.0, height = 30.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,
),
);
}
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
// TODO: implement build
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
alignment: Alignment(0, -0.7),
child: Container(
height: mediaSize.height * 0.25,
width: mediaSize.width * 0.95,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(2),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${this.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
)
],
),
),
Divider(),
SizedBox(height: 35),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "拍照",
onPressedFun: () async {
await _takePhoto();
await Navigator.pop(context, _imagePath); //先关闭“选择操作”对话框
},
),
getBtnSizeX(
text: "从相册选择",
width: 110.0,
onPressedFun: () async {
await _openGallery();
await Navigator.pop(context, _imagePath); //先关闭“选择操作”对话框
},
),
getBtnSizeX(
text: "取消",
onPressedFun: () {
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
// player.pause();
Navigator.pop(context);
},
);
}
File _image;
String _imagePath = '';
final picker = ImagePicker();
/*拍照*/
_takePhoto() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
if (pickedFile != null) {
_image = File(pickedFile.path);
_imagePath = pickedFile.path;
this._uploadImage(_image);
} else {
print('No image selected.');
}
}
/*相册*/
_openGallery() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
if (pickedFile != null) {
_image = File(pickedFile.path);
_imagePath = pickedFile.path;
this._uploadImage(_image);
} else {
print('No image selected.');
}
}
//上传图片
_uploadImage(File _imageDir) async {
//注意:dio3.x版本为了兼容web做了一些修改,上传图片的时候需要把File类型转换成String类型,具体代码如下
var fileDir = _imageDir.path;
FormData formData = FormData.fromMap({
"name": "zhangsna 6666666666",
"age": 20,
"sex": "男",
"file": await MultipartFile.fromFile(fileDir, filename: "xxx.jpg")
});
//var response = await Dio().post(ServicePath.uploadImageUrl, data: fileDir);
var response = await Dio().post(ServiceUrlJd, data: fileDir);
print(response);
}
}
+119
View File
@@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import 'package:hyzp_ybqx/components/dioFun.dart';
import 'commonFun.dart';
//确认对话框
class CustomDialogHysh extends Dialog {
String title;
String content;
String shjg; //审核结果
bool ret = false;
CustomDialogHysh({@required this.shjg, this.title = "", this.content});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
padding: EdgeInsets.only(top: 122),
alignment: Alignment(0, -1),
color: Colors.black12,
child: Container(
// height: 260,
// width: 300,
height: mediaSize.height * 0.35,
width: mediaSize.width * 0.98,
//color: Colors.white, //Cannot provide both a color and a decoration
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Text(
"${title}确认",
style: TextStyle(
fontSize: 20.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context, ret);
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 5, 20, 10),
width: double.infinity,
height: mediaSize.height * 0.15,
child: SingleChildScrollView(
child: RichText(
text: TextSpan(children: [
TextSpan(
text: '${title}为 ',
style: TextStyle(fontSize: 18.0, color: Colors.blue)),
TextSpan(
text: shjg,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: shjg == hyc_text ? Colors.red : Colors.green)),
TextSpan(
text: ',' + content,
style: TextStyle(fontSize: 18.0, color: Colors.blue)),
]),
),
),
),
SizedBox(height: 0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
onPressed: () async {
ret = true;
Navigator.pop(context, ret); //关闭弹框,返回sRet
},
child: Text("确认"),
),
RaisedButton(
child: Text("取消"),
onPressed: () async {
Navigator.pop(context, ret); //关闭弹框,返回sRet
},
)
],
),
],
),
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
Navigator.pop(context, ret);
},
);
}
}
+340
View File
@@ -0,0 +1,340 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../pages/Works/SBBJ/sbbj_content.dart';
import 'doJSON.dart';
//删除消息对话框。自定义透明背景窗口,类似对话框
class CustomDialogJ extends StatefulWidget {
CustomDialogJ({Key key, this.title = "", this.theKey = "", this.index = -1}) : super(key: key);
String title;
String theKey;
int index;
_CheckBoxDemoState createState() => _CheckBoxDemoState();
}
//需要监听软键盘的弹出和隐藏 主要用 WidgetsBindingObserver 这个继承类
//https://www.jianshu.com/p/872e23124470
class _CheckBoxDemoState extends State<CustomDialogJ> with WidgetsBindingObserver {
String getTitle(int index) {}
int mapLen = 0;
@override
void dispose() {
// TODO: implement dispose
//销毁
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void initState() {
// TODO: implement initState
super.initState();
//mapLen = mapGetSbbjGetData.length;
print("mapLen = $mapLen");
getContent();
//初始化
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeMetrics() {
super.didChangeMetrics();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
if (MediaQuery.of(context).viewInsets.bottom == 0) {
//关闭键盘
bViewInsets = false;
} else {
//显示键盘
bViewInsets = true;
}
});
});
}
String strContent = '';
bool bModifiable = false;
bool bViewInsets = false;
getContent() async {
// strContent = ("" == mapGetSbbjGetData[widget.theKey].toString())
// ? "(无数据)"
// : mapGetSbbjGetData[widget.theKey].toString();
// widget.title =
// "第 ${widget.index + 1} 项(共 ${mapLen} 项) : " + mapGetSbbjGetDataText[widget.theKey];
getPreBtn_NextBtn();
//时间戳转换
if(strContent.isNotEmpty && ('addtime' == widget.theKey || 'createtime' == widget.theKey)) {
strContent = getDate(int.parse(strContent));
}
myController.text = strContent;
bModifiable = false;//mapGetSbbjGetDataModifiable[widget.thekey];
setState(() {});
}
Widget getBtnSizeX({@required text, width = 60.0, height = 30.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,
),
);
}
Future<bool> alertDialog(String title, String content, var onPresse) async {
return await showDialog(
barrierDismissible: false, //表示点击灰色背景的时候是否消失弹出框
context: context,
builder: (context) {
return AlertDialog(
title: Text(title),
content: Text(content),
actions: <Widget>[
FlatButton(
child: Text("确定"),
onPressed: onPresse,
),
FlatButton(
child: Text("取消"),
onPressed: () {
Navigator.pop(context, false);
},
),
],
);
},
);
}
//解决第一次进入报错问题。因为getPreBtn_NextBtn()还未执行,preBtn和nextBtn为空
Widget preBtn = Container(
color: Colors.white12, //onPressedFun为null时无效
width: 60.0,
height: 30.0,
child: RaisedButton(
padding: EdgeInsets.all(0),
textColor: Colors.black,
child: Text('上一项'),
onPressed: null,
),
);
Widget nextBtn = Container(
color: Colors.white12, //onPressedFun为null时无效
width: 60.0,
height: 30.0,
child: RaisedButton(
padding: EdgeInsets.all(0),
textColor: Colors.black,
child: Text('下一项'),
onPressed: null,
),
);
getPreBtn_NextBtn() {
preBtn = getBtnSizeX(
text: "上一项",
onPressedFun: null,
);
nextBtn = getBtnSizeX(
text: "下一项",
onPressedFun: null,
);
if (widget.index > 0 && mapLen > 0) {
preBtn = getBtnSizeX(
text: "上一项",
onPressedFun: () async {
if (widget.index > 0) {
widget.index--;
//widget.theKey = mapGetSbbjGetData.keys.elementAt(widget.index);
getContent();
}
},
);
}
if (widget.index < (mapLen - 1) && mapLen > 0) {
nextBtn = getBtnSizeX(
text: "下一项",
onPressedFun: () async {
if (widget.index < mapLen - 1) {
widget.index++;
//widget.theKey = mapGetSbbjGetData.keys.elementAt(widget.index);
getContent();
}
},
);
}
}
@override
Widget build(BuildContext context) {
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
Size mediaSize = MediaQuery.of(context).size;
// TODO: implement build
return WillPopScope(
child: Scaffold(
//type: MaterialType.transparency,
//color: Colors.transparent,
//backgroundColor: Colors.transparent,
//color: Colors.blue,
backgroundColor: Color.fromRGBO(212, 212, 212, 0.6),
body: SafeArea(
child: Stack(
children: <Widget>[
Container(
alignment: Alignment(0, 0.2),
child: Container(
height: bViewInsets ? mediaSize.height * 0.4 : mediaSize.height * 0.85,
width: mediaSize.width * 0.95,
decoration: BoxDecoration(
color: Colors.white,
//border: Border.all(width: 1.0, color: Colors.black),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
" ${widget.title}",
style: TextStyle(
fontSize: 15.0,
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
)
],
),
),
Divider(),
Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(width: 1.0, color: Colors.blue),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
width: double.infinity,
height: mediaSize.height * 0.15,
child: SingleChildScrollView(
child: Container(
child: TextField(
//textAlign: TextAlign.right,
keyboardType: TextInputType.multiline,
maxLines: 5,
minLines: 1,
style: TextStyle(fontSize: 14),
decoration: InputDecoration(
hintText: '請輸入字段信息',
border: InputBorder.none, //TextField去掉下划线
contentPadding: EdgeInsets.only(right: 0),
),
controller: myController,
enabled: bModifiable,
//利用控制器初始化文本
onChanged: (value) {},
),
),
),
),
),
SizedBox(height: 5),
bViewInsets
? SizedBox(height: 0)
: Container(
padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
width: double.infinity,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(width: 1.0, color: Colors.blue),
borderRadius: BorderRadius.all(
Radius.circular(3),
),
),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
width: double.infinity,
height: mediaSize.height * 0.45,
child: SingleChildScrollView(
child: Container(
//child: Text(strContent),
child: Text(strContent),
),
),
),
),
Expanded(
child: Container(),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
getBtnSizeX(
text: "复制",
onPressedFun: () {
// Flutter 复制文本到剪贴板
Clipboard.setData(ClipboardData(text: strContent));
//showToast('帮助信息已复制到剪贴板', textAlign: TextAlign.left);
Fluttertoast.showToast(
msg: '联系人信息已复制到剪贴板', gravity: ToastGravity.BOTTOM);
},
),
getBtnSizeX(
text: "返回",
onPressedFun: () {
Navigator.pop(context); //关闭弹框,播放输入视频地址
},
),
preBtn,
nextBtn,
],
),
SizedBox(height: 35),
],
),
),
),
],
),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
//player.pause();
Navigator.pop(context);
},
);
}
}
+27
View File
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'commonFun.dart';
//等待对话框
class CustomDialogWait extends Dialog {
String title;
bool ret = false;
CustomDialogWait({this.title = ""});
@override
Widget build(BuildContext context) {
Size mediaSize = MediaQuery.of(context).size;
return WillPopScope(
child: Material(
type: MaterialType.transparency,
child: Container(
child: getMoreWidget(text: title),
),
),
onWillPop: () {
// 屏蔽点击返回键的操作
Navigator.pop(context, ret);
},
);
}
}
+44
View File
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
//自定义图标按钮组件,顶部工具栏用
class MyIcontButton extends StatelessWidget {
var pressed;
double width;
double height;
double iconSize;
Color color;
Color iconColor;
double radius;
IconData icon;
MyIcontButton({
this.width = 30,
this.height = 30,
this.iconSize = 20,
this.color = Colors.blue,
this.iconColor = Colors.white,
this.radius = 0,
this.icon = Icons.message,
this.pressed = null,
});
@override
Widget build(BuildContext context) {
return Container(
height: this.height,
width: this.width,
decoration: BoxDecoration(
color: this.color,
border: Border.all(color: Colors.blue, width: 1.0),
borderRadius: BorderRadius.all(
Radius.circular(radius),
)),
child: IconButton(
color: Colors.white,
padding: EdgeInsets.all(0),
iconSize: this.iconSize,
icon: Icon(this.icon),
onPressed: this.pressed,
),
);
}
}
File diff suppressed because it is too large Load Diff
+178
View File
@@ -0,0 +1,178 @@
//JSON数据写入文件、从文件中读取
import 'dart:convert';
import 'dart:io';
import 'package:intl/intl.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
//控制字段处理数据类
class ItemData {
ItemData({
this.fieldName,
this.fieldText,
this.fieldVisible,
this.fieldModifiable,
this.fieldUrlVisible,
}) {}
String fieldName = '';
String fieldText = '';
bool fieldVisible = true;
bool fieldUrlVisible = true;
bool fieldModifiable = true;
}
//ftpdir 字符串 必须 上传目录,为checkid记录的抓拍时间,格式为4位年+2位月+2位日,如:20210208
//timeStamp可以是int类型或String类型的时间戳(秒)
String getFtpdir_YYYYMMDD(var timeStamp, {String sep = ''}) {
int timeStampSecond;
if (timeStamp is String) {
timeStampSecond = int.parse(timeStamp);
} else {
timeStampSecond = timeStamp;
}
//将拿到的时间戳转化为日期
DateTime _dateTime = DateTime.fromMillisecondsSinceEpoch(timeStampSecond * 1000, isUtc: true);
print('_dateTime = $_dateTime');
//_dateTime_now = 2021-02-08 20:31:31.235300
print('formattedDateYYYY_MM_DD_KK_MM = ${DateFormat('yyyy-MM-dd – kk:mm').format(_dateTime)}');
//formattedDateYYYY_MM_DD_KK_MM = 2021-01-31 – 06:49
String formattedDateYYYYMMDD = DateFormat('yyyy${sep}MM${sep}dd').format(_dateTime);
print('formattedDateYYYYMMDD = ${formattedDateYYYYMMDD}');
//formattedDateYYYYMMDD = 20210131
return formattedDateYYYYMMDD;
}
// 获得前 31 天的日期起点和终点:['2021-03-18', '2021-04-17']
List getLast31DateString() {
var _nowTime = DateTime.now();
String _nowDate_YYYY_MM_DD = DateFormat('yyyy-MM-dd').format(_nowTime);
//print('_nowDate_YYYY_MM_DD = ${_nowDate_YYYY_MM_DD}');
var _startTime = _nowTime.add(new Duration(days: -31));
String _startDate_YYYY_MM_DD = DateFormat('yyyy-MM-dd').format(_startTime);
print('_startDate_YYYY_MM_DD = ${_startDate_YYYY_MM_DD}');
var _endTime = _nowTime.add(new Duration(days: -1));
String _endDate_YYYY_MM_DD = DateFormat('yyyy-MM-dd').format(_endTime);
print('_endDate_YYYY_MM_DD = ${_endDate_YYYY_MM_DD}');
return [_startDate_YYYY_MM_DD, _endDate_YYYY_MM_DD];
}
///获取昨天的结束时间的秒时间戳
int getEndDayOfYesterdayStamp() {
var nowTime = DateTime.now();
var yesterday = nowTime.add(new Duration(days: -1));
var day = new DateTime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59);
//return day.microsecondsSinceEpoch; //微妙时间戳
//return day.millisecondsSinceEpoch; //毫秒时间戳
return day.millisecondsSinceEpoch ~/ 1000; //秒时间戳,加 ~ 为取整
}
///判断字符串时间是否是今日时间
bool isToday(String strTime) {
//5.字符串转DateTime,DateTime.parse('2019-11-08') 或者 DateTime.parse('2019-11-08 12:30:05')
DateTime _dateTime = DateTime.parse(strTime);
//return day.microsecondsSinceEpoch; //微妙时间戳
//return day.millisecondsSinceEpoch; //毫秒时间戳
int _secondTiem = _dateTime.millisecondsSinceEpoch ~/ 1000; //秒时间戳,加 ~ 为取整
return _secondTiem > getEndDayOfYesterdayStamp();
}
///从字符串时间获取秒时间戳
int getStampFromString(String strTime) {
//5.字符串转DateTime,DateTime.parse('2019-11-08') 或者 DateTime.parse('2019-11-08 12:30:05')
var _dateTime = DateTime.parse(strTime);
//return day.microsecondsSinceEpoch; //微妙时间戳
//return day.millisecondsSinceEpoch; //毫秒时间戳
return _dateTime.millisecondsSinceEpoch ~/ 1000; //秒时间戳,加 ~ 为取整
}
///获取字符串时间 Ntime (HH:MM)中时间的秒数
int getSecondsOfNtime(String Ntime) {
List list = Ntime.split(':');
int seconds = (int.parse(list[0]) * 60 + int.parse(list[1])) * 60;
return seconds; //秒时间戳,加 ~ 为取整
}
//mantissa尾数
String getDate(var timeStamp, {bool mantissa = false}) {
//String getDate(int timeStamp, {bool mantissa = false}) {
if (timeStamp == null) {
return "null";
}
if (timeStamp is String) {
return timeStamp;
}
//接口获得的时间戳是以秒为单位的
//flutter 时间戳转换 差8小时。可能是因为默认时区的问题,导致并不是北京时间。(我猜的。。。)
// 【解决办法】 // 在utc上直接加上8小时(28800秒)。
//var strtime = DateTime.fromMillisecondsSinceEpoch((timeStamp + 28800) * 1000); //将拿到的时间戳转化为日期
//Android Studio ADV默认是Use network-provided time zone,时区是GTM+00:00
//需要指定时区为China-Shanghai,China Time(GMT+08:00)
var strtime = DateTime.fromMillisecondsSinceEpoch(timeStamp * 1000, isUtc: true); //将拿到的时间戳转化为日期
String date = strtime.toLocal().toString();
//print('date = $date');
if (!mantissa) {
//去除末尾小数
date = date.substring(0, date.lastIndexOf('.'));
}
//print('date = $date'); //date = 2021-05-29 13:52:40
return date;
}
writeJSON(String jsonContent, String fileName) async {
File file = await getTheFile(fileName);
await file.writeAsString(jsonEncode(jsonContent));
}
Future<String> readJSON(String fileName) async {
return jsonDecode(await (await getTheFile(fileName)).readAsString());
}
Future<File> getTheFile(String fileName) async {
String strExt = path.extension(fileName).toLowerCase().trim();
if (0 != strExt.compareTo('.json')) {
fileName += '.json';
}
//在指定位置创建"json"目录
//final dirPath = await getExternalStorageDirectory();
final dirPath = await getApplicationDocumentsDirectory();
var dirJson = Directory(dirPath.path + "/" + "json");
try {
bool exists = await dirJson.exists();
if (!exists) {
await dirJson.create();
}
} catch (e) {
print(e);
}
// /data/data/com.flutter.hyzp_ybqx/app_flutter/json/listMessagesInbox02.json
// /data/data/com.flutter.hyzp_ybqx/app_flutter/json/listContacts02.json
return File('${(await getApplicationDocumentsDirectory()).path}/json/$fileName');
}
//以下为测试学习之用
// Future<File> get getFile async {
// File('${(await getApplicationDocumentsDirectory()).path}/json/listContacts.json');
// }
// writeJSON(String jsonContent) async {
// //You can write data like this:
// //await (await getFile).writeAsString(jsonEncode(jsonContent));
// //该句等同于
// File file = await getFile;
// await file.writeAsString(jsonEncode(jsonContent));
// }
//
// readJSON() async {
// //从文件中读取,下次您可能想读取更改的数据。你可以这样做:
// String decodedContent = jsonDecode(await (await getFile).readAsString());
// }
File diff suppressed because it is too large Load Diff
+34
View File
@@ -0,0 +1,34 @@
import 'dart:io';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
class StorageDataToFile {
static Future<String> get _localPath async {
final _path = await getTemporaryDirectory();
return _path.path;
}
static Future<File> get _localFile async {
final path = await _localPath;
return File('$path/counter.txt');
}
static Future<int> readCounter() async {
try {
final file = await _localFile;
var contents = await file.readAsString();
return int.parse(contents);
} catch (e) {
return 0;
}
}
static Future<File> writeCounter(counter) async {
final file = await _localFile;
return file.writeAsString('$counter');
}
}