Reputation: 6140
After added SplashScreen in Flutter
, Statusbar not showing in the main activity.
If I open 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>
issue arrise because of this = >
<item name="android:windowFullscreen">true</item>
How to set full screen only for SplashScreen and show status bar for all other screens?
flutter code
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);
}
Upvotes: 3
Views: 2102
Reputation: 2220
You should write a MethodChannel, just like:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void showHideStatusBar(boolean show, Activity activity){
if (show == false){
View decorView = activity.getWindow().getDecorView();
// Hide Status Bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Log.e("flutter","隐藏statusBar");
}else{
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
activity.getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE);
Log.e("flutter","显示statusBar");
}
}
and call this native method in your "initState" method!
Upvotes: 0
Reputation: 12703
Remove <item name="android:windowFullscreen">true</item>
and try this.
class SplashScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
return Scaffold(
body: Center(
child: Text("Hello"),
),
floatingActionButton: FloatingActionButton(
onPressed: (){
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => HomeScreen()));
},
),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
return Scaffold(
body: Center(
child: Text("Home Screen"),
),
);
}
}
Upvotes: 0
Reputation: 8239
Try out my below code
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",
),
),
],
),
),
);
}
this one for more info :
// to hide only bottom bar:
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.top]);
// to hide only status bar:
SystemChrome.setEnabledSystemUIOverlays ([SystemUiOverlay.bottom]);
// to hide both:
SystemChrome.setEnabledSystemUIOverlays ([]);
Upvotes: 2