I've been trying to test an element that when an IconButton is pressed, a Text object changes to a TextFormField. When I try to test this I get the following error:
A Timer is still pending even after the widget tree was disposed.
'package:flutter_test/src/binding.dart': Failed assertion: line 672 pos 7:
'_fakeAsync.nonPeriodicTimerCount == 0'
Despite the widget not using any timers that I'm aware of?
Example code:
await tester.tap(find.byType(IconButton));
await tester.pump();
expect(find.byType(TextFormField), findsOneWidget);
await tester.pump();
await tester.enterText(find.byType(EditableText), "0.2");
I'm really not sure what's causing the issue but if I remove the last 2 lines it runs fine (although I don't get to actually test my input).
The issue was that the text field used had a 300ms delay so that the keyboard can scroll into view and then the app can scroll to the textfield. I completely ignored that the text field has this delay and didn't account for it.
Adding
await tester.pump(Duration(milliseconds:400));
worked exactly as intended.
Assign Key To the EditableText
new EditableText(
key: new Key('mySpecialEditableText1234'),
controller: myCtrl,
style: myStyle,
focusNode: myFocusNode,
)
and access this widget in your test as:
find.byKey(new Key('mySpecialEditableText1234'))
If this doesn't find your Widget, your tester
instance is probably not pumping the correct widget
NOTE: Make sure you are going through correct navigation path. You cannot directly pump a widget that is not first in the tree
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With