WidgetController class Null safety

Class that programmatically interacts with widgets.

For a variant of this class suited specifically for unit tests, see WidgetTester. For one suitable for live tests on a device, consider LiveWidgetController.

Concrete subclasses must implement the pump method.

Implementers

Constructors

WidgetController(WidgetsBinding binding)
Creates a widget controller that uses the given binding.

Properties

allElements Iterable<Element>
All elements currently in the widget tree (lazy pre-order traversal).
read-only
allRenderObjects Iterable<RenderObject>
Render objects of all the widgets currently in the widget tree (lazy pre-order traversal).
read-only
allStates Iterable<State<StatefulWidget>>
All states currently in the widget tree (lazy pre-order traversal).
read-only
allWidgets Iterable<Widget>
All widgets currently in the widget tree (lazy pre-order traversal).
read-only
binding WidgetsBinding
A reference to the current instance of the binding.
final
hashCode int
The hash code for this object.
read-onlyinherited
layers List<Layer>
Returns a list of all the Layer objects in the rendering.
read-only
nextPointer int
The next available pointer identifier.
read-only
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

any(Finder finder) bool
Checks if finder exists in the tree.
createGesture({int? pointer, PointerDeviceKind kind = PointerDeviceKind.touch, int buttons = kPrimaryButton}) Future<TestGesture>
Creates gesture and returns the TestGesture object which you can use to continue the gesture using calls on the TestGesture object.
drag(Finder finder, Offset offset, {int? pointer, int buttons = kPrimaryButton, double touchSlopX = kDragSlopDefault, double touchSlopY = kDragSlopDefault, bool warnIfMissed = true, PointerDeviceKind kind = PointerDeviceKind.touch}) Future<void>
Attempts to drag the given widget by the given offset, by starting a drag in the middle of the widget.
dragFrom(Offset startLocation, Offset offset, {int? pointer, int buttons = kPrimaryButton, double touchSlopX = kDragSlopDefault, double touchSlopY = kDragSlopDefault, PointerDeviceKind kind = PointerDeviceKind.touch}) Future<void>
Attempts a drag gesture consisting of a pointer down, a move by the given offset, and a pointer up.
dragUntilVisible(Finder finder, Finder view, Offset moveStep, {int maxIteration = 50, Duration duration = const Duration(milliseconds: 50)}) Future<void>
Repeatedly drags view by moveStep until finder is visible.
element<T extends Element>(Finder finder) → T
The matching element in the widget tree.
elementList<T extends Element>(Finder finder) Iterable<T>
The matching elements in the widget tree.
ensureSemantics() SemanticsHandle
Enable semantics in a test by creating a SemanticsHandle.
ensureVisible(Finder finder) Future<void>
Given a widget W specified by finder and a Scrollable widget S in its ancestry tree, this scrolls S so as to make W visible.
firstElement<T extends Element>(Finder finder) → T
The first matching element according to a depth-first pre-order traversal of the widget tree.
firstRenderObject<T extends RenderObject>(Finder finder) → T
The render object of the first matching widget according to a depth-first pre-order traversal of the widget tree.
firstState<T extends State<StatefulWidget>>(Finder finder) → T
The first matching state according to a depth-first pre-order traversal of the widget tree.
firstWidget<T extends Widget>(Finder finder) → T
The first matching widget according to a depth-first pre-order traversal of the widget tree.
fling(Finder finder, Offset offset, double speed, {int? pointer, int buttons = kPrimaryButton, Duration frameInterval = const Duration(milliseconds: 16), Offset initialOffset = Offset.zero, Duration initialOffsetDelay = const Duration(seconds: 1), bool warnIfMissed = true}) Future<void>
Attempts a fling gesture starting from the center of the given widget, moving the given distance, reaching the given speed.
flingFrom(Offset startLocation, Offset offset, double speed, {int? pointer, int buttons = kPrimaryButton, Duration frameInterval = const Duration(milliseconds: 16), Offset initialOffset = Offset.zero, Duration initialOffsetDelay = const Duration(seconds: 1)}) Future<void>
Attempts a fling gesture starting from the given location, moving the given distance, reaching the given speed.
getBottomLeft(Finder finder, {bool warnIfMissed = false, String callee = 'getBottomLeft'}) Offset
Returns the point at the bottom left of the given widget. This point is not inside the object's hit test area.
getBottomRight(Finder finder, {bool warnIfMissed = false, String callee = 'getBottomRight'}) Offset
Returns the point at the bottom right of the given widget. This point is not inside the object's hit test area.
getCenter(Finder finder, {bool warnIfMissed = false, String callee = 'getCenter'}) Offset
Returns the point at the center of the given widget.
getRect(Finder finder) Rect
Returns the rect of the given widget. This is only valid once the widget's render object has been laid out at least once.
getSemantics(Finder finder) SemanticsNode
Attempts to find the SemanticsNode of first result from finder.
getSize(Finder finder) Size
Returns the size of the given widget. This is only valid once the widget's render object has been laid out at least once.
getTopLeft(Finder finder, {bool warnIfMissed = false, String callee = 'getTopLeft'}) Offset
Returns the point at the top left of the given widget.
getTopRight(Finder finder, {bool warnIfMissed = false, String callee = 'getTopRight'}) Offset
Returns the point at the top right of the given widget. This point is not inside the object's hit test area.
handlePointerEventRecord(List<PointerEventRecord> records) Future<List<Duration>>
A simulator of how the framework handles a series of PointerEvents received from the Flutter engine.
hitTestOnBinding(Offset location) HitTestResult
Forwards the given location to the binding's hitTest logic.
layerListOf(Finder finder) Iterable<Layer>
Find all layers that are children of the provided finder.
longPress(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) Future<void>
Dispatch a pointer down / pointer up sequence (with a delay of kLongPressTimeout + kPressTimeout between the two events) at the center of the given widget, assuming it is exposed.
longPressAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) Future<void>
Dispatch a pointer down / pointer up sequence at the given location with a delay of kLongPressTimeout + kPressTimeout between the two events.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
press(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) Future<TestGesture>
Dispatch a pointer down at the center of the given widget, assuming it is exposed.
printToConsole(String message) → void
Calls debugPrint with the given message.
protected">@protected
pump([Duration duration]) Future<void>
Called to indicate that there should be a new frame after an optional delay.
pumpAndSettle([Duration duration = const Duration(milliseconds: 100)]) Future<int>
Repeatedly calls pump with the given duration until there are no longer any frames scheduled. This will call pump at least once, even if no frames are scheduled when the function is called, to flush any pending microtasks which may themselves schedule a frame.
renderObject<T extends RenderObject>(Finder finder) → T
The render object of the matching widget in the widget tree.
renderObjectList<T extends RenderObject>(Finder finder) Iterable<T>
The render objects of the matching widgets in the widget tree.
scrollUntilVisible(Finder finder, double delta, {Finder? scrollable, int maxScrolls = 50, Duration duration = const Duration(milliseconds: 50)}) Future<void>
Repeatedly scrolls a Scrollable by delta in the Scrollable.axisDirection direction until a widget matching finder is visible.
sendEventToBinding(PointerEvent event) Future<void>
Forwards the given pointer event to the binding.
sendKeyDownEvent(LogicalKeyboardKey key, {String platform = _defaultPlatform, String? character, PhysicalKeyboardKey? physicalKey}) Future<bool>
Simulates sending a physical key down event.
sendKeyEvent(LogicalKeyboardKey key, {String platform = _defaultPlatform, String? character, PhysicalKeyboardKey? physicalKey}) Future<bool>
Simulates sending physical key down and up events.
sendKeyRepeatEvent(LogicalKeyboardKey key, {String platform = _defaultPlatform, String? character, PhysicalKeyboardKey? physicalKey}) Future<bool>
Simulates sending a key repeat event from a physical keyboard.
sendKeyUpEvent(LogicalKeyboardKey key, {String platform = _defaultPlatform, PhysicalKeyboardKey? physicalKey}) Future<bool>
Simulates sending a physical key up event through the system channel.
startGesture(Offset downLocation, {int? pointer, PointerDeviceKind kind = PointerDeviceKind.touch, int buttons = kPrimaryButton}) Future<TestGesture>
Creates a gesture with an initial down gesture at a particular point, and returns the TestGesture object which you can use to continue the gesture.
state<T extends State<StatefulWidget>>(Finder finder) → T
The matching state in the widget tree.
stateList<T extends State<StatefulWidget>>(Finder finder) Iterable<T>
The matching states in the widget tree.
tap(Finder finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) Future<void>
Dispatch a pointer down / pointer up sequence at the center of the given widget, assuming it is exposed.
tapAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) Future<void>
Dispatch a pointer down / pointer up sequence at the given location.
timedDrag(Finder finder, Offset offset, Duration duration, {int? pointer, int buttons = kPrimaryButton, double frequency = 60.0, bool warnIfMissed = true}) Future<void>
Attempts to drag the given widget by the given offset in the duration time, starting in the middle of the widget.
timedDragFrom(Offset startLocation, Offset offset, Duration duration, {int? pointer, int buttons = kPrimaryButton, double frequency = 60.0}) Future<void>
Attempts a series of PointerEvents to simulate a drag operation in the duration time.
toString() String
A string representation of this object.
inherited
widget<T extends Widget>(Finder finder) → T
The matching widget in the widget tree.
widgetList<T extends Widget>(Finder finder) Iterable<T>
The matching widgets in the widget tree.

Operators

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

Static Properties

hitTestWarningShouldBeFatal bool
Whether warnings relating to hit tests not hitting their mark should be fatal (cause the test to fail).
read / write