DevicePreview class

Simulates how the result of builder would render on different devices.

{@tool snippet}

This sample shows how to define an app with a plugin.

DevicePreview(
  builder: (context) => MaterialApp(
     useInheritedMediaQuery: true,
     locale: DevicePreview.locale(context),
     builder: DevicePreview.appBuilder,
     theme: ThemeData.light(),
     darkTheme: ThemeData.dark(),
     home: const Home(),
   ),
)

{@end-tool}

See also :

  • Devices has a set of predefined common devices.
Inheritance

Constructors

DevicePreview({Key? key, required WidgetBuilder builder, List<DeviceInfo>? devices, DevicePreviewData? data, bool isToolbarVisible = true, List<Locale>? availableLocales, DeviceInfo? defaultDevice, List<Widget> tools = defaultTools, DevicePreviewStorage? storage, bool enabled = true, Color? backgroundColor})
Create a new DevicePreview.
const

Properties

availableLocales List<Locale>?
The available locales.
final
backgroundColor Color?
The background color of the canvas
final
builder WidgetBuilder
The previewed widget.
final
data DevicePreviewData?
The configuration. If not precised, it is loaded from preferences.
final
defaultDevice DeviceInfo?
The default selected device when opening device preview for the first time.
final
devices List<DeviceInfo>?
The available devices used for previewing.
final
enabled bool
If not enabled, the child is used directly.
final
hashCode int
The hash code for this object.
no setterinherited
isToolbarVisible bool
Indicates whether the tool bar should be visible or not.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storage DevicePreviewStorage?
The storage used to persist preferences.
final
tools List<Widget>
The list of available tools.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _DevicePreviewState
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

defaultDevices List<DeviceInfo>
All the default available devices.
final

Static Methods

allLocales(BuildContext context) List<Locale>
All available locales in the tool.
appBuilder(BuildContext context, Widget? child) Widget
Create a new ThemeData from the given data, but with updated properties from the currently simulated device.
availableDeviceIdentifiers(BuildContext context) List<DeviceIdentifier>
The list of all available device identifiers.
hideToolbar(BuildContext context, {bool disablePreview = true}) → void
Hide the toolbar.
isEnabled(BuildContext context) bool
Indicates whether the device preview is currently enabled.
locale(BuildContext context) Locale?
Currently defined locale.
platform(BuildContext context) TargetPlatform
The simulated target platform for the currently selected device.
screenshot(BuildContext context) Future<DeviceScreenshot>
Take a screenshot.
selectDevice(BuildContext context, DeviceIdentifier deviceIdentifier) → void
Select a device from its unique deviceIdentifier.
selectedDevice(BuildContext context) DeviceInfo
The currently selected device.
showToolbar(BuildContext context, {bool enablePreview = true}) → void
Make the toolbar visible to the user.
visualDensity(BuildContext context) VisualDensity
The simulated visual density for the currently selected device.

Constants

defaultTools → const List<Widget>
All the default tools included in the menu : DeviceSection, SystemSection, AccessibilitySection and SettingsSection.