user3808307
user3808307

Reputation: 1549

Add id to element in Flutter

The tester needs to have an id on flutter Elements. I am looking at the documentation and this is what I found

https://api.dart.dev/stable/2.10.2/dart-html/Element/id.html

But I can't figure how to do this. I try for example

Padding(
  id: "some id",
  // ...
)

And of course it doesn't work. Is there a way to add an id for the test automation?

Thank you

Upvotes: 2

Views: 9038

Answers (2)

Sebastian Garzon
Sebastian Garzon

Reputation: 304

you need to add keys into your widgets, for example if I want to test when I use an API and render a card into a ListView builder, I can find the card with a key

This link is all you need: https://flutter.dev/docs/cookbook/testing/widget/finders

PD: you are looking for the wrong documentation, search the documentation of Flutter, no Dart

Upvotes: 2

Akif
Akif

Reputation: 7640

You need to use the key properties of the related widgets. You can look at this example.

   child: Text(
        'Go to next route',
        key: Key('next_route_key'),
      ),

Or for a FloatingActionButton:

   floatingActionButton: FloatingActionButton(
       // Provide a Key to this button. This allows finding this
       // specific button inside the test suite, and tapping it.
       key: Key('increment'),
       onPressed: () => plusClickSink.add(null),
       tooltip: 'Increment',
       child: Icon(Icons.add),
     ),       

Upvotes: 1

Related Questions