I am developing some intregration tests for one of my flutter-web application. I wanted to specifically locate the container(width: 50, height: 50) in the following below widget hierarchy tree considering top to bottom approach. ParentWidget --> Row --> Text, SizedBox, Row --> Container(), Container(width: 50, height: 50), Container(). Note: Without key approach
I tried to locate using descendant of ParentWidget --> Row --> Row --> with index tried to select the 2nd container, but this isn't working, it fails with error "Bad state: No element".
import 'package:flutter/material.dart';
class ParentWidget extends StatelessWidget {
const ParentWidget({Key? key});
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("Hello World..!!"),
SizedBox(
width: 20,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
width: 20,
height: 20,
color: Colors.red,
),
Container(
width: 50,
height: 50,
color: Colors.red,
),
Container(
width: 20,
height: 20,
color: Colors.red,
),
],
),
],
);
}
}
final container = tester.widget<Container>(find.descendant(
of: find.descendant(
of: find.byType(ParentWidget), matching: find.byType(Row)),
matching: find.descendant(
of: find.byType(Row), matching: find.byType(Container).at(1))));