mardi 27 novembre 2018

How to find the order of a Stack during testing in Flutter?

Say I have a Stack of widgets that are not the same:

return Stack(
  children: <Widget>[
    Container(),
    Text('Hey'),
    Positioned(top: 300.0, child: CustomWidget()),
  ],

);

How do I test the order of the child widgets? I could assign keys to each item, but how can I tell which item appears in front of another?

I could assign a key to my Stack, wrap each child in a Positioned, and then use find.byKey(stackKey) to get my Stack, and then use find.byType(Positioned) to get its children. This returns an Iterable which I can convert to a List. But, is find.byType() guaranteed to return the same order each time?

Aucun commentaire:

Enregistrer un commentaire