Home > Software design >  Flutter app is going to full screen by default without any logic. How to stop going into full screen
Flutter app is going to full screen by default without any logic. How to stop going into full screen

Time:02-21

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 code in my simple app.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() async {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
        overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      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()
  };
}

CodePudding user response:

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([]);

CodePudding user response:

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();
  }
  • Related