mirror of
https://github.com/asjqkkkk/flutter-todos.git
synced 2025-08-06 14:19:24 +08:00
110 lines
3.9 KiB
Dart
110 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:todo_list/json/color_bean.dart';
|
|
import 'package:todo_list/json/theme_bean.dart';
|
|
import 'package:todo_list/model/all_model.dart';
|
|
import 'package:todo_list/utils/shared_util.dart';
|
|
import 'package:todo_list/utils/theme_util.dart';
|
|
import 'dart:convert';
|
|
|
|
class GlobalLogic{
|
|
|
|
final GlobalModel _model;
|
|
|
|
GlobalLogic(this._model);
|
|
|
|
|
|
//当为夜间模式时候,白色替换为灰色
|
|
Color getWhiteInDark(){
|
|
final themeType = _model.currentThemeBean.themeType;
|
|
return themeType == MyTheme.darkTheme ? Colors.grey : Colors.white;
|
|
}
|
|
|
|
//当为夜间模式时候,白色背景替换为特定灰色
|
|
Color getBgInDark(){
|
|
final themeType = _model.currentThemeBean.themeType;
|
|
return themeType == MyTheme.darkTheme ? Colors.grey[800] : Colors.white;
|
|
}
|
|
|
|
//当为夜间模式时候,主题色背景替换为特定灰色
|
|
Color getPrimaryInDark(BuildContext context){
|
|
final themeType = _model.currentThemeBean.themeType;
|
|
return themeType == MyTheme.darkTheme ? Colors.grey : Theme.of(context).primaryColor;
|
|
}
|
|
|
|
Future getCurrentLanguageCode() async{
|
|
final list = await SharedUtil.instance.getStringList(Keys.currentLanguageCode);
|
|
if (list == null) return;
|
|
if (list == _model.currentLanguageCode) return;
|
|
_model.currentLanguageCode = list;
|
|
}
|
|
|
|
Future getCurrentLanguage() async{
|
|
final currentLanguage = await SharedUtil.instance.getString(Keys.currentLanguage);
|
|
if (currentLanguage == null) return;
|
|
if (currentLanguage == _model.currentLanguage) return;
|
|
_model.currentLanguage = currentLanguage;
|
|
}
|
|
|
|
Future getCurrentTheme() async{
|
|
final theme = await SharedUtil.instance.getString(Keys.currentThemeBean);
|
|
if(theme == null) return;
|
|
ThemeBean themeBean = ThemeBean.fromMap(jsonDecode(theme));
|
|
if(themeBean.themeType == _model.currentThemeBean.themeType) return;
|
|
_model.currentThemeBean = themeBean;
|
|
}
|
|
|
|
Future getAppName() async{
|
|
final appName = await SharedUtil.instance.getString(Keys.appName);
|
|
if(appName == null) return;
|
|
if(appName == _model.appName) return;
|
|
_model.appName = appName;
|
|
}
|
|
|
|
|
|
Future getIsBgGradient()async{
|
|
final isBgGradient = await SharedUtil.instance.getBoolean(Keys.backgroundGradient);
|
|
if(isBgGradient == null) return;
|
|
if(isBgGradient == _model.isBgGradient) return;
|
|
_model.isBgGradient = isBgGradient;
|
|
}
|
|
|
|
Future getCurrentNavHeader()async{
|
|
final currentNavHeader = await SharedUtil.instance.getString(Keys.currentNavHeader);
|
|
if(currentNavHeader == null) return;
|
|
if(currentNavHeader == _model.currentNavHeader) return;
|
|
_model.currentNavHeader = currentNavHeader;
|
|
}
|
|
|
|
Future getCurrentNetPicUrl()async{
|
|
final currentNetPicUrl = await SharedUtil.instance.getString(Keys.currentNetPicUrl);
|
|
if(currentNetPicUrl == null) return;
|
|
if(currentNetPicUrl == _model.currentNavHeader) return;
|
|
_model.currentNetPicUrl = currentNetPicUrl;
|
|
}
|
|
|
|
Future getIsBgChangeWithCard() async {
|
|
final isBgChangeWithCard = await SharedUtil.instance.getBoolean(Keys.backgroundChangeWithCard);
|
|
if(isBgChangeWithCard == null) return;
|
|
if(isBgChangeWithCard == _model.isBgChangeWithCard) return;
|
|
_model.isBgChangeWithCard = isBgChangeWithCard;
|
|
}
|
|
|
|
Future getIsCardChangeWithBg() async {
|
|
final isCardChangeWithBg = await SharedUtil.instance.getBoolean(Keys.cardChangeWithBackground);
|
|
if(isCardChangeWithBg == null) return;
|
|
if(isCardChangeWithBg == _model.isCardChangeWithBg) return;
|
|
_model.isCardChangeWithBg = isCardChangeWithBg;
|
|
}
|
|
|
|
Future getEnableInfiniteScroll() async{
|
|
final enableInfiniteScroll = await SharedUtil.instance.getBoolean(Keys.enableInfiniteScroll);
|
|
if(enableInfiniteScroll == null) return;
|
|
if(enableInfiniteScroll == _model.enableInfiniteScroll) return;
|
|
_model.enableInfiniteScroll = enableInfiniteScroll;
|
|
}
|
|
|
|
bool isDarkNow(){
|
|
return _model.currentThemeBean.themeType == MyTheme.darkTheme;
|
|
}
|
|
|
|
} |