搜尋套件、儲存庫與 APP 分類

media_query_preview 封面
套件詳情v0.1.0

media_query_preview

此套件可於各種裝置與條件下進行UI預覽,支援自訂裝置、亮度與文字縮放。適合開發使用,不適用於生產環境。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
14
喜歡數
3
Pub 分數
140

安裝套件

flutter pub add media_query_preview

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

MediaQueryPreview 是一個開發工具,可於不同裝置、螢幕尺寸、亮度層級與文字縮放下即時預覽 UI。它幫助開發者在不部署至實體裝置的情況下,直觀地查看應用程式在各種設定下的外觀。此套件支援自訂裝置定義,專為開發工作流程設計,不適用於生產環境。它與 Flutter 的 MediaQuery 無縫整合,便於在設計與測試階段快速迭代。

適用情境

  • 測試響應式佈局
  • 模擬不同的設備螢幕
  • 調整可存取性設定
  • 在各種條件下驗證UI行為
  • 簡化UI開發工作流程

主要特色

  • 支援自訂裝置設定
  • 即時預覽螢幕尺寸變更
  • 可調節亮度和文字縮放
  • 跨平台相容性
  • 與現有 Flutter 項目輕鬆整合

適合對象

  • Flutter 開發者在設計階段
  • 專注於響應式 UI 的團隊
  • 可存取性測試
  • 快速原型設計

使用建議

  • 不適用於生產環境
  • 需要手動設定以支援自訂裝置
  • 僅限開發環境
  • 在大量使用期間可能影響效能
  • 不取代實際裝置測試

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

pub package GitHub deployments

Have you ever experienced your UI breaking when the font size is too large or the screen size of the device is small? Checking for these issues can be a hassle.

This package allows you to preview how your implemented UI will appear on various devices with different screen sizes, text scales, and brightness.

It was inspired by device_preview.

Media Query Preview

Features

This package provides the following features:

  • Preview your UI on various devices with different screen sizes, text scales, and brightness.
  • In addition to pre-defined devices like PreviewDevice.iPhone5_5inch and PreviewDevice.android6_7inch, you can create custom PreviewDevice instances.
  • Preview your UI when the keyboard is displayed.
  • Manipulate each preview individually.
  • Friendly with riverpod.

Demo

Check out the demo at https://kingu-dev.github.io/media_query_preview.

Usage

If you are using riverpod, you can do the following.

// Initialize Provider
final container = ProviderContainer();

final previewDevices = [
  [
    PreviewDevice.iPhone5_5inch(
      textScaleFactor: 0.5,
    ),
    PreviewDevice.iPhone5_5inch(),
    PreviewDevice.iPhone5_5inch(
      brightness: Brightness.dark,
    ),
    PreviewDevice.iPhone5_5inch(
      textScaleFactor: 1.5,
    ),
  ],
  [
    PreviewDevice.iPhone6_7inch(
      textScaleFactor: 0.5,
    ),
    PreviewDevice.iPhone6_7inch(),
    PreviewDevice.iPhone6_7inch(
      brightness: Brightness.dark,
    ),
    PreviewDevice.iPhone6_7inch(
      textScaleFactor: 1.5,
    ),
  ],
  [
    PreviewDevice.android6_7inch(
      textScaleFactor: 0.5,
    ),
    PreviewDevice.android6_7inch(),
    PreviewDevice.android6_7inch(
      brightness: Brightness.dark,
    ),
    PreviewDevice.android6_7inch(
      textScaleFactor: 1.5,
    ),
  ]
];

runApp(
  MediaQueryPreview(
    previewDevices: previewDevices,
    builder: (_, previewDevice) {
      // If you want to change the theme based on the targetPlatform,
      // you can get the targetPlatform from [previewDevice.targetPlatform].
      return UncontrolledProviderScope(
        container: container,
        child: const MyApp(),
      );
    },
  ),
);

If you are not using riverpod, it is even simpler.

runApp(
  MediaQueryPreview(
    previewDevices: previewDevices,
    builder: (_, previewDevice) {
      // If you want to change the theme based on the targetPlatform,
      // you can get the targetPlatform from [previewDevice.targetPlatform].
      return const MyApp();
    },
  ),
);

Attention

  • It is recommended to use this package only development. Please do not use it in production.
  • This package allows you to display multiple instances of the Widget you implemented at the same time, which may lead to poor performance or issues with state management.
  • If you manage GlobalKey with global variables, they will be shared across each preview, which can lead to errors or unintended behavior. Since the widget trees of each preview are independent, it is recommended to generate a separate GlobalKey for each tree.

Future

If you have Apple Vision Pro, you can use it as a "Designed for iPad" app. This is the future!

Vision Pro

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。