mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
tweaks (#1780)
* opt: sized * fix: self send * feat: ctrl enter to send * opt: checked * opt: download notifier * opt: Future.syncValue * mod: account * mod: loading state * opt: DebounceStreamMixin * opt: report * opt: enum map * opt: file handler * opt: dyn color * opt: Uint8List subview * opt: FileExt * opt: computeLuminance * opt: isNullOrEmpty * opt: Get context * update [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * opt dynamicColor [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * fixes [skip ci] * update Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * update Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Signed-off-by: My-Responsitories <107370289+My-Responsitories@users.noreply.github.com> Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
02e0d34127
commit
ce5e85e64b
119
lib/main.dart
119
lib/main.dart
@@ -56,6 +56,7 @@ void main() async {
|
||||
if (kDebugMode) debugPrint('GStorage init error: $e');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (PlatformUtils.isDesktop) {
|
||||
final customDownPath = Pref.downloadPath;
|
||||
if (customDownPath != null && customDownPath.isNotEmpty) {
|
||||
@@ -135,15 +136,13 @@ void main() async {
|
||||
),
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
late List<DisplayMode> modes;
|
||||
FlutterDisplayMode.supported.then((value) {
|
||||
modes = value;
|
||||
FlutterDisplayMode.supported.then((mode) {
|
||||
final String? storageDisplay = GStorage.setting.get(
|
||||
SettingBoxKey.displayMode,
|
||||
);
|
||||
DisplayMode? displayMode;
|
||||
if (storageDisplay != null) {
|
||||
displayMode = modes.firstWhereOrNull(
|
||||
displayMode = mode.firstWhereOrNull(
|
||||
(e) => e.toString() == storageDisplay,
|
||||
);
|
||||
}
|
||||
@@ -153,7 +152,7 @@ void main() async {
|
||||
} else if (PlatformUtils.isDesktop) {
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
WindowOptions windowOptions = WindowOptions(
|
||||
final windowOptions = WindowOptions(
|
||||
minimumSize: const Size(400, 720),
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: Pref.showWindowTitleBar
|
||||
@@ -172,6 +171,10 @@ void main() async {
|
||||
});
|
||||
}
|
||||
|
||||
if (Pref.dynamicColor) {
|
||||
await MyApp.initPlatformState();
|
||||
}
|
||||
|
||||
if (Pref.enableLog) {
|
||||
// 异常捕获 logo记录
|
||||
final customParameters = {
|
||||
@@ -215,6 +218,8 @@ void main() async {
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
static ColorScheme? _light, _dark;
|
||||
|
||||
static ThemeData? darkThemeData;
|
||||
|
||||
static void _onBack() {
|
||||
@@ -252,36 +257,35 @@ class MyApp extends StatelessWidget {
|
||||
Get.back();
|
||||
}
|
||||
|
||||
static Widget _build({
|
||||
ColorScheme? lightColorScheme,
|
||||
ColorScheme? darkColorScheme,
|
||||
}) {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dynamicColor = Pref.dynamicColor && _light != null && _dark != null;
|
||||
late final brandColor = colorThemeTypes[Pref.customColor].color;
|
||||
late final variant = FlexSchemeVariant.values[Pref.schemeVariant];
|
||||
return GetMaterialApp(
|
||||
title: Constants.appName,
|
||||
theme: ThemeUtils.getThemeData(
|
||||
colorScheme:
|
||||
lightColorScheme ??
|
||||
SeedColorScheme.fromSeeds(
|
||||
variant: variant,
|
||||
primaryKey: brandColor,
|
||||
brightness: Brightness.light,
|
||||
useExpressiveOnContainerColors: false,
|
||||
),
|
||||
isDynamic: lightColorScheme != null,
|
||||
colorScheme: dynamicColor
|
||||
? _light!
|
||||
: SeedColorScheme.fromSeeds(
|
||||
variant: variant,
|
||||
primaryKey: brandColor,
|
||||
brightness: Brightness.light,
|
||||
useExpressiveOnContainerColors: false,
|
||||
),
|
||||
isDynamic: dynamicColor,
|
||||
),
|
||||
darkTheme: ThemeUtils.getThemeData(
|
||||
isDark: true,
|
||||
colorScheme:
|
||||
darkColorScheme ??
|
||||
SeedColorScheme.fromSeeds(
|
||||
variant: variant,
|
||||
primaryKey: brandColor,
|
||||
brightness: Brightness.dark,
|
||||
useExpressiveOnContainerColors: false,
|
||||
),
|
||||
isDynamic: darkColorScheme != null,
|
||||
colorScheme: dynamicColor
|
||||
? _dark!
|
||||
: SeedColorScheme.fromSeeds(
|
||||
variant: variant,
|
||||
primaryKey: brandColor,
|
||||
brightness: Brightness.dark,
|
||||
useExpressiveOnContainerColors: false,
|
||||
),
|
||||
isDynamic: dynamicColor,
|
||||
),
|
||||
themeMode: Pref.themeMode,
|
||||
localizationsDelegates: const [
|
||||
@@ -343,23 +347,52 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!Platform.isIOS && Pref.dynamicColor) {
|
||||
return DynamicColorBuilder(
|
||||
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
||||
if (lightDynamic != null && darkDynamic != null) {
|
||||
return _build(
|
||||
lightColorScheme: lightDynamic.harmonized(),
|
||||
darkColorScheme: darkDynamic.harmonized(),
|
||||
);
|
||||
} else {
|
||||
return _build();
|
||||
}
|
||||
}),
|
||||
);
|
||||
/// from [DynamicColorBuilderState.initPlatformState]
|
||||
static Future<void> initPlatformState() async {
|
||||
if (_light != null || _dark != null) return;
|
||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||
try {
|
||||
final corePalette = await DynamicColorPlugin.getCorePalette();
|
||||
|
||||
if (corePalette != null) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('dynamic_color: Core palette detected.');
|
||||
}
|
||||
_light = corePalette.toColorScheme();
|
||||
_dark = corePalette.toColorScheme(brightness: Brightness.dark);
|
||||
return;
|
||||
}
|
||||
} on PlatformException {
|
||||
if (kDebugMode) {
|
||||
debugPrint('dynamic_color: Failed to obtain core palette.');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
final Color? accentColor = await DynamicColorPlugin.getAccentColor();
|
||||
|
||||
if (accentColor != null) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('dynamic_color: Accent color detected.');
|
||||
}
|
||||
_light = ColorScheme.fromSeed(
|
||||
seedColor: accentColor,
|
||||
brightness: Brightness.light,
|
||||
);
|
||||
_dark = ColorScheme.fromSeed(
|
||||
seedColor: accentColor,
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
return;
|
||||
}
|
||||
} on PlatformException {
|
||||
if (kDebugMode) {
|
||||
debugPrint('dynamic_color: Failed to obtain accent color.');
|
||||
}
|
||||
}
|
||||
if (kDebugMode) {
|
||||
debugPrint('dynamic_color: Dynamic color not detected on this device.');
|
||||
}
|
||||
return _build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user