Skip to content

Commit a196557

Browse files
FEATURE: Add itemSetup to Gallery so that a single setup can be applied to all items.
1 parent ae42541 commit a196557

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/src/scenes/gallery.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ class Gallery {
3232
BoxConstraints? itemConstraints,
3333
Finder? itemBoundsFinder,
3434
required SceneLayout layout,
35+
GoldenSetup? itemSetup,
3536
}) : _fileName = fileName,
3637
_sceneDescription = sceneDescription,
3738
_itemScaffold = itemScaffold,
3839
_itemConstraints = itemConstraints,
3940
_itemBoundsFinder = itemBoundsFinder,
40-
_layout = layout {
41+
_layout = layout,
42+
_itemSetup = itemSetup {
4143
_directory = directory ?? GoldenSceneTheme.current.directory;
4244
}
4345

@@ -84,6 +86,12 @@ class Gallery {
8486
/// 3. `find.byType(GoldenImageBounds)`.
8587
final Finder? _itemBoundsFinder;
8688

89+
/// An optional setup method that runs after pumping an item's tree, and just before the
90+
/// item is screenshotted.
91+
///
92+
/// This setup runs for every item in the scene unless an individual item overrides it.
93+
final GoldenSetup? _itemSetup;
94+
8795
/// Requests for all screenshots within this scene, by their ID.
8896
final _requests = <String, GalleryGoldenRequest>{};
8997

@@ -353,7 +361,7 @@ class Gallery {
353361
}
354362

355363
// Run the item's setup function, if there is one.
356-
await item.setup?.call(tester);
364+
await (item.setup ?? _itemSetup)?.call(tester);
357365

358366
// Take a screenshot.
359367
expect(item.boundsFinder, findsOne);

0 commit comments

Comments
 (0)