Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget test a widget which uses WidgetsBinding.instance.addPostFrameCallback()

I'm trying to do a widget test in flutter to one widget which uses WidgetsBinding.instance.addPostFrameCallback() to show a dialog at the very beggining of the widget lifecycle.

The widget works fine, but I cannot figure out how to do a widget test, because the very first expect() of the test is executed before this post frame is triggered.

Anyway to "tell" the test to wait until all the post frames are dispatched?

PD: tester.pump(), tester.pumpAndSettle(), etc. are not working.

like image 582
svprdga Avatar asked Aug 22 '19 15:08

svprdga


People also ask

Where are the widgets on flutter?

To locate widgets in a test environment, use the Finder classes. While it's possible to write your own Finder classes, it's generally more convenient to locate widgets using the tools provided by the flutter_test package.


1 Answers

But what do you know... suddenly it popped up:

    tester.binding.scheduleWarmUpFrame();

Run that :-)

Taken from here: https://chromium.googlesource.com/external/github.com/flutter/flutter/+/v0.9.2/packages/flutter/test/widgets/binding_test.dart

like image 72
christianalfoni Avatar answered Nov 15 '22 08:11

christianalfoni