flutterandroid-timepicker

How to select a time in flutters time picker from integration test


I'm writing an integration test for a flutter app where I need to open the time picker and select a time, Its a time picker dialog in android, I can tap the time above the picker and tap the ok and cancel buttons but I cannot change the selected time for the dial. Looking at their widget test they're testing it using an offset which I'm not sure how to do this from an integration test. I've created a demo and took a screenshot of the flutter widget tree where you can see the dial and gesture detector etc but there aren't any keys to find and trying to find by text isn't possible either, digging into the source code they create a list of _TappableLabel which gets the text from the painter, does anyone have a way to do this?

flutter widget tree


Solution

  • Inspired from the timepicker unit test, thats doable that way :

        var center = tester
            .getCenter(find.byKey(const ValueKey<String>('time-picker-dial')));
    
        await tester.tapAt(Offset(center.dx - 10, center.dy));
    
    

    Since the dial accept clicking close to the center, the 10 offset is enough to select 9 in that case.