Preview class base

Annotation used to mark functions that return a widget preview.

NOTE: this interface is not stable and will change.

Functions annotated with @Preview() must return a Widget or WidgetBuilder and be public. This annotation can only be applied to top-level functions, static methods defined within a class, and public Widget constructors and factories with no required arguments.
link
@Preview(name: 'Top-level preview')
Widget preview() => const Text('Foo');

@Preview(name: 'Builder preview')
WidgetBuilder builderPreview() {
  return (BuildContext context) {
    return const Text('Builder');
  };
}

class MyWidget extends StatelessWidget {
  @Preview(name: 'Constructor preview')
  const MyWidget.preview({super.key});

  @Preview(name: 'Factory constructor preview')
  factory MyWidget.factoryPreview() => const MyWidget.preview();

  @Preview(name: 'Static preview')
  static Widget previewStatic() => const Text('Static');

  @override
  Widget build(BuildContext context) {
    return const Text('MyWidget');
  }
}

Important Note: all values provided to the @Preview() annotation must be constant and non-private.

Constructors

Preview.new({String? name, Size? size, double? textScaleFactor, WidgetWrapper? wrapper, PreviewTheme? theme, Brightness? brightness, PreviewLocalizations? localizations})
Annotation used to mark functions that return widget previews.
const

Properties

brightness Brightness?
Sets the initial theme brightness.
final
hashCode int
The hash code for this object.
no setterinherited
localizations PreviewLocalizations?
A callback to return a localization configuration to be applied to the previewed Widget.
final
name String?
A description to be displayed alongside the preview.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size Size?
Artificial constraints to be applied to the previewed widget.
final
textScaleFactor double?
Applies font scaling to text within the previewed widget.
final
theme PreviewTheme?
A callback to return Material and Cupertino theming data to be applied to the previewed Widget.
final
wrapper WidgetWrapper?
Wraps the previewed Widget in a Widget tree.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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