You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Flutter应用中的Slow Load Banner(Material组件场景)

How to Remove the Slow Load/Debug Banner When Using Material Instead of MaterialApp

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:00:27