-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Use case
An IndexedStack only ever shows one of its children. Other children aren't rendered or hit-tested. In this sense, I think these other children could be considered off-stage.
However, a finder in widget tests will still find every children:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('should only find current widget', (WidgetTester tester) async {
// Only the `1` text widget will be shown
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: IndexedStack(
index: 1,
children: [for (var i = 0 ; i < 10;i++) Text('$i')],
),
));
expect(find.text('1'), findsOneWidget);
expect(find.text('2'), findsNothing); // This currently fails, I believe it should pass
expect(find.text('2', skipOffstage: false), findsOneWidget); // This should continue to pass
});
}Proposal
I believe it would be more intuitive for IndexedStack to override debugVisitOnstageChildren so that it only reports the currently-active child.
ahmdaeyz, silverhairs and Gustl22
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version