1

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()
  };
}
2
  • please provide text source code instead of screenshot Commented Feb 20, 2022 at 13:37
  • @swifthing I have update the code Commented Feb 20, 2022 at 13:48

2 Answers 2

3

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

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

the latest format of this code is : SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]); . But still, it is not working. I have updated my question with the code which I am using.
please see my reply update
I saw your reply. I tried everything. Still no luck. Updated my code in the question once again with latest changes.
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();
  }

1 Comment

Hi Manish, I tried your suggestion, but no luck. I have the complete code in my question. Can you try once and see what problem it has

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.