|
|
@ -8,36 +8,39 @@ import 'package:intl/intl.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class AppUtils { |
|
|
|
class AppUtils { |
|
|
|
|
|
|
|
|
|
|
|
///计算距离(当前位置到店位置直线距离) |
|
|
|
///计算距离(当前位置到店位置直线距离) |
|
|
|
static Future<String> calculateDistance(BMFCoordinate bmfCoordinate, BMFCoordinate myLatLng) async { |
|
|
|
static Future<String> calculateDistance( |
|
|
|
double mi = await BMFCalculateUtils.getLocationDistance(bmfCoordinate, myLatLng); |
|
|
|
BMFCoordinate bmfCoordinate, BMFCoordinate myLatLng) async { |
|
|
|
|
|
|
|
double mi = |
|
|
|
|
|
|
|
await BMFCalculateUtils.getLocationDistance(bmfCoordinate, myLatLng); |
|
|
|
NumberFormat numberFormat = NumberFormat("#.#"); |
|
|
|
NumberFormat numberFormat = NumberFormat("#.#"); |
|
|
|
return "${numberFormat.format(mi / 1000)}"; |
|
|
|
return "${numberFormat.format(mi / 1000)}"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///版本号 |
|
|
|
///版本号 |
|
|
|
static bool versionCompare(String localVersion,String serverVersion){ |
|
|
|
static bool versionCompare(String localVersion, String serverVersion) { |
|
|
|
try{ |
|
|
|
try { |
|
|
|
var localVersionArr = localVersion.split("."); |
|
|
|
var localVersionArr = localVersion.split("."); |
|
|
|
var serverVersionArr = serverVersion.split("."); |
|
|
|
var serverVersionArr = serverVersion.split("."); |
|
|
|
if((int.tryParse(localVersionArr[0]) < int.tryParse(serverVersionArr[0])) |
|
|
|
if (int.tryParse(localVersionArr[0]) > int.tryParse(serverVersionArr[0])) |
|
|
|
|| (int.tryParse(localVersionArr[1]) < int.tryParse(serverVersionArr[1])) |
|
|
|
return false; |
|
|
|
|| (int.tryParse(localVersionArr[2]) < int.tryParse(serverVersionArr[2]))) |
|
|
|
if (int.tryParse(localVersionArr[1]) > int.tryParse(serverVersionArr[1])) |
|
|
|
return true; |
|
|
|
|
|
|
|
}catch(ex){ } |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
if (int.tryParse(localVersionArr[2]) > int.tryParse(serverVersionArr[2])) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} catch (ex) {} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static String trimEnd(String resString,String char){ |
|
|
|
static String trimEnd(String resString, String char) { |
|
|
|
while(resString.endsWith(char)){ |
|
|
|
while (resString.endsWith(char)) { |
|
|
|
resString = resString.substring(0,resString.length - 1); |
|
|
|
resString = resString.substring(0, resString.length - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
return resString; |
|
|
|
return resString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///金额保留整数/后两位 |
|
|
|
///金额保留整数/后两位 |
|
|
|
static String calculateDouble(double res){ |
|
|
|
static String calculateDouble(double res) { |
|
|
|
String resString = res.toStringAsFixed(2); |
|
|
|
String resString = res.toStringAsFixed(2); |
|
|
|
resString = trimEnd(resString, "0"); |
|
|
|
resString = trimEnd(resString, "0"); |
|
|
|
resString = trimEnd(resString, "."); |
|
|
|
resString = trimEnd(resString, "."); |
|
|
@ -57,10 +60,9 @@ class AppUtils { |
|
|
|
return exp.hasMatch(mobile); |
|
|
|
return exp.hasMatch(mobile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static String phoneEncode(String phone){ |
|
|
|
static String phoneEncode(String phone) { |
|
|
|
if(phone == null || phone.length != 11) |
|
|
|
if (phone == null || phone.length != 11) return phone; |
|
|
|
return phone; |
|
|
|
return phone.substring(0, 3) + "****" + phone.substring(phone.length - 4); |
|
|
|
return phone.substring(0,3) + "****" + phone.substring(phone.length-4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static double textScale(context) { |
|
|
|
static double textScale(context) { |
|
|
@ -193,31 +195,37 @@ class AppUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static String dioErrorTypeToString(DioErrorType type){ |
|
|
|
static String dioErrorTypeToString(DioErrorType type) { |
|
|
|
String errorStr = ""; |
|
|
|
String errorStr = ""; |
|
|
|
switch(type){ |
|
|
|
switch (type) { |
|
|
|
case DioErrorType.CANCEL:{ |
|
|
|
case DioErrorType.CANCEL: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "取消请求"; |
|
|
|
errorStr = "取消请求"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case DioErrorType.CONNECT_TIMEOUT:{ |
|
|
|
case DioErrorType.CONNECT_TIMEOUT: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "链接超时"; |
|
|
|
errorStr = "链接超时"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case DioErrorType.RECEIVE_TIMEOUT:{ |
|
|
|
case DioErrorType.RECEIVE_TIMEOUT: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "响应超时"; |
|
|
|
errorStr = "响应超时"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case DioErrorType.SEND_TIMEOUT:{ |
|
|
|
case DioErrorType.SEND_TIMEOUT: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "请求超时"; |
|
|
|
errorStr = "请求超时"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case DioErrorType.RESPONSE:{ |
|
|
|
case DioErrorType.RESPONSE: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "服务器异常"; |
|
|
|
errorStr = "服务器异常"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case DioErrorType.DEFAULT: |
|
|
|
case DioErrorType.DEFAULT: |
|
|
|
default:{ |
|
|
|
default: |
|
|
|
|
|
|
|
{ |
|
|
|
errorStr = "请求异常"; |
|
|
|
errorStr = "请求异常"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -228,8 +236,7 @@ class AppUtils { |
|
|
|
|
|
|
|
|
|
|
|
static String textSubStr(String input, int length) { |
|
|
|
static String textSubStr(String input, int length) { |
|
|
|
length -= 1; |
|
|
|
length -= 1; |
|
|
|
if(length < 0 || input.length < length) |
|
|
|
if (length < 0 || input.length < length) return input; |
|
|
|
return input; |
|
|
|
return "${input.substring(0, length)}..."; |
|
|
|
return "${input.substring(0,length)}..."; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|