搜索插件、代码仓与 APP 分类

debug_overlay 封面
插件详情v2.0.0

debug_overlay

通过应用程序中的中心叠加层查看调试信息并更改设置。

AndroidiOS
近 30 天下载
767
喜欢数
28
Pub 分数
160

安装插件

flutter pub add debug_overlay

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

debug_overlay 包为 Flutter 应用提供了一个集中式的覆盖层,用于在开发过程中动态显示调试信息并调整设置。它使开发者能够实时查看应用指标、切换功能并检查状态,而无需重新启动应用。该覆盖层可通过简单手势访问,并可无缝集成到 Android 和 iOS 构建中。设计简洁易用,通过在应用界面内快速访问诊断数据和可配置选项,提升了调试工作流程的效率。

适合场景

  • 开发过程中的实时调试
  • 实时切换应用功能
  • 监控应用程序性能指标
  • 检查状态更改
  • 测试不同的配置
  • 快速访问调试工具

主要特点

  • 集中式调试叠加层
  • 基于手势的激活
  • 实时设置调整
  • Android 和 iOS 平台支持
  • 使用 pub add 进行最小化设置
  • 运行时应用信息显示

适合对象

  • Flutter 开发者在积极开发中
  • 需要快速调试的团队
  • 需要动态功能开关的应用程序
  • 原型设计和测试阶段
  • 开发人员在调试期间专注于用户体验

使用建议

  • 不适用于生产环境
  • 叠加层可能在测试期间干扰用户界面
  • 发布前需要手动移除
  • 有限的自定义选项
  • 无内置安全机制保护敏感的调试数据
  • 在大型应用中可能略微影响性能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

debug_overlay

🐛 View debug infos and change settings via a central overlay for your app.

debug_overlay demo

To add a debug overlay to your app, pass DebugOverlay.builder() to MaterialApp/CupertinoApp/WidgetsApp.builder:

MaterialApp(
  builder: DebugOverlay.builder(),
  // And other customization...
)

The debug overlay only works in debug mode and is not included in your widget tree in profile or release mode unless you pass enableOnlyInDebugMode: false.

To open the overlay, call DebugOverlay.show().

By default, this overlay includes MediaQueryDebugHelper, PackageInfoDebugHelper, and DeviceInfoDebugHelper.

Debug Helpers

To add a debug helper, you have to register it by calling either of the following two (which accept any sliver widget):

  • DebugOverlay.prependHelper(myDebugHelper) to add it to the front of the list
  • DebugOverlay.appendHelper(myDebugHelper) to add it to the end of the list

Or, if you want to override all currently registered overlays, set DebugOverlay.helpers.value to a list of sliver widget.

DeviceInfoDebugHelper
DeviceInfoDebugHelper demo

Displays information obtained from device_info_plus.

MediaQueryDebugHelper
´MediaQueryDebugHelper demo

Displays information obtained from MediaQuery.

LogsDebugHelper
´LogsDebugHelper demo

Displays logs generated by your app. To use it, follow these steps:

  1. Store its mutable state, e.g., in a global variable:

    final logs = LogCollection(
      // Default values:
      maximumSize: 500,
      onlyStoreLogsInDebugMode: true,
    );
    
  2. Register the helper and supply its state, e.g., in main():

    void main() {
      if (kDebugMode) {
        DebugOverlay.appendHelper(LogsDebugHelper(logs));
      }
    
      runApp(MyApp());
    }
    
  3. When you generate logs, add them to the collection. Except for message, all parameters are optional:

    logs.add(Log(
      level: DiagnosticLevel.info,
      timestamp: DateTime.now(),
      message: 'My message',
      error: myException,
      stackTrace: myStackTrace,
    ));
    

The error field can also hold data for non-error logs. If it stores JSON data (on an object with a toJson() method), the data can be inspected using json_view.

MediaOverridesDebugHelper
´MediaOverridesDebugHelper demo

This allows you to override the theme mode and locale of your app. To use it, follow these steps:

  1. Store its mutable state, e.g., in a global variable:

    final mediaOverrideState = ValueNotifier(MediaOverrideState());
    
  2. Register the helper and supply its state, e.g., in main():

    void main() {
      if (kDebugMode) {
        DebugOverlay.prependHelper(MediaOverrideDebugHelper(
          mediaOverrideState,
          // To support overriding locales, this value must be set and should
          // contain the same locales as passed to [MaterialApp.supportedLocales],
          // [CupertinoApp.supportedLocales] or [WidgetsApp.supportedLocales].
          supportedLocales: supportedLocales,
        ));
      }
    
      runApp(MyApp());
    }
    
  3. When building your MaterialApp/CupertinoApp/WidgetsApp, wrap it in a ValueListenableBuilder that uses the state from step 1:

    ValueListenableBuilder<MediaOverrideState>(
      valueListenable: mediaOverrideState,
      builder: (context, overrideState, child) {
        return MaterialApp(
          // You can access overridden values via [overrideState]:
          themeMode: overrideState.themeMode,
          locale: overrideState.locale,
    
          builder: DebugOverlay.builder(),
          supportedLocales: supportedLocales,
    
          // And your other customizations...
        );
      },
    );
    
PackageInfoDebugHelper
PackageInfoDebugHelper demo

Displays information obtained from package_info_plus.

Custom

To implement your own debug helper, you can use the provided DebugHelper class for the layout.

If your information can be represented with Flutter's DiagnosticsNode, you can use DiagnosticsBasedDebugHelper which automatically provides filtering. This is also used internally by DeviceInfoDebugHelper, MediaQueryDebugHelper, and PackageInfoDebugHelper.

所属分类

依赖

依赖清单 9 项

源码仓库

使用此插件的项目

暂无相关数据。