搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。