mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add tests for restorable_value.0.dart API example. (#148676)
This PR contributes to https://github.com/flutter/flutter/issues/130459 ### Description - Updates `examples/api/lib/widgets/restoration_properties/restorable_value.0.dart` to meet the latest API examples structure - Adds tests for `examples/api/lib/widgets/restoration_properties/restorable_value.0.dart`
This commit is contained in:
parent
fe0932f2c0
commit
3beeed4929
@ -388,7 +388,6 @@ final Set<String> _knownMissingTests = <String>{
|
|||||||
'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart',
|
'examples/api/test/widgets/scroll_position/scroll_metrics_notification.0_test.dart',
|
||||||
'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart',
|
'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart',
|
||||||
'examples/api/test/widgets/async/future_builder.0_test.dart',
|
'examples/api/test/widgets/async/future_builder.0_test.dart',
|
||||||
'examples/api/test/widgets/restoration_properties/restorable_value.0_test.dart',
|
|
||||||
'examples/api/test/widgets/animated_switcher/animated_switcher.0_test.dart',
|
'examples/api/test/widgets/animated_switcher/animated_switcher.0_test.dart',
|
||||||
'examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart',
|
'examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart',
|
||||||
'examples/api/test/widgets/transitions/positioned_transition.0_test.dart',
|
'examples/api/test/widgets/transitions/positioned_transition.0_test.dart',
|
||||||
|
@ -13,14 +13,13 @@ class RestorableValueExampleApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WidgetsApp(
|
return MaterialApp(
|
||||||
title: 'RestorableValue Sample',
|
home: Scaffold(
|
||||||
color: const Color(0xffffffff),
|
appBar: AppBar(
|
||||||
builder: (BuildContext context, Widget? child) {
|
title: const Text('RestorableValue Sample'),
|
||||||
return const Center(
|
),
|
||||||
child: RestorableValueExample(restorationId: 'main'),
|
body: const RestorableValueExample(restorationId: 'main'),
|
||||||
);
|
),
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,9 +71,11 @@ class _RestorableValueExampleState extends State<RestorableValueExample> with Re
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return OutlinedButton(
|
return Center(
|
||||||
|
child: OutlinedButton(
|
||||||
onPressed: _incrementAnswer,
|
onPressed: _incrementAnswer,
|
||||||
child: Text('${_answer.value}'),
|
child: Text('${_answer.value}'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ void main() {
|
|||||||
return button.style?.foregroundColor?.resolve(<WidgetState>{});
|
return button.style?.foregroundColor?.resolve(<WidgetState>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
testWidgets('increments and decrements value', (WidgetTester tester) async {
|
testWidgets('Increments and decrements value', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const example.ActionsExampleApp(),
|
const example.ActionsExampleApp(),
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
// 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/restoration_properties/restorable_value.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Increments answer on OutlinedButton tap', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.RestorableValueExampleApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify that the initial answer value in the example equals 42.
|
||||||
|
expect(find.text('42'), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap the button to increment the answer value by 1.
|
||||||
|
await tester.tap(find.byType(OutlinedButton));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
// Verify that the answer value increased by 1.
|
||||||
|
expect(find.text('43'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Restores answer value after restart', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const MaterialApp(
|
||||||
|
home: RootRestorationScope(
|
||||||
|
restorationId: 'root',
|
||||||
|
child: example.RestorableValueExample(restorationId: 'child'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// The initial answer value in the example equals 42.
|
||||||
|
expect(find.text('42'), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap the button 10 times to change the answer value.
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
await tester.tap(find.byType(OutlinedButton));
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that the answer value increased by 10.
|
||||||
|
expect(find.text('52'), findsOneWidget);
|
||||||
|
|
||||||
|
// Simulate restoring the state of the widget tree after the application
|
||||||
|
// is restarted.
|
||||||
|
await tester.restartAndRestore();
|
||||||
|
|
||||||
|
// Verify that the answer value is restored correctly.
|
||||||
|
expect(find.text('52'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user