Home > Software engineering >  Cant remove Debug Show Checked Banner
Cant remove Debug Show Checked Banner

Time:02-27

I used the debugShowCheckedModeBanner: false, code to remove the debug banner and it had worked fine with all of my previous apps. But now when I used this code only the shadow under debug banner get removed. Here's my code

  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomeScreen(),
    );
  }
}

I have attached the images link of debugShowCheckedModeBanner: false, and debugShowCheckedModeBanner: true,below.

How can I remove this debug banner completely, please help!

CodePudding user response:

Try below code hope its help to you.

Remove MaterialApp Widget from HomeScreen Class

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: HomeScreen(),
        ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('E Com App'),
      ),
      body: Container(
        color: Colors.red,
        height: 200,
        width: double.infinity,
        child: Text(
          'Red Container',
          style: TextStyle(
            fontSize: 30,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}

Your Result Screen-> image

If you want MaterialApp Widget in HomeScreen class then add below line inside MaterialApp in HomeScreen Class.

 debugShowCheckedModeBanner: false,

Full Widget:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: HomeScreen(),
        ),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text('E Com App'),
        ),
        body: Container(
          color: Colors.red,
          height: 200,
          width: double.infinity,
          child: Text(
            'Red Container',
            style: TextStyle(fontSize: 30, color: Colors.white),
          ),
        ),
      ),
    );
  }
}

CodePudding user response:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
//this code add it 
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: Center(
              child: HomeScreen(),
            ),
          ),
        );
      }
    }
  • Related