首页 > 解决方案 > 如果添加 Splashscreen,Flutter 中其他屏幕的状态栏不会显示

问题描述

在添加 SplashScreen 后Flutter,状态栏未显示在主活动中。

如果我打开 style.xml

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:windowFullscreen">true</item>
</style>

因为这个问题出现=> <item name="android:windowFullscreen">true</item>

如何仅为 SplashScreen 设置全屏并为所有其他屏幕显示状态栏?

颤振代码

import 'package:flutter/material.dart';
import 'package:sixbrix/screens/login.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    return MaterialApp(
      debugShowCheckedModeBanner: true,
      title: 'Flutter',
      theme: ThemeData(
        primarySwatch: createMaterialColor(Color(0xFFD96332)),
      ),
      home: MyHomePage(title: 'Flutter App'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
    return Scaffold(
      body: Text("Hello"),
    );
  }
}

MaterialColor createMaterialColor(Color color) {
  List strengths = <double>[.05];
  Map swatch = <int, Color>{};
  final int r = color.red, g = color.green, b = color.blue;

  for (int i = 1; i < 10; i++) {
    strengths.add(0.1 * i);
  }
  strengths.forEach((strength) {
    final double ds = 0.5 - strength;
    swatch[(strength * 1000).round()] = Color.fromRGBO(
      r + ((ds < 0 ? r : (255 - r)) * ds).round(),
      g + ((ds < 0 ? g : (255 - g)) * ds).round(),
      b + ((ds < 0 ? b : (255 - b)) * ds).round(),
      1,
    );
  });
  return MaterialColor(color.value, swatch);
}

标签: androidiosflutterdart

解决方案


试试我下面的代码

import 'package:flutter/services.dart'; 

@override
Widget build(BuildContext context) {

 SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); //add this line 
   return Scaffold(
   backgroundColor: Colors.white,
   body: Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Image.asset(
          'images/splash_logo.png',
          width: 50.0,
          height: 100.0,
          fit: BoxFit.contain,
        ),
        SizedBox(
          height: 10.0,
        ),
        Text(
          "Any",
          ),
        ),
      ],
     ),
    ),
  );
}

这个了解更多信息:

// to hide only bottom bar:
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.top]);

// to hide only status bar: 
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.bottom]);

// to hide both:
SystemChrome.setEnabledSystemUIOverlays ([]);

推荐阅读