mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR cleans up a bunch of files for the cross imports, in one big change, per offline discussion. The following files have been fixed: - debug_test.dart - dual_transition_builder_test.dart - listener_test.dart - placeholder_test.dart - rotated_box_test.dart - run_app_async_test.dart - run_app_test.dart - scroll_activity_test.dart - scroll_position_test.dart - scrollable_dispose_test.dart - semantics_test.dart - shape_decoration_test.dart - simple_semantics_test.dart - sliver_list_test.dart - slivers_padding_test.dart - syncing_test.dart - text_semantics_test.dart Part of https://github.com/flutter/flutter/issues/177415 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## 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]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] 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]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- 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
193 lines
5.2 KiB
Dart
193 lines
5.2 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/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
class TestWidget extends StatefulWidget {
|
|
const TestWidget({
|
|
super.key,
|
|
required this.child,
|
|
required this.persistentState,
|
|
required this.syncedState,
|
|
});
|
|
|
|
final Widget child;
|
|
final int persistentState;
|
|
final int syncedState;
|
|
|
|
@override
|
|
TestWidgetState createState() => TestWidgetState();
|
|
}
|
|
|
|
class TestWidgetState extends State<TestWidget> {
|
|
late int persistentState;
|
|
late int syncedState;
|
|
int updates = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
persistentState = widget.persistentState;
|
|
syncedState = widget.syncedState;
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(TestWidget oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
syncedState = widget.syncedState;
|
|
// we explicitly do NOT sync the persistentState from the new instance
|
|
// because we're using that to track whether we got recreated
|
|
updates += 1;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => widget.child;
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('no change', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: TestWidget(persistentState: 1, syncedState: 0, child: Container()),
|
|
),
|
|
),
|
|
);
|
|
|
|
final TestWidgetState state = tester.state(find.byType(TestWidget));
|
|
|
|
expect(state.persistentState, equals(1));
|
|
expect(state.updates, equals(0));
|
|
|
|
await tester.pumpWidget(
|
|
ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: TestWidget(persistentState: 2, syncedState: 0, child: Container()),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(state.persistentState, equals(1));
|
|
expect(state.updates, equals(1));
|
|
|
|
await tester.pumpWidget(Container());
|
|
});
|
|
|
|
testWidgets('remove one', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: ColoredBox(
|
|
color: const Color(0xFF0000FF),
|
|
child: TestWidget(persistentState: 10, syncedState: 0, child: Container()),
|
|
),
|
|
),
|
|
);
|
|
|
|
TestWidgetState state = tester.state(find.byType(TestWidget));
|
|
|
|
expect(state.persistentState, equals(10));
|
|
expect(state.updates, equals(0));
|
|
|
|
await tester.pumpWidget(
|
|
ColoredBox(
|
|
color: const Color(0xFF00FF00),
|
|
child: TestWidget(persistentState: 11, syncedState: 0, child: Container()),
|
|
),
|
|
);
|
|
|
|
state = tester.state(find.byType(TestWidget));
|
|
|
|
expect(state.persistentState, equals(11));
|
|
expect(state.updates, equals(0));
|
|
|
|
await tester.pumpWidget(Container());
|
|
});
|
|
|
|
testWidgets('swap instances around', (WidgetTester tester) async {
|
|
const Widget a = TestWidget(
|
|
persistentState: 0x61,
|
|
syncedState: 0x41,
|
|
child: Text('apple', textDirection: TextDirection.ltr),
|
|
);
|
|
const Widget b = TestWidget(
|
|
persistentState: 0x62,
|
|
syncedState: 0x42,
|
|
child: Text('banana', textDirection: TextDirection.ltr),
|
|
);
|
|
await tester.pumpWidget(const Column());
|
|
|
|
final GlobalKey keyA = GlobalKey();
|
|
final GlobalKey keyB = GlobalKey();
|
|
|
|
await tester.pumpWidget(
|
|
Column(
|
|
children: <Widget>[
|
|
Container(key: keyA, child: a),
|
|
Container(key: keyB, child: b),
|
|
],
|
|
),
|
|
);
|
|
|
|
TestWidgetState first, second;
|
|
|
|
first = tester.state(find.byWidget(a));
|
|
second = tester.state(find.byWidget(b));
|
|
|
|
expect(first.widget, equals(a));
|
|
expect(first.persistentState, equals(0x61));
|
|
expect(first.syncedState, equals(0x41));
|
|
expect(second.widget, equals(b));
|
|
expect(second.persistentState, equals(0x62));
|
|
expect(second.syncedState, equals(0x42));
|
|
|
|
await tester.pumpWidget(
|
|
Column(
|
|
children: <Widget>[
|
|
Container(key: keyA, child: a),
|
|
Container(key: keyB, child: b),
|
|
],
|
|
),
|
|
);
|
|
|
|
first = tester.state(find.byWidget(a));
|
|
second = tester.state(find.byWidget(b));
|
|
|
|
// same as before
|
|
expect(first.widget, equals(a));
|
|
expect(first.persistentState, equals(0x61));
|
|
expect(first.syncedState, equals(0x41));
|
|
expect(second.widget, equals(b));
|
|
expect(second.persistentState, equals(0x62));
|
|
expect(second.syncedState, equals(0x42));
|
|
|
|
// now we swap the nodes over
|
|
// since they are both "old" nodes, they shouldn't sync with each other even though they look alike
|
|
|
|
await tester.pumpWidget(
|
|
Column(
|
|
children: <Widget>[
|
|
Container(key: keyA, child: b),
|
|
Container(key: keyB, child: a),
|
|
],
|
|
),
|
|
);
|
|
|
|
first = tester.state(find.byWidget(b));
|
|
second = tester.state(find.byWidget(a));
|
|
|
|
expect(first.widget, equals(b));
|
|
expect(first.persistentState, equals(0x61));
|
|
expect(first.syncedState, equals(0x42));
|
|
expect(second.widget, equals(a));
|
|
expect(second.persistentState, equals(0x62));
|
|
expect(second.syncedState, equals(0x41));
|
|
});
|
|
}
|