diff --git a/lib/util/color.dart b/lib/util/color.dart index 7f5fa4b..de1b3cf 100644 --- a/lib/util/color.dart +++ b/lib/util/color.dart @@ -10,13 +10,21 @@ import 'dart:ui'; import 'dart:math'; +import 'package:flutter/material.dart'; +import 'package:zhiying_comm/util/log/let_log.dart'; + extension HexColor on Color { /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#". static Color fromHex(String hexString) { - final buffer = StringBuffer(); - if (hexString.length == 6 || hexString.length == 7) buffer.write('ff'); - buffer.write(hexString.replaceFirst('#', '')); - return Color(int.parse(buffer.toString(), radix: 16)); + try{ + final buffer = StringBuffer(); + if (hexString.length == 6 || hexString.length == 7) buffer.write('ff'); + buffer.write(hexString.replaceFirst('#', '')); + return Color(int.parse(buffer.toString(), radix: 16)); + }catch(e){ + Logger.log(e); + } + return Colors.white; } static Color random() { diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index fa9401e..d4af294 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -46,7 +46,7 @@ class NetUtil { if (_dio == null) { var setting = await NativeUtil.getSetting(); String domain = setting['domain']; //'http://www.hairuyi.com/'; -// _config(domain, proxyUrl: '192.168.0.66:8866'); + _config(domain, proxyUrl: '192.168.0.66:8866'); } return _dio; } @@ -86,12 +86,12 @@ class NetUtil { /// 同步请求 static Future post(String path, - {Map params, NetMethod method = NetMethod.POST}) async { + {Map params, NetMethod method = NetMethod.POST, bool cache = true}) async { if (params == null) { params = {}; } // 根据请求参数,获取缓存的Key - String cacheKey = _getRequestParamsCachedKey(params, path); + String cacheKey = getRequestParamsCachedKey(params, path); // 参数签名 TODO 加密? Map sign = await signParams(params); @@ -108,7 +108,9 @@ class NetUtil { // TODO 解密? if (isSuccess(result)) { // 缓存成功的数据 - _setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data); + if(cache) { + _setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data); + } return result; // 缓存返回的数据 } @@ -134,7 +136,7 @@ class NetUtil { } // 根据请求参数,获取缓存的Key - String cacheKey = _getRequestParamsCachedKey(params, path); + String cacheKey = getRequestParamsCachedKey(params, path); // // 读取缓存回调 if (onCache != null) { await _onCallBackCacheData(onCache, cacheKey); @@ -226,9 +228,7 @@ class NetUtil { // 站长ID String masterId = setting['master_id']; - if (null != null && - masterId != '' && - (!params.containsKey('master_id') || params['master_id'] == '')) { + if (null != masterId && masterId != '' && (!params.containsKey('master_id') || params['master_id'] == '')) { params['master_id'] = masterId; } @@ -289,7 +289,7 @@ class NetUtil { /// 根据请求参数,获取缓存的数据 static Future getRequestCachedData(String url, {Map params}) async{ - Map cacheMap = await SharedPreferencesUtil.getNetCacheResult(_getRequestParamsCachedKey(params, url)); + Map cacheMap = await SharedPreferencesUtil.getNetCacheResult(getRequestParamsCachedKey(params, url)); if (!EmptyUtil.isEmpty(cacheMap) && cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) && (cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] == @@ -318,7 +318,7 @@ class NetUtil { } /// 根据请求参数,获取缓存的Key - static String _getRequestParamsCachedKey( + static String getRequestParamsCachedKey( Map map, String path) { if (EmptyUtil.isEmpty(map)) { return EncodeUtil.generateMd5(path);