Skip to content

Commit

Permalink
fix status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
￴￴ committed Nov 17, 2024
1 parent d490f6f commit b6fe303
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 31 deletions.
16 changes: 14 additions & 2 deletions lib/route/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ class RouteDataGeneralLibFlutter {
final Object? arguments;
final BuildContext context;
// final PageStorageBucket pageStorageBucket;
RouteDataGeneralLibFlutter({
const RouteDataGeneralLibFlutter({
required this.routeName,
required this.arguments,
required this.context,
// required this.pageStorageBucket,
});

RouteDataGeneralLibFlutter copyWith({
String? routeName,
Object? arguments,
BuildContext? context,
}) {
return RouteDataGeneralLibFlutter(
routeName: routeName ?? this.routeName,
arguments: arguments ?? this.arguments,
context: context ?? this.context,
);
}

String get path {
return routeName;
}
Expand Down Expand Up @@ -112,7 +124,7 @@ class RouteGeneralLibFlutter {
void get(String path, RouteWidgetBuilderGeneralLibFlutter<dynamic> routeWidgetBuilderGeneralLibFlutter) {
all(path, routeWidgetBuilderGeneralLibFlutter);
}

void head(String path, RouteWidgetBuilderGeneralLibFlutter<dynamic> routeWidgetBuilderGeneralLibFlutter) {
all(path, routeWidgetBuilderGeneralLibFlutter);
}
Expand Down
82 changes: 53 additions & 29 deletions lib/widget/general_widget_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,50 @@ class GeneralLibFlutterApp extends ChangeNotifier {
required ThemeMode theme_mode,
required Brightness Function() onChangeBrightness,
}) {
if (theme_mode == ThemeMode.dark) {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
),
setSystemUIOverlayStyle(
theme_mode: theme_mode,
onChangeBrightness: onChangeBrightness,
);

notifyListeners();
}

void setSystemUIOverlayStyle({
required ThemeMode theme_mode,
required Brightness Function() onChangeBrightness,
}) {
SystemChrome.setSystemUIOverlayStyle(
getSystemUiOverlayStyle(
themeMode: theme_mode,
onChangeBrightness: onChangeBrightness,
),
);
}

SystemUiOverlayStyle getSystemUiOverlayStyle({
required ThemeMode themeMode,
required Brightness Function() onChangeBrightness,
}) {
if (themeMode == ThemeMode.dark) {
return const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
);
} else if (theme_mode == ThemeMode.light) {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.light,
),
} else if (themeMode == ThemeMode.light) {
return const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.light,
);
} else if (theme_mode == ThemeMode.system) {
Brightness brightness = onChangeBrightness();
// brightness ;
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: (brightness == Brightness.light) ? Brightness.dark : Brightness.light,
statusBarBrightness: (brightness == Brightness.light) ? Brightness.light : Brightness.dark,
),
} else {
final Brightness brightness = onChangeBrightness();
return SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: (brightness == Brightness.light) ? Brightness.dark : Brightness.light,
statusBarBrightness: (brightness == Brightness.light) ? Brightness.light : Brightness.dark,
);
}

notifyListeners();
}

ThemeMode autoChangeTheme({required Brightness Function() onChangeBrightness}) {
Expand Down Expand Up @@ -216,10 +231,10 @@ class GeneralLibFlutterApp extends ChangeNotifier {
indicatorColor: Colors.white,
dialogBackgroundColor: const Color.fromARGB(255, 64, 64, 64),
cardColor: Colors.grey,
appBarTheme: themeData.appBarTheme.copyWith(
backgroundColor: const Color.fromARGB(255, 22, 22, 30), // old themeData.scaffoldBackgroundColor,
surfaceTintColor: const Color.fromARGB(255, 22, 22, 30), // old themeData.scaffoldBackgroundColor,
),
appBarTheme: themeData.appBarTheme.copyWith(
backgroundColor: const Color.fromARGB(255, 22, 22, 30), // old themeData.scaffoldBackgroundColor,
surfaceTintColor: const Color.fromARGB(255, 22, 22, 30), // old themeData.scaffoldBackgroundColor,
systemOverlayStyle: SystemUiOverlayStyle()),
colorScheme: colorScheme.copyWith(
primary: Colors.white, // old const Color.fromARGB(255, 64, 64, 64),
surface: const Color.fromARGB(255, 26, 27, 38),
Expand All @@ -240,11 +255,13 @@ class GeneralLibFlutterAppMain extends StatelessWidget {
final ThemeData Function(BuildContext context, ThemeData defaultTheme)? lightTheme;
final ThemeData Function(BuildContext context, ThemeData defaultTheme)? darkTheme;
final Widget? child;
final bool isAutoInitialized;
final Widget Function(ThemeMode themeMode, ThemeData lightTheme, ThemeData darkTheme, Widget? widget) builder;

const GeneralLibFlutterAppMain({
super.key,
required this.generalLibFlutterApp,
this.isAutoInitialized = true,
this.lightTheme,
this.darkTheme,
// required this.theme_notifier,
Expand All @@ -268,6 +285,13 @@ class GeneralLibFlutterAppMain extends StatelessWidget {
builder: (context, child) {
final lightTheme = this.lightTheme;
final darkTheme = this.darkTheme;
if (isAutoInitialized) {
generalLibFlutterApp.initState(
context: context,
themeMode: generalLibFlutterApp.themeMode,
onSet: () {},
);
}
return builder(
generalLibFlutterApp.themeMode,
(lightTheme != null) ? lightTheme(context, lightTheme_default()) : lightTheme_default(),
Expand Down

0 comments on commit b6fe303

Please sign in to comment.