MaterialWidgetDirector<Args> class
A specialized TestDirector for testing individual Flutter widgets that require basic Material Design context.
This director automatically wraps the target widget with Material and Directionality, providing the necessary context for Material Design widgets to function properly in tests.
Usage:
void main() {
late MaterialWidgetDirector<(String, VoidCallback)> director;
setUp(() {
director = MaterialWidgetDirector<(String, VoidCallback)>()
..setUnitFactory((args) => MyButton(text: args.$1, onPressed: args.$2));
});
testWidgets('MyButton displays and functions correctly', (WidgetTester tester) async {
bool pressed = false;
director.setArgs(('Test Button', () => pressed = true));
await tester.pumpWidget(director.construct());
await tester.tap(find.byType(MyButton));
expect(pressed, isTrue);
});
}
@test For a complete example, see:
- Inheritance
-
- Object
- TestDirector<
Widget, Args> - MaterialWidgetDirector
Constructors
Properties
- args ↔ Args
-
The built arguments, available after buildArgs is called.
latefinalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- unit ↔ Widget
-
The built unit, available after buildUnit is called.
latefinalinherited
Methods
-
addUnitArrangement(
Widget arrangement(Widget)) → void -
Adds an arrangement function to modify or wrap the unit after its initial creation.
inherited
-
buildArgs(
) → Args -
Builds the arguments using either the set args or the args factory.
inherited
-
buildUnit(
Args args) → Widget -
Builds the unit using the factory and applies all arrangements.
inherited
-
construct(
{Args? args}) → Widget -
Constructs the
Unitusing the providedArgs.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setArgs(
Args args) → void -
Sets the arguments directly.
inherited
-
setArgsFactory(
covariant ArgsFactory< Args> argsFactory) → void -
Sets the factory function used to create arguments.
inherited
-
setUnitFactory(
UnitFactory< Widget, Args> unitFactory) → void -
Sets the factory function used to create the initial unit.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
useDirectionality(
[TextDirection textDirection = TextDirection.ltr]) → void -
useMaterial(
) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited