微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果最初在视口之外,如何测试Widget是否已渲染

如何解决如果最初在视口之外,如何测试Widget是否已渲染

我有这个自定义的Widget组件:

class CollectAssetDataButton extends StatelessWidget {
  const CollectAssetDataButton({ Key key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RaisedButton(
        child: Text(
      context
          .translate(I18NKeys.appointmentDetails.collectAssetsData)
          .toupperCase(),),onpressed: () {},);
  }
}

我正在尝试使用:

  final collectAssetsButtonFinder = find.byKey(WidgetKeysAppointmentDetails.collectAssetsButton);
  expect(collectAssetsButtonFinder,findsOneWidget);

根据https://github.com/flutter/flutter/issues/54651

中的建议

但是我仍然得到:

══╡ EXCEPTION CAUGHT BY FlutteR TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
  Expected: exactly one matching node in the widget tree
  Actual: _KeyFinder:<zero widgets with key [<'___appointment_details_collect_assets_button___'>]
(ignoring offstage widgets)>
   Which: means none were found but one was expected

谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。