|
|
@ -8,10 +8,11 @@ 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)}"; |
|
|
|
} |
|
|
|
} |
|
|
@ -21,12 +22,14 @@ class AppUtils { |
|
|
|
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) { |
|
|
@ -58,8 +61,7 @@ class AppUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -196,28 +198,34 @@ 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)}..."; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|