This commit is contained in:
2023-12-22 01:36:07 +08:00
commit 1414bd4bb4
77 changed files with 2327 additions and 0 deletions

8
lib/utils/logger.dart Normal file
View File

@@ -0,0 +1,8 @@
import 'package:flutter/material.dart';
class Logger {
// Sample of abstract logging function
static void write(String text, {bool isError = false}) {
Future.microtask(() => debugPrint('** $text. isError: [$isError]'));
}
}

29
lib/utils/status_bar.dart Normal file
View File

@@ -0,0 +1,29 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// 状态栏设置工具类
class StatusBarKit {
// 设置沉浸式状态栏
static void setStatusBarDark({bool dark = false, Color? darkColor}) {
if (Platform.isAndroid) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: dark ? darkColor : Colors.transparent,
systemNavigationBarIconBrightness:
dark ? Brightness.light : Brightness.dark,
statusBarIconBrightness: dark ? Brightness.light : Brightness.dark,
statusBarBrightness: dark ? Brightness.light : Brightness.dark,
),
);
}
}
// 设置竖屏
static Future setPortrait() {
return SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
]);
}
}

69
lib/utils/storage.dart Normal file
View File

@@ -0,0 +1,69 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
// 本地存储
class StorageUtil {
static final StorageUtil _singleton = StorageUtil._internal();
late SharedPreferences _prefs;
factory StorageUtil() => _singleton;
StorageUtil._internal();
Future init() async {
_prefs = await SharedPreferences.getInstance();
}
Future<bool> putJSON(String key, dynamic jsonVal) {
String jsonString = jsonEncode(jsonVal);
return _prefs.setString(key, jsonString);
}
dynamic getJSON(String key) {
String? jsonString = _prefs.getString(key);
return jsonString == null ? null : jsonDecode(jsonString);
}
String getString(String key, {String defValue = ''}) {
if (!_prefs.containsKey(key)) return defValue;
return _prefs.getString(key) ?? defValue;
}
Future<bool>? putString(String key, String value) {
return _prefs.setString(key, value);
}
bool getBool(String key, {bool defValue = false}) {
if (!_prefs.containsKey(key)) return defValue;
return _prefs.getBool(key) ?? defValue;
}
Future<bool>? putBool(String key, bool value) {
return _prefs.setBool(key, value);
}
int getInt(String key, {int defValue = 0}) {
if (!_prefs.containsKey(key)) return defValue;
return _prefs.getInt(key) ?? defValue;
}
Future<bool>? putInt(String key, int value) {
return _prefs.setInt(key, value);
}
bool? haveKey(String key) {
return getKeys().contains(key);
}
Set<String> getKeys() {
return _prefs.getKeys();
}
Future<bool>? remove(String key) {
return _prefs.remove(key);
}
Future<bool>? clear() {
return _prefs.clear();
}
}

5
lib/utils/utils.dart Normal file
View File

@@ -0,0 +1,5 @@
library utils;
export 'logger.dart';
export 'status_bar.dart';
export 'storage.dart';