'Flutter app is going to full screen by default without any logic. How to stop going into full screen
My flutter app is going to full screen by default. How can I prevent this?
I do not have any code to enable the full-screen mode.
But still, it is going to full screen by default. It is happening in both Android and IOS.
Don't know how to resolve this.
Below is the complete code in my simple app.
Updated the code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() async {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
initState() {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
super.initState();
}
@override
void dispose() {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
super.dispose();
}
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.bottom,SystemUiOverlay.top]);
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: darkMode ? lightTheme : lightTheme,
title: "APP SYDNEY",
initialRoute: '/',
routes: Navigate.routes,
);
}
}
class Pending extends StatelessWidget {
const Pending({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.tealAccent, Colors.white])),
child: Center(
child: Text(
'I am yet to be constructed',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.teal, fontSize: size.height * 0.017),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.pop(context);
},
child: const Icon(Icons.home),
tooltip: 'Home',
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
}
class Navigate {
static Map<String, Widget Function(BuildContext)> routes = {
'/': (context) => const Pending()
};
}
Solution 1:[1]
Just try this,
To set full screen put this code in initState()
SystemChrome.setEnabledSystemUIOverlays([]);
and to set back to normal. In dispose()
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
in the same class.
@override
void dispose() {
SystemChrome.setEnabledSys`enter code here`temUIOverlays(SystemUiOverlay.values);
super.dispose();
}
@override
initState() {
SystemChrome.setEnabledSystemUIOverlays([]);
super.initState();
}
Solution 2:[2]
add this code in main.dart put after Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
example
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
return MaterialApp(
but if you change your mind and want to make the screen full screen, use the following code
SystemChrome.setEnabledSystemUIOverlays([]);
Update:
results will vary depending on the type of smartphone. The error does not come from your code, but from the smartphone settings itself. Take a look at the picture below, only on Android Tiramisu fullscreen, but on Android Lollipop and Android S, the code runs fine
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manishyadav |
| Solution 2 |

