如何移除Flutter应用中的Slow Load Banner(Material组件场景)
Got it, since you're using the Material widget directly instead of MaterialApp, you can't rely on the handy debugShowCheckedModeBanner property that MaterialApp provides. But don't worry—there are two straightforward ways to get rid of that banner:
1. Wrap Your Material Widget with CheckedModeBanner
The CheckedModeBanner is the underlying widget that MaterialApp uses to display the debug banner. You can use it directly to toggle the banner for your Material subtree:
CheckedModeBanner( showBanner: false, child: Material( // Your existing Material widget content goes here child: Scaffold( appBar: AppBar(title: const Text('My App')), body: const Center(child: Text('No debug banner here!')), ), ), )
This approach lets you control the banner for just this specific Material tree, which is great if you only want to hide it in part of your app.
2. Globally Disable the Banner for the Entire App
If you want to turn off the banner everywhere in your debug build, you can set a global override at the start of your app:
import 'package:flutter/material.dart'; void main() { // Disable the debug banner globally debugCheckModeBannerOverride = false; runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return Material( child: Scaffold( appBar: AppBar(title: const Text('Global Banner Disabled')), body: const Center(child: Text('No banner anywhere!')), ), ); } }
Note that the debug banner won't appear in release builds automatically—these solutions are only needed for debug mode when you want a cleaner preview.
内容的提问来源于stack exchange,提问作者harsha20599

