Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-12-02 11:46:31 +08:00
parent d2dcba5a59
commit fa583ebd0f
2 changed files with 163 additions and 177 deletions

View File

@@ -117,15 +117,13 @@ void main() async {
Request(); Request();
Request.setCookie(); Request.setCookie();
RequestUtils.syncHistoryStatus(); RequestUtils.syncHistoryStatus();
if (Utils.isMobile) {
PiliScheme.init();
}
SmartDialog.config.toast = SmartConfigToast( SmartDialog.config.toast = SmartConfigToast(
displayType: SmartToastType.onlyRefresh, displayType: SmartToastType.onlyRefresh,
); );
if (Utils.isMobile) { if (Utils.isMobile) {
PiliScheme.init();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle( SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle( const SystemUiOverlayStyle(
@@ -135,6 +133,22 @@ void main() async {
systemNavigationBarContrastEnforced: false, systemNavigationBarContrastEnforced: false,
), ),
); );
if (Platform.isAndroid) {
late List<DisplayMode> modes;
FlutterDisplayMode.supported.then((value) {
modes = value;
final String? storageDisplay = GStorage.setting.get(
SettingBoxKey.displayMode,
);
DisplayMode? displayMode;
if (storageDisplay != null) {
displayMode = modes.firstWhereOrNull(
(e) => e.toString() == storageDisplay,
);
}
FlutterDisplayMode.setPreferredMode(displayMode ?? DisplayMode.auto);
});
}
} else if (Utils.isDesktop) { } else if (Utils.isDesktop) {
await windowManager.ensureInitialized(); await windowManager.ensureInitialized();
@@ -159,10 +173,12 @@ void main() async {
if (Pref.enableLog) { if (Pref.enableLog) {
// 异常捕获 logo记录 // 异常捕获 logo记录
String buildConfig = final customParameters = {
'BuildConfig':
'''\n '''\n
Build Time: ${DateFormatUtils.format(BuildConfig.buildTime, format: DateFormatUtils.longFormatDs)} Build Time: ${DateFormatUtils.format(BuildConfig.buildTime, format: DateFormatUtils.longFormatDs)}
Commit Hash: ${BuildConfig.commitHash}'''; Commit Hash: ${BuildConfig.commitHash}''',
};
final Catcher2Options debugConfig = Catcher2Options( final Catcher2Options debugConfig = Catcher2Options(
SilentReportMode(), SilentReportMode(),
[ [
@@ -173,30 +189,22 @@ Commit Hash: ${BuildConfig.commitHash}''';
enableCustomParameters: true, enableCustomParameters: true,
), ),
], ],
customParameters: { customParameters: customParameters,
'BuildConfig': buildConfig,
},
); );
final Catcher2Options releaseConfig = Catcher2Options( final Catcher2Options releaseConfig = Catcher2Options(
SilentReportMode(), SilentReportMode(),
[ [
FileHandler(await LoggerUtils.getLogsPath()), FileHandler(await LoggerUtils.getLogsPath()),
ConsoleHandler( ConsoleHandler(enableCustomParameters: true),
enableCustomParameters: true,
),
], ],
customParameters: { customParameters: customParameters,
'BuildConfig': buildConfig,
},
); );
Catcher2( Catcher2(
debugConfig: debugConfig, debugConfig: debugConfig,
releaseConfig: releaseConfig, releaseConfig: releaseConfig,
runAppFunction: () { runAppFunction: () => runApp(const MyApp()),
runApp(const MyApp());
},
); );
} else { } else {
runApp(const MyApp()); runApp(const MyApp());
@@ -208,97 +216,7 @@ class MyApp extends StatelessWidget {
static ThemeData? darkThemeData; static ThemeData? darkThemeData;
@override static void _onBack() {
Widget build(BuildContext context) {
Color brandColor = colorThemeTypes[Pref.customColor].color;
bool isDynamicColor = Pref.dynamicColor;
FlexSchemeVariant variant = FlexSchemeVariant.values[Pref.schemeVariant];
// 强制设置高帧率
if (Platform.isAndroid) {
late List<DisplayMode> modes;
FlutterDisplayMode.supported.then((value) {
modes = value;
final String? storageDisplay = GStorage.setting.get(
SettingBoxKey.displayMode,
);
DisplayMode? displayMode;
if (storageDisplay != null) {
displayMode = modes.firstWhereOrNull(
(e) => e.toString() == storageDisplay,
);
}
displayMode ??= DisplayMode.auto;
FlutterDisplayMode.setPreferredMode(displayMode);
});
}
return DynamicColorBuilder(
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
ColorScheme? lightColorScheme;
ColorScheme? darkColorScheme;
if (lightDynamic != null && darkDynamic != null && isDynamicColor) {
// dynamic取色成功
lightColorScheme = lightDynamic.harmonized();
darkColorScheme = darkDynamic.harmonized();
} else {
// dynamic取色失败采用品牌色
lightColorScheme = SeedColorScheme.fromSeeds(
primaryKey: brandColor,
brightness: Brightness.light,
variant: variant,
// dynamicSchemeVariant: dynamicSchemeVariant,
// tones: FlexTones.soft(Brightness.light),
useExpressiveOnContainerColors: false,
);
darkColorScheme = SeedColorScheme.fromSeeds(
primaryKey: brandColor,
brightness: Brightness.dark,
variant: variant,
// dynamicSchemeVariant: dynamicSchemeVariant,
// tones: FlexTones.soft(Brightness.dark),
useExpressiveOnContainerColors: false,
);
}
// 图片缓存
// PaintingBinding.instance.imageCache.maximumSizeBytes = 1000 << 20;
return GetMaterialApp(
title: Constants.appName,
theme: ThemeUtils.getThemeData(
colorScheme: lightColorScheme,
isDynamic: lightDynamic != null && isDynamicColor,
variant: variant,
),
darkTheme: ThemeUtils.getThemeData(
colorScheme: darkColorScheme,
isDynamic: darkDynamic != null && isDynamicColor,
isDark: true,
variant: variant,
),
themeMode: Pref.themeMode,
localizationsDelegates: const [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
locale: const Locale("zh", "CN"),
supportedLocales: const [Locale("zh", "CN"), Locale("en", "US")],
fallbackLocale: const Locale("zh", "CN"),
getPages: Routes.getPages,
initialRoute: '/',
builder: FlutterSmartDialog.init(
toastBuilder: (String msg) => CustomToast(msg: msg),
loadingBuilder: (msg) => LoadingWidget(msg: msg),
builder: (context, child) {
child = MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.linear(Pref.defaultTextScale),
),
child: child!,
);
if (Utils.isDesktop) {
void onBack() {
if (SmartDialog.checkExist()) { if (SmartDialog.checkExist()) {
SmartDialog.dismiss(); SmartDialog.dismiss();
return; return;
@@ -333,18 +251,71 @@ class MyApp extends StatelessWidget {
Get.back(); Get.back();
} }
static Widget _build({
ColorScheme? lightColorScheme,
ColorScheme? darkColorScheme,
}) {
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,
),
darkTheme: ThemeUtils.getThemeData(
isDark: true,
colorScheme:
darkColorScheme ??
SeedColorScheme.fromSeeds(
variant: variant,
primaryKey: brandColor,
brightness: Brightness.dark,
useExpressiveOnContainerColors: false,
),
isDynamic: darkColorScheme != null,
),
themeMode: Pref.themeMode,
localizationsDelegates: const [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
locale: const Locale("zh", "CN"),
fallbackLocale: const Locale("zh", "CN"),
supportedLocales: const [Locale("zh", "CN"), Locale("en", "US")],
initialRoute: '/',
getPages: Routes.getPages,
builder: FlutterSmartDialog.init(
toastBuilder: (String msg) => CustomToast(msg: msg),
loadingBuilder: (msg) => LoadingWidget(msg: msg),
builder: (context, child) {
child = MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.linear(Pref.defaultTextScale),
),
child: child!,
);
if (Utils.isDesktop) {
return Focus( return Focus(
canRequestFocus: false, canRequestFocus: false,
onKeyEvent: (_, event) { onKeyEvent: (_, event) {
if (event.logicalKey == LogicalKeyboardKey.escape && if (event.logicalKey == LogicalKeyboardKey.escape &&
event is KeyDownEvent) { event is KeyDownEvent) {
onBack(); _onBack();
return KeyEventResult.handled; return KeyEventResult.handled;
} }
return KeyEventResult.ignored; return KeyEventResult.ignored;
}, },
child: MouseBackDetector( child: MouseBackDetector(
onTapDown: onBack, onTapDown: _onBack,
child: child, child: child,
), ),
); );
@@ -353,8 +324,8 @@ class MyApp extends StatelessWidget {
}, },
), ),
navigatorObservers: [ navigatorObservers: [
FlutterSmartDialog.observer,
PageUtils.routeObserver, PageUtils.routeObserver,
FlutterSmartDialog.observer,
], ],
scrollBehavior: const MaterialScrollBehavior().copyWith( scrollBehavior: const MaterialScrollBehavior().copyWith(
scrollbars: false, scrollbars: false,
@@ -368,9 +339,26 @@ 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();
}
}), }),
); );
} }
return _build();
}
} }
class _CustomHttpOverrides extends HttpOverrides { class _CustomHttpOverrides extends HttpOverrides {

View File

@@ -2,7 +2,6 @@ import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/main.dart'; import 'package:PiliPlus/main.dart';
import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flex_seed_scheme/flex_seed_scheme.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -11,7 +10,6 @@ abstract class ThemeUtils {
required ColorScheme colorScheme, required ColorScheme colorScheme,
required bool isDynamic, required bool isDynamic,
bool isDark = false, bool isDark = false,
required FlexSchemeVariant variant,
}) { }) {
final appFontWeight = Pref.appFontWeight.clamp( final appFontWeight = Pref.appFontWeight.clamp(
-1, -1,