Skip to content

Instantly share code, notes, and snippets.

@PROGrand
Created December 5, 2022 23:42
Show Gist options
  • Save PROGrand/85f72406765eb69087a037d2775634e4 to your computer and use it in GitHub Desktop.
Save PROGrand/85f72406765eb69087a037d2775634e4 to your computer and use it in GitHub Desktop.
Flutter: how to solve timeout on tester.pumpAndSettle()

Just insert it before bad tester.pumpAndSettle() and analyze output.

  await TestAsyncUtils.guard<int>(() async {
    final DateTime endTime =
        tester.binding.clock.fromNowBy(Duration(seconds: 30));
    int count = 0;
    do {
      if (tester.binding.clock.now().isAfter(endTime)) {
        break;
      }
      await tester.binding.pump(
          Duration(milliseconds: 100), EnginePhase.sendSemanticsUpdate);
      count += 1;
    } while (tester.binding.hasScheduledFrame);
    return count;
  });

  debugProfilePaintsEnabled = true;
  debugPrintBeginFrameBanner = true;
  debugPrintEndFrameBanner = true;
  debugProfileLayoutsEnabled = true;
  debugPrintLayouts = true;
  debugPrintMarkNeedsLayoutStacks = true;
  debugPrintRebuildDirtyWidgets = true;

  debugDumpApp();

  await TestAsyncUtils.guard<int>(() async {
    final DateTime endTime =
        tester.binding.clock.fromNowBy(Duration(seconds: 1));
    int count = 0;
    do {
      if (tester.binding.clock.now().isAfter(endTime)) {
        break;
      }
      await tester.binding.pump(
          Duration(milliseconds: 100), EnginePhase.sendSemanticsUpdate);
      count += 1;
    } while (tester.binding.hasScheduledFrame);
    return count;
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment