I'm writing unit and integration tests for Flutter. Is it possible to access children/parent widgets from a given widget?
To call a function of a parent, you can use the callback pattern. In this example, a function on the color selected is passed to the child. The child calls the function when a button is pressed: import 'package:flutter/material.
Yes, you can use find.descendant
and Element.ancestorWidgetOfExactType
.
Examples:
// Finds a RichText widget that a descendant (child/grand-child/etc) of a // tab widget with text "Tab 1" find.descendant(of: find.text('Tab 1'), matching: find.byType(RichText)); // Finds a parent widget of type MyParentWidget. tester.element(find.byType(MyChildWidget)) .ancestorWidgetOfExactType(MyParentWidget);
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