theme_config.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. class ThemeConfig {
  5. //亮色模式模式下的状态栏与导航栏设置 (默认黑色状态栏文本,白色导航栏)
  6. static SystemUiOverlayStyle get systemUiOverlayStyleLightThemeBlack {
  7. return SystemUiOverlayStyle.light.copyWith(
  8. statusBarColor: Colors.transparent,
  9. //顶部导航栏的状态栏背景颜色
  10. statusBarBrightness: Brightness.light,
  11. //顶部状态栏颜色模式
  12. statusBarIconBrightness: Brightness.dark,
  13. //顶部状态栏Icon与文本颜色模式
  14. systemNavigationBarDividerColor: Colors.transparent,
  15. //底部导航栏分割线颜色
  16. systemNavigationBarColor: Colors.white,
  17. //底部导航栏背景颜色
  18. systemNavigationBarIconBrightness: Brightness.dark, //底部导航栏三大金刚键的颜色模式
  19. );
  20. }
  21. //亮色模式模式下的状态栏与导航栏设置 (设置白色状态栏文本,白色导航栏)
  22. static SystemUiOverlayStyle get systemUiOverlayStyleLightThemeWhite {
  23. return SystemUiOverlayStyle.light.copyWith(
  24. statusBarColor: Colors.transparent,
  25. statusBarBrightness: Brightness.dark,
  26. statusBarIconBrightness: Brightness.light,
  27. systemNavigationBarDividerColor: Colors.transparent,
  28. systemNavigationBarColor: Colors.white,
  29. systemNavigationBarIconBrightness: Brightness.dark,
  30. );
  31. }
  32. //黑暗模式下,统一使用白色状态栏文本,黑色导航栏
  33. static SystemUiOverlayStyle get systemUiOverlayStyleDarkTheme {
  34. return SystemUiOverlayStyle.dark.copyWith(
  35. statusBarColor: Colors.transparent,
  36. statusBarBrightness: Brightness.dark,
  37. statusBarIconBrightness: Brightness.light,
  38. );
  39. }
  40. //根据上下文的亮色模式和暗色模式返回对应的 SystemUiOverlay 配置
  41. static SystemUiOverlayStyle getSystemUiOverlayStyleByTheme(BuildContext context) {
  42. late SystemUiOverlayStyle systemUiOverlayStyle;
  43. Brightness currentBrightness = MediaQuery.of(context).platformBrightness;
  44. if (currentBrightness == Brightness.dark) {
  45. systemUiOverlayStyle = systemUiOverlayStyleDarkTheme;
  46. } else {
  47. systemUiOverlayStyle = systemUiOverlayStyleLightThemeBlack;
  48. }
  49. return systemUiOverlayStyle;
  50. }
  51. }