flutter_flutter/examples/api/test/widgets/basic/indexed_stack.0_test.dart
Kate Lovett a04fb324be
Bump Dart to 3.8 and reformat (#171703)
Bumps the Dart version to 3.8 across the repo (excluding
engine/src/flutter/third_party) and applies formatting updates from Dart
3.8.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-07-07 17:58:32 +00:00

113 lines
4.4 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/basic/indexed_stack.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('has correct forward rendering mechanism', (WidgetTester tester) async {
await tester.pumpWidget(const example.IndexedStackApp());
final Finder gesture2 = find.byKey(const Key('gesture2'));
final Element containerFinder = find
.byKey(const Key('Dash'), skipOffstage: false)
.evaluate()
.first;
expect(containerFinder.renderObject!.debugNeedsPaint, false);
final Element containerFinder1 = find
.byKey(const Key('John'), skipOffstage: false)
.evaluate()
.first;
expect(containerFinder1.renderObject!.debugNeedsPaint, true);
final Element containerFinder2 = find
.byKey(const Key('Mary'), skipOffstage: false)
.evaluate()
.first;
expect(containerFinder2.renderObject!.debugNeedsPaint, true);
await tester.tap(gesture2);
await tester.pump();
expect(containerFinder.renderObject!.debugNeedsPaint, false);
expect(containerFinder1.renderObject!.debugNeedsPaint, false);
expect(containerFinder2.renderObject!.debugNeedsPaint, true);
await tester.tap(gesture2);
await tester.pump();
expect(containerFinder.renderObject!.debugNeedsPaint, false);
expect(containerFinder1.renderObject!.debugNeedsPaint, false);
expect(containerFinder2.renderObject!.debugNeedsPaint, false);
});
testWidgets('has correct backward rendering mechanism', (WidgetTester tester) async {
await tester.pumpWidget(const example.IndexedStackApp());
final Finder gesture1 = find.byKey(const Key('gesture1'));
final Element containerFinder = find
.byKey(const Key('Dash'), skipOffstage: false)
.evaluate()
.first;
final Element containerFinder1 = find
.byKey(const Key('John'), skipOffstage: false)
.evaluate()
.first;
final Element containerFinder2 = find
.byKey(const Key('Mary'), skipOffstage: false)
.evaluate()
.first;
await tester.tap(gesture1);
await tester.pump();
expect(containerFinder.renderObject!.debugNeedsPaint, false);
expect(containerFinder1.renderObject!.debugNeedsPaint, true);
expect(containerFinder2.renderObject!.debugNeedsPaint, false);
await tester.tap(gesture1);
await tester.pump();
expect(containerFinder.renderObject!.debugNeedsPaint, false);
expect(containerFinder1.renderObject!.debugNeedsPaint, false);
expect(containerFinder2.renderObject!.debugNeedsPaint, false);
});
testWidgets('has correct element addition handling', (WidgetTester tester) async {
await tester.pumpWidget(const example.IndexedStackApp());
expect(find.byType(example.PersonTracker), findsOneWidget);
expect(find.byType(example.PersonTracker, skipOffstage: false), findsNWidgets(3));
final Finder textField = find.byType(TextField);
await tester.enterText(textField, 'hello');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();
expect(find.byType(example.PersonTracker, skipOffstage: false), findsNWidgets(4));
await tester.enterText(textField, 'hello1');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();
expect(find.byType(example.PersonTracker, skipOffstage: false), findsNWidgets(5));
});
testWidgets('has state preservation', (WidgetTester tester) async {
await tester.pumpWidget(const example.IndexedStackApp());
final Finder gesture1 = find.byKey(const Key('gesture1'));
final Finder gesture2 = find.byKey(const Key('gesture2'));
final Finder containerFinder = find.byKey(const Key('Dash'));
final Finder incrementFinder = find.byKey(const Key('incrementDash'));
Finder counterFinder(int score) {
return find.descendant(of: containerFinder, matching: find.text('Score: $score'));
}
expect(counterFinder(0), findsOneWidget);
await tester.tap(incrementFinder);
await tester.pump();
expect(counterFinder(1), findsOneWidget);
await tester.tap(gesture2);
await tester.pump();
await tester.tap(gesture1);
await tester.pump();
expect(counterFinder(1), findsOneWidget);
expect(counterFinder(0), findsNothing);
});
}