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
link
@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.
@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');
}
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
Artificial height constraint 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
- textScaleFactor → double?
-
Applies font scaling to text within the previewed widget.
final
- width → double?
-
Artificial width constraint to be applied to the previewed widget.
final
- wrapper → Widget Function(Widget)?
-
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