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

插件详情v2.9.9

device_preview_plus

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

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.4万
喜欢数
75
Pub 分数
150

安装插件

flutter pub add device_preview_plus

插件介绍

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

Device Preview Plus 允许开发者在开发环境中直接模拟其 Flutter 应用在不同设备上的外观和行为。它提供精确的设备特定渲染,包括屏幕尺寸、方向以及平台特定的 UI 行为。该包支持多个平台——Android、iOS、Web、macOS、Windows 和 Linux——非常适合跨平台测试。通过实时预览调整和可自定义的设备配置文件,它无需物理设备即可简化 UI 验证。

适合场景

  • 在设备上测试响应式布局
  • 在各种屏幕尺寸上验证UI一致性
  • 在开发过程中模拟设备特定行为
  • 快速在设备配置文件之间切换
  • 预览应用程序在不同操作系统上的外观

主要特点

  • 实时设备模拟
  • 支持所有主要平台
  • 可自定义的设备配置文件
  • 方向和缩放调整
  • 与 Flutter 开发工具的集成
  • 跨平台 UI 测试

适合对象

  • Flutter 开发者构建跨平台应用
  • 需要快速UI验证的团队
  • 设计师与开发人员协作
  • 需要一致设备预览的项目

使用建议

  • 可能会影响大型项目中的性能
  • 需要手动配置自定义设备
  • 仅限视觉仿真(非完整运行时测试)
  • 不可替代物理设备测试
  • 最好在开发期间使用,而不是在生产环境中

原始 README

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

Device Preview for Flutter

pub package docs MIT License GitHub Actions Codacy Badge style: flutter_lints

Github-sponsors BuyMeACoffee Ko-Fi LiberaPay Patreon PayPal

This is a fork of device_preview to keep it up to date with newer Flutter versions.

For users migrating from the device_preview package the only changes required are changing your pubspec.yaml file to point to device_preview_plus and changing any import statements to point to the updated package:device_preview_plus\device_preview_plus.dart.

Device Preview for Flutter

Approximate how your app looks and performs on another device. Main features:

  • Preview any device from any device
  • Change the device orientation
  • Dynamic system configuration (language, dark mode, text scaling factor, ...)
  • Freeform device with adjustable resolution and safe areas
  • Keep the application state
  • Plugin system (Screenshot, File explorer, ...)
  • Customizable plugins

Getting Started

Add this to your project's pubspec.yaml file:

dependencies:
  device_preview_plus: ^2.9.4

Usage

Wrap your app's root widget in a DevicePreview and make sure to :

  • Set your app's useInheritedMediaQuery to true.
  • Set your app's builder to DevicePreview.appBuilder.
  • Set your app's locale to DevicePreview.locale(context).

Make sure to override the previous properties as described. If not defined, MediaQuery won't be simulated for the selected device.

import 'package:device_preview_plus/device_preview_plus.dart';

void main() => runApp(
  DevicePreview(
    enabled: !kReleaseMode,
    builder: (context) => MyApp(), // Wrap your app
  ),
);

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      useInheritedMediaQuery: true,
      locale: DevicePreview.locale(context),
      builder: DevicePreview.appBuilder,
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      home: const HomePage(),
    );
  }
}

Demo

Open the demo

Limitations

Think of Device Preview as a first-order approximation of how your app looks and feels on a mobile device. With Device Mode you don't actually run your code on a mobile device. You simulate the mobile user experience from your laptop, desktop or tablet.

There are some aspects of mobile devices that Device Preview will never be able to simulate. When in doubt, your best bet is to actually run your app on a real device.

所属分类

依赖

依赖清单 7 项

源码仓库

使用此插件的项目