opt: main.daat code
This commit is contained in:
168
lib/main.dart
168
lib/main.dart
@ -23,7 +23,7 @@ import 'package:pilipala/utils/app_scheme.dart';
|
|||||||
import 'package:pilipala/utils/data.dart';
|
import 'package:pilipala/utils/data.dart';
|
||||||
import 'package:pilipala/utils/global_data.dart';
|
import 'package:pilipala/utils/global_data.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
import 'package:media_kit/media_kit.dart'; // Provides [Player], [Media], [Playlist] etc.
|
import 'package:media_kit/media_kit.dart';
|
||||||
import 'package:pilipala/utils/recommend_filter.dart';
|
import 'package:pilipala/utils/recommend_filter.dart';
|
||||||
import 'package:catcher_2/catcher_2.dart';
|
import 'package:catcher_2/catcher_2.dart';
|
||||||
import './services/loggeer.dart';
|
import './services/loggeer.dart';
|
||||||
@ -31,35 +31,21 @@ import './services/loggeer.dart';
|
|||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
MediaKit.ensureInitialized();
|
MediaKit.ensureInitialized();
|
||||||
SystemChrome.setPreferredOrientations(
|
await SystemChrome.setPreferredOrientations(
|
||||||
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown])
|
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
||||||
.then((_) async {
|
|
||||||
await GStrorage.init();
|
await GStrorage.init();
|
||||||
await setupServiceLocator();
|
await setupServiceLocator();
|
||||||
clearLogs();
|
clearLogs();
|
||||||
Request();
|
Request();
|
||||||
await Request.setCookie();
|
await Request.setCookie();
|
||||||
RecommendFilter();
|
|
||||||
|
|
||||||
// 异常捕获 logo记录
|
// 异常捕获 logo记录
|
||||||
final Catcher2Options debugConfig = Catcher2Options(
|
|
||||||
SilentReportMode(),
|
|
||||||
[
|
|
||||||
FileHandler(await getLogsPath()),
|
|
||||||
ConsoleHandler(
|
|
||||||
enableDeviceParameters: false,
|
|
||||||
enableApplicationParameters: false,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
final Catcher2Options releaseConfig = Catcher2Options(
|
final Catcher2Options releaseConfig = Catcher2Options(
|
||||||
SilentReportMode(),
|
SilentReportMode(),
|
||||||
[FileHandler(await getLogsPath())],
|
[FileHandler(await getLogsPath())],
|
||||||
);
|
);
|
||||||
|
|
||||||
Catcher2(
|
Catcher2(
|
||||||
debugConfig: debugConfig,
|
|
||||||
releaseConfig: releaseConfig,
|
releaseConfig: releaseConfig,
|
||||||
runAppFunction: () {
|
runAppFunction: () {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -79,11 +65,8 @@ void main() async {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Data.init();
|
|
||||||
GlobalData();
|
|
||||||
PiliSchame.init();
|
PiliSchame.init();
|
||||||
DisableBatteryOpt();
|
DisableBatteryOpt();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@ -124,6 +107,39 @@ class MyApp extends StatelessWidget {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
return AndroidApp(
|
||||||
|
brandColor: brandColor,
|
||||||
|
isDynamicColor: isDynamicColor,
|
||||||
|
currentThemeValue: currentThemeValue,
|
||||||
|
textScale: textScale,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return OtherApp(
|
||||||
|
brandColor: brandColor,
|
||||||
|
currentThemeValue: currentThemeValue,
|
||||||
|
textScale: textScale,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AndroidApp extends StatelessWidget {
|
||||||
|
const AndroidApp({
|
||||||
|
super.key,
|
||||||
|
required this.brandColor,
|
||||||
|
required this.isDynamicColor,
|
||||||
|
required this.currentThemeValue,
|
||||||
|
required this.textScale,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Color brandColor;
|
||||||
|
final bool isDynamicColor;
|
||||||
|
final ThemeType currentThemeValue;
|
||||||
|
final double textScale;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return DynamicColorBuilder(
|
return DynamicColorBuilder(
|
||||||
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
||||||
ColorScheme? lightColorScheme;
|
ColorScheme? lightColorScheme;
|
||||||
@ -143,50 +159,77 @@ class MyApp extends StatelessWidget {
|
|||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return BuildMainApp(
|
||||||
|
lightColorScheme: lightColorScheme,
|
||||||
|
darkColorScheme: darkColorScheme,
|
||||||
|
currentThemeValue: currentThemeValue,
|
||||||
|
textScale: textScale,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ThemeData themeData = ThemeData(
|
class OtherApp extends StatelessWidget {
|
||||||
// colorScheme: currentThemeValue == ThemeType.dark
|
const OtherApp({
|
||||||
// ? darkColorScheme
|
super.key,
|
||||||
// : lightColorScheme,
|
required this.brandColor,
|
||||||
// );
|
required this.currentThemeValue,
|
||||||
|
required this.textScale,
|
||||||
|
});
|
||||||
|
|
||||||
// // 小白条、导航栏沉浸
|
final Color brandColor;
|
||||||
// if (Platform.isAndroid) {
|
final ThemeType currentThemeValue;
|
||||||
// List<String> versionParts = Platform.version.split('.');
|
final double textScale;
|
||||||
// int androidVersion = int.parse(versionParts[0]);
|
|
||||||
// if (androidVersion >= 29) {
|
@override
|
||||||
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
Widget build(BuildContext context) {
|
||||||
// }
|
return BuildMainApp(
|
||||||
// SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
lightColorScheme: ColorScheme.fromSeed(
|
||||||
// systemNavigationBarColor: GlobalData().enableMYBar
|
seedColor: brandColor,
|
||||||
// ? const Color(0x00010000)
|
brightness: Brightness.light,
|
||||||
// : themeData.canvasColor,
|
),
|
||||||
// systemNavigationBarDividerColor: GlobalData().enableMYBar
|
darkColorScheme: ColorScheme.fromSeed(
|
||||||
// ? const Color(0x00010000)
|
seedColor: brandColor,
|
||||||
// : themeData.canvasColor,
|
brightness: Brightness.dark,
|
||||||
// systemNavigationBarIconBrightness:
|
),
|
||||||
// currentThemeValue == ThemeType.dark
|
currentThemeValue: currentThemeValue,
|
||||||
// ? Brightness.light
|
textScale: textScale,
|
||||||
// : Brightness.dark,
|
);
|
||||||
// statusBarColor: Colors.transparent,
|
}
|
||||||
// ));
|
}
|
||||||
// }
|
|
||||||
|
class BuildMainApp extends StatelessWidget {
|
||||||
|
const BuildMainApp({
|
||||||
|
super.key,
|
||||||
|
required this.lightColorScheme,
|
||||||
|
required this.darkColorScheme,
|
||||||
|
required this.currentThemeValue,
|
||||||
|
required this.textScale,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ColorScheme lightColorScheme;
|
||||||
|
final ColorScheme darkColorScheme;
|
||||||
|
final ThemeType currentThemeValue;
|
||||||
|
final double textScale;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final SnackBarThemeData snackBarTheme = SnackBarThemeData(
|
||||||
|
actionTextColor: lightColorScheme.primary,
|
||||||
|
backgroundColor: lightColorScheme.secondaryContainer,
|
||||||
|
closeIconColor: lightColorScheme.secondary,
|
||||||
|
contentTextStyle: TextStyle(color: lightColorScheme.secondary),
|
||||||
|
elevation: 20,
|
||||||
|
);
|
||||||
|
|
||||||
// 图片缓存
|
|
||||||
// PaintingBinding.instance.imageCache.maximumSizeBytes = 1000 << 20;
|
|
||||||
return GetMaterialApp(
|
return GetMaterialApp(
|
||||||
title: 'PiliPala',
|
title: 'PiliPala',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: currentThemeValue == ThemeType.dark
|
colorScheme: currentThemeValue == ThemeType.dark
|
||||||
? darkColorScheme
|
? darkColorScheme
|
||||||
: lightColorScheme,
|
: lightColorScheme,
|
||||||
snackBarTheme: SnackBarThemeData(
|
snackBarTheme: snackBarTheme,
|
||||||
actionTextColor: lightColorScheme.primary,
|
|
||||||
backgroundColor: lightColorScheme.secondaryContainer,
|
|
||||||
closeIconColor: lightColorScheme.secondary,
|
|
||||||
contentTextStyle: TextStyle(color: lightColorScheme.secondary),
|
|
||||||
elevation: 20,
|
|
||||||
),
|
|
||||||
pageTransitionsTheme: const PageTransitionsTheme(
|
pageTransitionsTheme: const PageTransitionsTheme(
|
||||||
builders: <TargetPlatform, PageTransitionsBuilder>{
|
builders: <TargetPlatform, PageTransitionsBuilder>{
|
||||||
TargetPlatform.android: ZoomPageTransitionsBuilder(
|
TargetPlatform.android: ZoomPageTransitionsBuilder(
|
||||||
@ -199,13 +242,7 @@ class MyApp extends StatelessWidget {
|
|||||||
colorScheme: currentThemeValue == ThemeType.light
|
colorScheme: currentThemeValue == ThemeType.light
|
||||||
? lightColorScheme
|
? lightColorScheme
|
||||||
: darkColorScheme,
|
: darkColorScheme,
|
||||||
snackBarTheme: SnackBarThemeData(
|
snackBarTheme: snackBarTheme,
|
||||||
actionTextColor: darkColorScheme.primary,
|
|
||||||
backgroundColor: darkColorScheme.secondaryContainer,
|
|
||||||
closeIconColor: darkColorScheme.secondary,
|
|
||||||
contentTextStyle: TextStyle(color: darkColorScheme.secondary),
|
|
||||||
elevation: 20,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
localizationsDelegates: const [
|
localizationsDelegates: const [
|
||||||
GlobalCupertinoLocalizations.delegate,
|
GlobalCupertinoLocalizations.delegate,
|
||||||
@ -231,8 +268,11 @@ class MyApp extends StatelessWidget {
|
|||||||
VideoDetailPage.routeObserver,
|
VideoDetailPage.routeObserver,
|
||||||
SearchPage.routeObserver,
|
SearchPage.routeObserver,
|
||||||
],
|
],
|
||||||
);
|
onInit: () {
|
||||||
}),
|
RecommendFilter();
|
||||||
|
Data.init();
|
||||||
|
GlobalData();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user