1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- class ThemeConfig {
- //亮色模式模式下的状态栏与导航栏设置 (默认黑色状态栏文本,白色导航栏)
- static SystemUiOverlayStyle get systemUiOverlayStyleLightThemeBlack {
- return SystemUiOverlayStyle.light.copyWith(
- statusBarColor: Colors.transparent,
- //顶部导航栏的状态栏背景颜色
- statusBarBrightness: Brightness.light,
- //顶部状态栏颜色模式
- statusBarIconBrightness: Brightness.dark,
- //顶部状态栏Icon与文本颜色模式
- systemNavigationBarDividerColor: Colors.transparent,
- //底部导航栏分割线颜色
- systemNavigationBarColor: Colors.white,
- //底部导航栏背景颜色
- systemNavigationBarIconBrightness: Brightness.dark, //底部导航栏三大金刚键的颜色模式
- );
- }
- //亮色模式模式下的状态栏与导航栏设置 (设置白色状态栏文本,白色导航栏)
- static SystemUiOverlayStyle get systemUiOverlayStyleLightThemeWhite {
- return SystemUiOverlayStyle.light.copyWith(
- statusBarColor: Colors.transparent,
- statusBarBrightness: Brightness.dark,
- statusBarIconBrightness: Brightness.light,
- systemNavigationBarDividerColor: Colors.transparent,
- systemNavigationBarColor: Colors.white,
- systemNavigationBarIconBrightness: Brightness.dark,
- );
- }
- //黑暗模式下,统一使用白色状态栏文本,黑色导航栏
- static SystemUiOverlayStyle get systemUiOverlayStyleDarkTheme {
- return SystemUiOverlayStyle.dark.copyWith(
- statusBarColor: Colors.transparent,
- statusBarBrightness: Brightness.dark,
- statusBarIconBrightness: Brightness.light,
- );
- }
- //根据上下文的亮色模式和暗色模式返回对应的 SystemUiOverlay 配置
- static SystemUiOverlayStyle getSystemUiOverlayStyleByTheme(BuildContext context) {
- late SystemUiOverlayStyle systemUiOverlayStyle;
- Brightness currentBrightness = MediaQuery.of(context).platformBrightness;
- if (currentBrightness == Brightness.dark) {
- systemUiOverlayStyle = systemUiOverlayStyleDarkTheme;
- } else {
- systemUiOverlayStyle = systemUiOverlayStyleLightThemeBlack;
- }
- return systemUiOverlayStyle;
- }
- }
|