i try to unittest a small own widget:
testWidgets('MyWidget has a title and message', (WidgetTester tester) async {
var text = "abc";
var label = "def";
await tester.pumpWidget(LabeledTextWidget(
text,
label: label,
));
final textFinder = find.text(text);
final labelFinder = find.text(label);
expect(textFinder , findsOneWidget);
expect(labelFinder, findsOneWidget);
});
Here is the widget code:
class LabeledTextWidget extends StatelessWidget {
final String text;
final String label;
LabeledTextWidget(this.text, {this.label});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(label,style: Theme.of(context).textTheme.caption,),
Text(text),
],
);
}
The test always throws the exception:
...
No Directionality widget found.
RichText widgets require a Directionality widget ancestor.
The specific widget that could not find a Directionality ancestor was:
RichText
...
I can avoid this error by adding a text direction to all Text-Widgets. (textDirection: TextDirection.ltr,), but i thats a bad solution and it doesn´t work with rows.