【问题标题】:Add id to element in Flutter在 Flutter 中为元素添加 id
【发布时间】:2021-02-09 17:16:31
【问题描述】:

测试者需要在 Flutter Elements 上有一个 id。我正在查看文档,这就是我发现的

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

但我不知道该怎么做。例如我试试

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

当然它不起作用。有没有办法为测试自动化添加一个 id?

谢谢

【问题讨论】:

    标签: flutter automated-tests flutter-layout flutter-web


    【解决方案1】:

    您需要使用相关小部件的关键属性。你可以看看this example

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

    或者对于 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),
         ),       
    

    【讨论】:

      【解决方案2】:

      您需要在小部件中添加密钥,例如,如果我想测试何时使用 API 并将卡片呈现到 ListView 构建器中,我可以找到带有密钥的卡片

      这个链接就是你所需要的:https://flutter.dev/docs/cookbook/testing/widget/finders

      PD:你找错文档了,搜索Flutter的文档,没有Dart

      【讨论】:

        猜你喜欢
        • 2018-11-04
        • 2012-07-11
        • 2018-07-24
        • 1970-01-01
        • 1970-01-01
        • 2022-01-17
        • 2016-02-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多