Skip to content

Commit

Permalink
Merge pull request #21 from Muska-Ami/dev
Browse files Browse the repository at this point in the history
Fix some bugs
  • Loading branch information
Muska-Ami authored Jan 10, 2024
2 parents 540bf07 + b1b9e57 commit ae0322e
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 20 deletions.
14 changes: 14 additions & 0 deletions lib/controller/dsettinglauncher.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:get/get.dart';
import 'package:nyalcf/io/settingStorage.dart';
import 'package:nyalcf/prefs/LauncherSettingPrefs.dart';
import 'package:package_info_plus/package_info_plus.dart';

Expand All @@ -12,6 +13,8 @@ class DSettingLauncherController extends GetxController {
var theme_light_seed = ''.obs;
var theme_light_seed_enable = false.obs;

Rx<Function(bool)?> switch_theme_dark_event = null.obs;

load() async {
final packageInfo = await PackageInfo.fromPlatform();
app_name.value = packageInfo.appName;
Expand All @@ -23,5 +26,16 @@ class DSettingLauncherController extends GetxController {
theme_dark.value = settings.theme_dark;
theme_light_seed.value = settings.theme_light_seed;
theme_light_seed_enable.value = settings.theme_light_seed_enable;
loadx();
}

void loadx() {
if (theme_dark.value) switch_theme_dark_event.value = switchDarkTheme;
}

void switchDarkTheme(value) async {
LauncherSettingPrefs.setThemeDark(value);
theme_dark.value = value;
SettingStorage.save(await LauncherSettingPrefs.getInfo());
}
}
22 changes: 14 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ class App extends StatelessWidget {
));
} else {
_theme_data = ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.pink.shade300,
).copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400,
),
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.pink.shade300,
).copyWith(
primary: Colors.pink.shade400,
secondary: Colors.pink.shade300,
),
appBarTheme: AppBarTheme(
color: Colors.pink.shade100,
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Colors.pink.shade200,
),
);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/prefs/LauncherSettingPrefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class LauncherSettingPrefs {
final res = await SettingStorage.read();
if (res != null) setInfo(res);
}

static Future<void> setThemeAuto(bool value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('setting@theme@auto', value.toString());
}

static Future<void> setThemeDark(bool value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('setting@theme@dark', value.toString());
}
}

extension on String {
Expand Down
1 change: 0 additions & 1 deletion lib/ui/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class _LoginState extends State<Login> {
appBar: AppBar(
title:
Text('$title - 登录', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],
actions: AppbarActionsX(context: context).actions(),
),
body: Center(
Expand Down
1 change: 0 additions & 1 deletion lib/ui/auth/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class _RegisterState extends State<Register> {
appBar: AppBar(
title:
Text('$title - 注册', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],
actions: AppbarActionsX(context: context).actions(),
),
body: ListView(
Expand Down
1 change: 0 additions & 1 deletion lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Home extends StatelessWidget {
appBar: AppBar(
title:
Text('$title - 首页', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],
actions: AppbarActionsX(context: context).actions(),
automaticallyImplyLeading: false,
),
Expand Down
1 change: 0 additions & 1 deletion lib/ui/model/FloatingActionButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class FloatingActionButtonX {
return Builder(builder: (BuildContext context) {
return FloatingActionButton(
foregroundColor: Colors.white,
backgroundColor: Colors.pink[100],
onPressed: () => Get.dialog(ToolDialogX(context: context).build()),
elevation: 7.0,
highlightElevation: 14.0,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PanelConsole extends StatelessWidget {
appBar: AppBar(
title:
Text('$title - 仪表板', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],

//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
IconButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/panel/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PanelHome extends StatelessWidget {
appBar: AppBar(
title:
Text('$title - 仪表板', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],

//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
IconButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/panel/proxies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PanelProxies extends StatelessWidget {
appBar: AppBar(
title:
Text('$title - 仪表板', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],

//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
IconButton(
Expand Down
1 change: 0 additions & 1 deletion lib/ui/setting/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SettingInjector extends StatelessWidget {
appBar: AppBar(
title: Text('$title - 设置',
style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],
actions:
AppbarActionsX(context: context, setting: false).actions(),
bottom: TabBar(
Expand Down
17 changes: 13 additions & 4 deletions lib/ui/setting/launcher.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/dsettinglauncher.dart';
import 'package:nyalcf/io/settingStorage.dart';
import 'package:nyalcf/prefs/LauncherSettingPrefs.dart';
import 'package:url_launcher/url_launcher.dart';

class LauncherSX {
Expand Down Expand Up @@ -37,8 +39,14 @@ class LauncherSX {
),
),
Switch(
value: ds_c.theme_auto.value,
onChanged: null),
value: ds_c.theme_auto.value,
onChanged: (value) async {
LauncherSettingPrefs.setThemeAuto(value);
ds_c.theme_auto.value = value;
SettingStorage.save(
await LauncherSettingPrefs.getInfo());
},
),
],
),
Row(
Expand All @@ -50,8 +58,9 @@ class LauncherSX {
),
),
Switch(
value: ds_c.theme_dark.value,
onChanged: null),
value: ds_c.theme_dark.value,
onChanged: ds_c.switch_theme_dark_event.value,
),
],
),
Row(
Expand Down

0 comments on commit ae0322e

Please sign in to comment.