125 lines
2.7 KiB
Dart
125 lines
2.7 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:get/get.dart';
|
|
import 'dart:io';
|
|
|
|
import 'package:star_lock/mine/about/debug/debug_console.dart';
|
|
|
|
|
|
class AppLog {
|
|
static bool _printLog = false;
|
|
static bool _onlyError = false;
|
|
|
|
static showLog({required bool printLog, bool? onlyError}){
|
|
_printLog = printLog;
|
|
_onlyError = onlyError ?? false;
|
|
}
|
|
static log(String msg,{bool? error}){
|
|
DebugConsole.info(msg);
|
|
if(!kDebugMode)return;
|
|
error = error ?? false;
|
|
// if(!_printLog)return;
|
|
// if(_onlyError && !error) return;
|
|
if(error){
|
|
msg = '----->>> $msg';
|
|
}
|
|
Get.log(msg);
|
|
}
|
|
}
|
|
|
|
class AppPlatform {
|
|
static bool isIOS = Platform.isIOS;
|
|
static bool isAndroid = Platform.isAndroid;
|
|
static String platformString(){
|
|
String name = 'unknown';
|
|
if(isIOS){
|
|
name = 'iOS';
|
|
}
|
|
if(isAndroid){
|
|
name = 'Android';
|
|
}
|
|
return name;
|
|
}
|
|
|
|
static String _brand = 'unknown';
|
|
static int _sdkInt = 23;
|
|
|
|
static void setBrandString(String brand){
|
|
_brand = brand;
|
|
}
|
|
static String getBrandString()=>_brand;
|
|
static void setSDKInt(int sdkInt){
|
|
_sdkInt = sdkInt;
|
|
}
|
|
static bool isSamsung()=>_brand.toLowerCase().contains('samsung');
|
|
static int getSdkIntValue()=>_sdkInt;
|
|
static bool onlyCanNetUpgrade()=>isSamsung() && (getSdkIntValue() >= 29);
|
|
|
|
}
|
|
|
|
class AppMowerCodes {
|
|
static int idCodeLength(){
|
|
int len = 19;
|
|
return len;
|
|
}
|
|
static int fenceNameLength = 8;
|
|
static int registerCodeLength = 4;
|
|
}
|
|
|
|
class AppDate {
|
|
static String dateString() {
|
|
return '${year()}-${month().toString().padLeft(2,'0')}-${day().toString()
|
|
.padLeft(2,'0')}';
|
|
}
|
|
|
|
static String calendarString() {
|
|
String temp = '${year()}${month().toString().padLeft(2,'0')}${day().toString()
|
|
.padLeft(2,'0')}${hour().toString().padLeft(2,'0')}${second()
|
|
.toString().padLeft(2,'0')}';
|
|
return temp;
|
|
}
|
|
|
|
static int year()=>DateTime.now().year;
|
|
static int month()=>DateTime.now().month;
|
|
static int day()=>DateTime.now().day;
|
|
static int hour()=>DateTime.now().hour;
|
|
static int minute()=>DateTime.now().minute;
|
|
static int second()=>DateTime.now().second;
|
|
static int weekDay()=>DateTime.now().weekday;
|
|
static int timeZeroOffset()=>DateTime.now().timeZoneOffset.inHours;
|
|
|
|
}
|
|
|
|
//TODO:错误类型
|
|
enum ErrorType {
|
|
modeNotMatch,
|
|
notConnected,
|
|
mqttNotConnect,
|
|
timeOut,
|
|
}
|
|
|
|
class AppErrorCode {
|
|
static int errorCode(ErrorType type){
|
|
int code = 0;
|
|
switch(type){
|
|
case ErrorType.modeNotMatch:
|
|
code = 1;
|
|
break;
|
|
case ErrorType.notConnected:
|
|
code = 2;
|
|
break;
|
|
case ErrorType.mqttNotConnect:
|
|
code = 3;
|
|
break;
|
|
case ErrorType.timeOut:
|
|
code = 4;
|
|
break;
|
|
}
|
|
return code;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|