Closed rehlma closed 7 months ago
By default, spot() only finds widgets that are "onstage", not hidden with the Offstage widget.
spot()
Offstage
To find offstage widgets, start your widget selector with spotOffstage(). Search for both - the on- and offstage widgets - with spotAllWidgets().
spotOffstage()
spotAllWidgets()
For existing selectors, use overrideWidgetPresence(WidgetPresence presence) to modify the presence to offstage, onstage or combined.
overrideWidgetPresence(WidgetPresence presence)
offstage
onstage
combined
import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:spot/spot.dart'; void main() { testWidgets('Spot offstage and combined widgets', (tester) async { await tester.pumpWidget( MaterialApp( home: Row( children: [ Text('a'), Text('b'), Offstage(child: Text('c')), ], ), ), ); spot<Text>().withText('a').existsOnce(); spot<Text>().withText('c').doesNotExist(); spot<Text>().withText('c').overrideWidgetPresence(WidgetPresence.offstage).existsOnce(); spotOffstage().spot<Text>().atMost(3); spotOffstage().spotText('c').existsOnce(); spotOffstage().overrideWidgetPresence(WidgetPresence.onstage).spotText('c').doesNotExist(); spotAllWidgets().spotText('a').existsOnce(); spotAllWidgets().spotText('c').existsOnce(); spotOffstage().overrideWidgetPresence(WidgetPresence.combined).spotText('a').existsOnce(); spotOffstage().overrideWidgetPresence(WidgetPresence.combined).spotText('c').existsOnce(); }); }
By default,
spot()
only finds widgets that are "onstage", not hidden with theOffstage
widget.To find offstage widgets, start your widget selector with
spotOffstage()
. Search for both - the on- and offstage widgets - withspotAllWidgets()
.For existing selectors, use
overrideWidgetPresence(WidgetPresence presence)
to modify the presence tooffstage
,onstage
orcombined
.