flutter_glove_box
flutter_glove_box copied to clipboard
Support asynchronous Scenarios
I'm trying to assemble a golden sheet of button states: normal, pressed, and disabled.
For a pressed button state, I need to orchestrate a tap, but there doesn't appear to be any place within a standard Scenario to do this. A Widget is expected. There should probably be an option for a function that returns Future<Widget> or something like that.
It looks like a DeviceScenario supports onCreate, which might allow for this, but onCreate is not offered for regular scenarios.
@matthew-carroll I think this can be accomplished with the GoldenBuilder or the DeviceScenario option.
Here is an pseudo-code example with just the golden builder:
testGoldens('GRID: Different weather types without frame', (tester) async {
final gb = GoldenBuilder.grid(
columns: 2,
bgColor: Colors.white,
widthToHeightRatio: 1,
)
..addScenario(
'Normal', const WeatherCard(temp: 37, weather: Weather.rain))
..addScenario(
'Pressed', const WeatherCard(key: Key('click_me'), temp: 37, weather: Weather.rain))
..addScenario(
'Disabled',
const WeatherCard(temp: 25, weather: Weather.cold, enabled: false),
);
await tester.pumpWidgetBuilder(
gb.build(),
surfaceSize: const Size(500, 500),
);
await tester.press(find.byKey(const Key('click_me')));
await tester.pump(const Duration(milliseconds: 300));
await screenMatchesGolden(tester, 'weather_types_grid');
});
@coreysprague I think this is a use case we need to document in our examples.
That approach seems to work.