flutter 设置手机自身状态栏状态

171 阅读1分钟

全局设置

Future<void> main() async {
  await GetStorage.init();
  // 初始化请求
  DioHttp();
  // 强制横屏
  WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations(
    [
      DeviceOrientation.landscapeLeft, // 横屏 Landscape 模式
      DeviceOrientation.landscapeRight,
    ],
  );
  
  SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
      //配置透明的状态栏
      statusBarColor: Colors.transparent,
      // 设置主题为黑色,light:为白色
      statusBarIconBrightness: Brightness.dark);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  
  
  runApp(const MyApp());
}