简体   繁体   English

Flutter:在集成测试中无法单击列表视图项

[英]Flutter: Can't click listview item on integration test

I have an app with a listview feature with provider pattern, and it has 5 items of data.我有一个具有提供程序模式的列表视图功能的应用程序,它有 5 项数据。 Here is my snippet code这是我的代码段

    ListView.builder(
      key: Key("listview_portfolio"),
      itemBuilder: (context, index) =>
          _itemListPortofolio(data.items[index], context),
      itemCount: data.items.length,
    )

... ...

    Widget _itemListPortofolio(Portfolio portfolio, BuildContext context) {
      return Container(
        key: ValueKey("item_list_portfolio"),
        margin: EdgeInsets.only(bottom: 16),
        child: InkWell(

When I run this code, it doesn't throw an error, but when I do the integration test, it throws an error when trying to click the item listview当我运行此代码时,它不会引发错误,但是当我进行集成测试时,它会在尝试单击项目列表视图时引发错误

'package:flutter_test/src/binding.dart': Failed assertion: line 802 pos 14: '_pendingExceptionDetails:= null'. 'package:flutter_test/src/binding.dart':断言失败:第 802 行 pos 14:'_pendingExceptionDetails:= null'。 A test overrode FlutterError,onError but either failed to return it to its original state.测试覆盖了 FlutterError,onError 但未能将其返回到其原始 state。 or had unexpected additional errors that it could not handle, Typically.或有无法处理的意外附加错误,通常情况下。 this is caused by using expect() before restoring FlutterError.onError: flutter: dart.core-patch/errors_patch:dart 51.61 _AssertionError._doThrowNew这是由在恢复 FlutterError.onError 之前使用 expect() 引起的:flutter: dart.core-patch/errors_patch:dart 51.61 _AsserError._doThrowtionNew

here's my integration test class这是我的集成测试 class

    Future<void> tapPortfolioItem({bool scrollUp = false}) async {
        await _tester.pumpAndSettle(Duration(seconds: 5));
        final Widget itemPortfolio =
            find.byKey(ValueKey("item_list_portfolio")).evaluate().last.widget;

        await _tester.tap(find.byWidget(itemPortfolio));
      }

try the code below:试试下面的代码:

final Finder instance = find.byKey(ValueKey("item_list_portifolio"));
final _itemListPortofolio test = _tester.widget(instance);
await _tester.tap(instance);
expect(anything, findsOneWidget);
expect(test.color, Colors.red);  

see also other way to use pumpAndSeatle() here .另请参阅此处使用pumpAndSeatle()的其他方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM