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

device_preview 封面
插件详情v3.0.0

device_preview

大致预览您的 Flutter 应用在另一台设备上的外观和性能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
22.6万
喜欢数
4270
Pub 分数
150

安装插件

flutter pub add device_preview

插件介绍

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

Device Preview 是一个 Flutter 包,允许开发者在开发环境中直接模拟其应用在不同设备上的外观和行为。它提供实时设备仿真,包括屏幕尺寸、方向、平台以及暗色模式等系统设置。这有助于确保在各种设备上保持一致的用户界面,而无需使用实体硬件。该包支持多个平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常适合跨平台测试。

适合场景

  • 在各种设备上测试用户界面的响应能力
  • 模拟不同的屏幕尺寸和方向
  • 验证深色模式和平台特定行为
  • 预览应用在各种设备类型上的外观
  • 跨平台 UI 一致性检查

主要特点

  • 实时设备模拟
  • 对多平台的支持
  • 动态设备选择
  • 方向和主题模拟
  • 与 Flutter DevTools 集成

适合对象

  • Flutter 开发人员测试 UI 布局
  • 致力于跨平台应用的团队
  • 设计师验证响应式设计
  • 开发人员确保可访问性和可用性

使用建议

  • 不可替代物理设备测试
  • 性能可能因复杂界面而有所不同
  • 仅限视觉和行为模拟
  • 不复制网络或硬件条件

原始 README

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

Device Preview for Flutter

Simulate any device — screen, safe areas, locale, accessibility — with full framework fidelity.

You build on one screen; your users arrive on hundreds. Device Preview switches your running app to another device — an old 320pt phone, a tablet in landscape, a notched display, a half-width desktop window — instantly, with no rebuild and no simulator.

Screen size, pixel ratio, safe areas, orientation, folds, the software keyboard, locales, brightness, text scale, accessibility settings and target platform all change with it, and your app reads them through the same MediaQuery it always used. So the problems that normally surface in front of a customer — a clipped headline, a button under the home indicator, an overflow at 200% text — surface in front of you instead.

Control it from Flutter DevTools, from Dart, or from your tests.

Quickstart

dependencies:
  device_preview: <latest version>
void main() {
  DevicePreview.enable();
  runApp(const MyApp()); // runs as usual — now simulatable
}

That's the whole integration. Open DevTools, select the device_preview tab, and pick a device.

enable() is safe to call unconditionally: simulation is active in debug and profile builds and completely off in release, so nothing ships to your users. Pass a value to decide yourself — DevicePreview.enable(enabled: kDebugMode) for debug only, DevicePreview.enable(enabled: false) to turn it off.

Programmatic control:

import 'package:device_preview/presets.dart';

final c = DevicePreview.controller;
await c.applyPreset(DevicePresets.iPhone16Pro);
await c.setOrientation(Orientation.landscape);
await c.update((s) => s.copyWith(textScaleFactor: 2.0, platformBrightness: Brightness.dark));
await c.reset();

DevicePreview.controller throws when simulation is off (every release build); use DevicePreview.maybeController?.… from code that ships.

See device_preview/README.md for the full package documentation, including widget-test support via DevicePreviewBindingMixin.

Documentation

Open the website · Design document

Repository structure

Directory Contents
device_preview The published package: binding, controller, presets, service extensions, bundled DevTools extension build.
device_preview_devtools_extension Source of the DevTools extension web app (never published; built into device_preview/extension/devtools/build).
device_specs The device catalog: one JSON per device — metrics, screen outline and body artwork. Generated into both the extension catalog and the package's built-in DevicePresets; see its README to add a device.
device_frame Legacy device frame drawings package from the 2.x era. Nothing in the 3.0 release depends on it — 3.0 renders frames from the device_specs artwork, carried by the built-in presets and pushed over the DevTools protocol.
docs The website, including its interactive demo — docs/demo is the counter example built for the web, docs/device_catalog.json the catalog its HTML panel pushes to it. Rebuild both with tool/build_demo.sh.

所属分类

源码仓库

使用此插件的项目