134 lines
3.0 KiB
Dart
Executable File
134 lines
3.0 KiB
Dart
Executable File
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/mine/about/debug/debug_console.dart';
|
|
|
|
class AppLog {
|
|
static bool _printLog = true;
|
|
static bool _onlyError = false;
|
|
|
|
static void showLog({required bool printLog, bool? onlyError}) {
|
|
_printLog = printLog;
|
|
_onlyError = onlyError ?? false;
|
|
}
|
|
|
|
static void log(String msg, {StackTrace? stackTrace, bool? error}) {
|
|
msg = '${DateTime.now().toIso8601String()} : $msg';
|
|
DebugConsole.info(msg, stackTrace: stackTrace, isErr: error ?? false);
|
|
if (!kDebugMode) {
|
|
return;
|
|
}
|
|
error = error ?? false;
|
|
// if(!_printLog)return;
|
|
// if(_onlyError && !error) return;
|
|
if (error) {
|
|
final bool stackTraceIsNull = stackTrace != null;
|
|
msg = '----->>> $msg ${stackTraceIsNull ? '\n$stackTrace' : ''}';
|
|
}
|
|
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;
|
|
}
|
|
|
|
// 错误类型
|
|
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;
|
|
}
|
|
}
|