搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。