lundi 25 novembre 2019

How to test a Flutter widget's intrinsic size

I have a custom text widget and I am trying to test that the widget has a certain intrinsic size for some text string.

void main() {
  testWidgets('MongolRichText has correct size for string', (WidgetTester tester) async {
    await tester.pumpWidget(MongolRichText(text: TextSpan(text: 'hello'),));

    final finder = find.byType(MongolRichText);
    expect(finder, findsOneWidget);

    // How do I check the size?
  });
}

How do I check the intrinsic size of the widget?

I'm not trying to limit the screen size as in this question.

I found the answer in the Flutter source code, so I am posting this as a Q&A pair. My answer is below.

Aucun commentaire:

Enregistrer un commentaire