0

I want to select a specific date of birth on the calendar but, firstly I have to assert which date is now, and then tap in the loop until the particular month (September) on the calendar is visible. The challenge is I cannot use expect(actual, matcher) as a condition in the loop because it does not store value true or false.

My idea was something like this

static selectMonth(WidgetTester tester) async {
    final now = DateTime.now();

    final september = find.text('September');

    var month = expect(september, findsOneWidget);

    if (now.month < 9) {
      while (month == true) {
        await ScreenTest.tapChevronRightIcon(tester);
      }
      await ScreenTest.tapDay(
        tester,
        dayOfBirth,
      );
    } else if (now.month > 9) {
      while (month == true) {
        await ScreenTest.tapChevronLeftIcon(tester);
      }
      await ScreenTest.tapDay(
        tester,
        dayOfBirth,
      );
    } else {
      await ScreenTest.tapDay(
        tester,
        dayOfBirth,
      );
    }
  }
wojnarto
  • 411
  • 4
  • 9

1 Answers1

0

I've found a workaround. Instead of while (month == true) I used tester.any(Locator). This solution finds text on the screen and returns false or true.

wojnarto
  • 411
  • 4
  • 9