opt.: primaryColor

This commit is contained in:
lollipopkit
2023-09-10 11:13:02 +08:00
parent b187ec88be
commit ddaee7c2f3
7 changed files with 86 additions and 76 deletions

View File

@@ -470,7 +470,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -478,7 +478,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -602,7 +602,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -610,7 +610,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -628,7 +628,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -636,7 +636,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -657,7 +657,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -670,7 +670,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
@@ -696,7 +696,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -709,7 +709,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -732,7 +732,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
@@ -745,7 +745,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@@ -3,15 +3,23 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:toolbox/core/extension/context.dart';
import 'package:toolbox/core/extension/locale.dart';
import 'package:toolbox/view/page/full_screen.dart';
import 'core/utils/ui.dart';
import 'data/res/build_data.dart';
import 'data/res/color.dart';
import 'data/store/setting.dart';
import 'locator.dart';
import 'view/page/full_screen.dart';
import 'view/page/home.dart';
/// After upgrading to flutter 3.13,
/// the shadow color of the drawer is white (maybe a bug).
/// Only on [iOS].
/// TODO: remember to remove it after the bug is fixed.
const _drawerTheme = DrawerThemeData(
shadowColor: Colors.black12,
);
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
@@ -19,50 +27,54 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DynamicColorBuilder(builder: (light, dark) {
setTransparentNavigationBar(context);
_setupPrimaryColor(context, light, dark);
setTransparentNavigationBar(context);
final child = _wrapTheme(context);
if (_setting.useSystemPrimaryColor.fetch()) {
return _wrapSystemColor(context, child);
}
return child;
}
return ValueListenableBuilder<int>(
valueListenable: _setting.themeMode.listenable(),
builder: (_, tMode, __) {
final isAMOLED = tMode >= 0 && tMode <= ThemeMode.values.length - 1;
// Issue #57
// if not [ok] -> [AMOLED] mode, use [ThemeMode.dark]
final themeMode = isAMOLED ? ThemeMode.values[tMode] : ThemeMode.dark;
final locale = _setting.locale.fetch().toLocale;
final darkTheme = ThemeData(
Widget _wrapTheme(BuildContext context) {
return ValueListenableBuilder<int>(
valueListenable: _setting.themeMode.listenable(),
builder: (_, tMode, __) {
final isAMOLED = tMode >= 0 && tMode <= ThemeMode.values.length - 1;
// Issue #57
// if not [ok] -> [AMOLED] mode, use [ThemeMode.dark]
final themeMode = isAMOLED ? ThemeMode.values[tMode] : ThemeMode.dark;
final locale = _setting.locale.fetch().toLocale;
final darkTheme = ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: primaryColor,
drawerTheme: _drawerTheme,
);
return MaterialApp(
debugShowCheckedModeBanner: false,
locale: locale,
localizationsDelegates: S.localizationsDelegates,
supportedLocales: S.supportedLocales,
title: BuildData.name,
themeMode: themeMode,
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: primaryColor,
),
darkTheme: isAMOLED ? darkTheme : _getAmoledTheme(darkTheme),
home: _setting.fullScreen.fetch()
? const FullScreenPage()
: const HomePage(),
);
},
);
}
/// After upgrading to flutter 3.13,
/// the shadow color of the drawer is white (maybe a bug).
/// Only on [iOS].
/// TODO: remember to remove it after the bug is fixed.
drawerTheme: const DrawerThemeData(
shadowColor: Colors.black12,
),
);
return MaterialApp(
debugShowCheckedModeBanner: false,
locale: locale,
localizationsDelegates: S.localizationsDelegates,
supportedLocales: S.supportedLocales,
title: BuildData.name,
themeMode: themeMode,
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: primaryColor,
),
darkTheme: isAMOLED ? darkTheme : _getAmoledTheme(darkTheme),
home: _setting.fullScreen.fetch()
? const FullScreenPage()
: const HomePage(),
);
},
);
Widget _wrapSystemColor(BuildContext context, Widget child) {
return DynamicColorBuilder(builder: (light, dark) {
_setupPrimaryColor(context, light, dark);
return child;
});
}
@@ -71,14 +83,10 @@ class MyApp extends StatelessWidget {
ColorScheme? light,
ColorScheme? dark,
) {
if (_setting.useSystemPrimaryColor.fetch()) {
if (context.isDark && light != null) {
primaryColor = light.primary;
} else if (!context.isDark && dark != null) {
primaryColor = dark.primary;
}
} else {
primaryColor = Color(_setting.primaryColor.fetch());
if (context.isDark && light != null) {
primaryColor = light.primary;
} else if (!context.isDark && dark != null) {
primaryColor = dark.primary;
}
}
}
@@ -86,6 +94,7 @@ class MyApp extends StatelessWidget {
ThemeData _getAmoledTheme(ThemeData darkTheme) => darkTheme.copyWith(
scaffoldBackgroundColor: Colors.black,
dialogBackgroundColor: Colors.black,
drawerTheme: _drawerTheme.copyWith(backgroundColor: Colors.black),
appBarTheme: const AppBarTheme(backgroundColor: Colors.black),
dialogTheme: const DialogTheme(backgroundColor: Colors.black),
bottomSheetTheme:

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 538;
static const int build = 539;
static const String engine = "3.13.2";
static const String buildAt = "2023-09-08 19:51:19.470479";
static const int modifications = 4;
static const int script = 13;
static const String buildAt = "2023-09-08 20:40:50.892853";
static const int modifications = 6;
static const int script = 14;
}

View File

@@ -1,10 +1,8 @@
import 'package:flutter/material.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart';
import '../model/app/dynamic_color.dart';
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch());
late Color primaryColor;
const contentColor = DynamicColor(Colors.black87, Colors.white70);
const bgColor = DynamicColor(Colors.white, Colors.black);

View File

@@ -6,8 +6,6 @@ import 'package:logging/logging.dart';
import 'package:macos_window_utils/window_manipulator.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toolbox/data/res/misc.dart';
import 'package:toolbox/view/widget/custom_appbar.dart';
import 'app.dart';
import 'core/analysis.dart';
@@ -26,8 +24,11 @@ import 'data/provider/server.dart';
import 'data/provider/sftp.dart';
import 'data/provider/snippet.dart';
import 'data/provider/virtual_keyboard.dart';
import 'data/res/color.dart';
import 'data/res/misc.dart';
import 'data/store/setting.dart';
import 'locator.dart';
import 'view/widget/custom_appbar.dart';
import 'view/widget/rebuild.dart';
DebugProvider? _debug;
@@ -90,6 +91,7 @@ Future<void> initApp() async {
// Load font
final settings = locator<SettingStore>();
loadFontFile(settings.fontPath.fetch());
primaryColor = Color(settings.primaryColor.fetch());
// Android only
if (!isAndroid) return;

View File

@@ -366,6 +366,7 @@ class _SettingPageState extends State<SettingPage> {
}
_selectedColorValue.value = color.value;
_setting.primaryColor.put(_selectedColorValue.value);
primaryColor = color;
context.pop();
_showRestartSnackbar();
}

View File

@@ -474,9 +474,9 @@
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -489,9 +489,9 @@
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
@@ -504,9 +504,9 @@
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 538;
CURRENT_PROJECT_VERSION = 539;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.538;
MARKETING_VERSION = 1.0.539;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;