You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.0 KiB
137 lines
4.0 KiB
import 'dart:core';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../entity/User.dart';
|
|
import '../widgets/FreeTimetableWidget.dart';
|
|
import '../widgets/TeamWidget.dart';
|
|
import '../widgets/TimetableWidget.dart';
|
|
|
|
class Setting {
|
|
static SharedPreferences? prefs;
|
|
static bool initFlag = true;
|
|
static DateTime startdate_init = DateTime(2023, 8, 28);
|
|
static int termAllWeekCout = 20; // 一学期的周数
|
|
static DateTime timeTableStartTime = DateTime(2023, 8, 28, 7, 00); // 一天的开始时间
|
|
static DateTime timeTableEndTime = DateTime(2023, 8, 28, 23, 00); // 一天的结束时间
|
|
static late DateTime startdate;
|
|
static late User? user;
|
|
static User nullUser = User(id:-1, username: "null", password: "null", role: 0);
|
|
static double pixelToMinuteRatio_ratio = 1; // 用于调整时间轴的比例
|
|
static late double deviceWidth ; // 用于调整时间轴的宽度
|
|
static bool isMusicPlaying = false; // 用于番茄钟音乐播放的状态
|
|
static bool isDeveloperButtonVisible = false; // 假设开发者测试初始状态为不可见
|
|
|
|
static GlobalKey<TimetableWidgetState>? timetableWidgetKey;
|
|
static GlobalKey<TeamWidgetState>? teamWidgetKey;
|
|
static GlobalKey<FreeTimetableWidgetState>? freeTimetableWidgeKey;
|
|
|
|
static init() async {
|
|
//初始化
|
|
print("Setting初始化");
|
|
prefs = await SharedPreferences.getInstance();
|
|
saveStartDate(startdate_init); // 用于测试
|
|
startdate = getStartDate();
|
|
user = getUser();
|
|
isDeveloperButtonVisible = getIsDeveloperButtonVisible();
|
|
pixelToMinuteRatio_ratio = getpixelToMinuteRatio_ratio();
|
|
initFlag = getInitFlag();
|
|
print("Setting初始化成功");
|
|
}
|
|
|
|
static DateTime getStartDate() {
|
|
//获取
|
|
String res = null.toString();
|
|
if(prefs!.containsKey("startdate")) res = prefs!.getString("startdate")!;
|
|
if (res == null.toString()) {
|
|
saveStartDate(startdate_init);
|
|
return startdate_init;
|
|
} else {
|
|
return DateTime.parse(res);
|
|
}
|
|
}
|
|
|
|
static saveStartDate(DateTime startdate) async {
|
|
//保存
|
|
await prefs?.setString("startdate", startdate.toString());
|
|
}
|
|
|
|
static User? getUser() {
|
|
//获取
|
|
String res = null.toString();
|
|
if(prefs!.containsKey("user")) res = prefs!.getString("user")!;
|
|
if (res == null.toString()) {
|
|
user = nullUser;
|
|
return nullUser;
|
|
} else {
|
|
user = User.parseString(res);
|
|
return user;
|
|
}
|
|
}
|
|
|
|
static saveUser(User newuser) async {
|
|
//保存
|
|
user = newuser;
|
|
await prefs?.setString("user", newuser.toString());
|
|
}
|
|
|
|
|
|
|
|
//pixelToMinuteRatio_ratio
|
|
static double getpixelToMinuteRatio_ratio() {
|
|
//获取
|
|
double? res;
|
|
if(prefs!.containsKey("pixelToMinuteRatio_ratio")) res = prefs!.getDouble("pixelToMinuteRatio_ratio")!;
|
|
if (res == null) {
|
|
pixelToMinuteRatio_ratio = 1;
|
|
return 1;
|
|
} else {
|
|
pixelToMinuteRatio_ratio = res!;
|
|
return pixelToMinuteRatio_ratio;
|
|
}
|
|
}
|
|
|
|
static savepixelToMinuteRatio_ratio(double value) async {
|
|
//保存
|
|
pixelToMinuteRatio_ratio = value;
|
|
await prefs?.setDouble("pixelToMinuteRatio_ratio", value);
|
|
}
|
|
|
|
static bool getIsDeveloperButtonVisible() {
|
|
//获取
|
|
bool? res;
|
|
if(prefs!.containsKey("isDeveloperButtonVisible")) res = prefs!.getBool("isDeveloperButtonVisible")!;
|
|
if (res == null) {
|
|
isDeveloperButtonVisible = false;
|
|
return false;
|
|
} else {
|
|
isDeveloperButtonVisible = res!;
|
|
return isDeveloperButtonVisible;
|
|
}
|
|
}
|
|
|
|
static saveIsDeveloperButtonVisible(bool value) async {
|
|
//保存
|
|
isDeveloperButtonVisible = value;
|
|
await prefs?.setBool("isDeveloperButtonVisible", value);
|
|
}
|
|
|
|
static getInitFlag() {
|
|
bool? getInitFlag = prefs!.getBool("initFlag");
|
|
if (getInitFlag == null) {
|
|
initFlag = true;
|
|
return true;
|
|
} else {
|
|
initFlag = getInitFlag;
|
|
return initFlag;
|
|
}
|
|
}
|
|
|
|
static saveInitFlag(bool value) async {
|
|
initFlag = value;
|
|
await prefs?.setBool("initFlag", value);
|
|
}
|
|
|
|
|
|
}
|