diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 263a7ff24246..dc45fce90c6f 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -388,7 +388,6 @@ final Set _knownMissingTests = { '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/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/transitions/relative_positioned_transition.0_test.dart', 'examples/api/test/widgets/transitions/positioned_transition.0_test.dart', diff --git a/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart b/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart index f16a6994f928..3f7de573e77b 100644 --- a/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart +++ b/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart @@ -13,14 +13,13 @@ class RestorableValueExampleApp extends StatelessWidget { @override Widget build(BuildContext context) { - return WidgetsApp( - title: 'RestorableValue Sample', - color: const Color(0xffffffff), - builder: (BuildContext context, Widget? child) { - return const Center( - child: RestorableValueExample(restorationId: 'main'), - ); - }, + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('RestorableValue Sample'), + ), + body: const RestorableValueExample(restorationId: 'main'), + ), ); } } @@ -72,9 +71,11 @@ class _RestorableValueExampleState extends State with Re @override Widget build(BuildContext context) { - return OutlinedButton( - onPressed: _incrementAnswer, - child: Text('${_answer.value}'), + return Center( + child: OutlinedButton( + onPressed: _incrementAnswer, + child: Text('${_answer.value}'), + ), ); } } diff --git a/examples/api/test/widgets/actions/actions.0_test.dart b/examples/api/test/widgets/actions/actions.0_test.dart index e2e5f03ec51e..1aa359203e5b 100644 --- a/examples/api/test/widgets/actions/actions.0_test.dart +++ b/examples/api/test/widgets/actions/actions.0_test.dart @@ -21,7 +21,7 @@ void main() { return button.style?.foregroundColor?.resolve({}); } - testWidgets('increments and decrements value', (WidgetTester tester) async { + testWidgets('Increments and decrements value', (WidgetTester tester) async { await tester.pumpWidget( const example.ActionsExampleApp(), ); diff --git a/examples/api/test/widgets/restoration_properties/restorable_value.0_test.dart b/examples/api/test/widgets/restoration_properties/restorable_value.0_test.dart new file mode 100644 index 000000000000..8c52ea8c5cfe --- /dev/null +++ b/examples/api/test/widgets/restoration_properties/restorable_value.0_test.dart @@ -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); + }); +}