開發(fā)語言:Dart
開發(fā)生態(tài):Flutter
準(zhǔn)備工作
方案需要使用到插件device_info_plus: ^latest_version,在pubspec.yaml內(nèi)添加此插件
dependencies:
device_info_plus: $last_version
實(shí)現(xiàn)方法
/// 對(duì)于狀態(tài)欄、導(dǎo)航欄的整體處理
static Future<void> redoSystemStyle() async {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
));
if (Platform.isAndroid) {
var darkMode = window.platformBrightness == Brightness.dark;
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
final bool edgeToEdge = androidInfo.version.sdkInt != null &&
androidInfo.version.sdkInt! >= 29;
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: edgeToEdge
? Colors.transparent
: darkMode
? Colors.black
: Colors.white,
systemNavigationBarContrastEnforced: true,
systemNavigationBarIconBrightness:
darkMode ? Brightness.light : Brightness.dark,
));
}
}
小白的進(jìn)階之路,感謝大家的支持!