Unverified Commit 248645a2 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

RestorableProperty should dispatch creation in constructor. (#133883)

parent a3362a9f
...@@ -454,6 +454,13 @@ class _RootRestorationScopeState extends State<RootRestorationScope> { ...@@ -454,6 +454,13 @@ class _RootRestorationScopeState extends State<RootRestorationScope> {
/// * [RestorationManager], which describes how state restoration works in /// * [RestorationManager], which describes how state restoration works in
/// Flutter. /// Flutter.
abstract class RestorableProperty<T> extends ChangeNotifier { abstract class RestorableProperty<T> extends ChangeNotifier {
/// Creates a [RestorableProperty].
RestorableProperty(){
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
}
}
/// Called by the [RestorationMixin] if no restoration data is available to /// Called by the [RestorationMixin] if no restoration data is available to
/// restore the value of the property from to obtain the default value for the /// restore the value of the property from to obtain the default value for the
/// property. /// property.
......
...@@ -58,7 +58,9 @@ void main() { ...@@ -58,7 +58,9 @@ void main() {
group('RestorableTimeOfDay tests', () { group('RestorableTimeOfDay tests', () {
testWidgetsWithLeakTracking('value is not accessible when not registered', (WidgetTester tester) async { testWidgetsWithLeakTracking('value is not accessible when not registered', (WidgetTester tester) async {
expect(() => RestorableTimeOfDay(const TimeOfDay(hour: 20, minute: 4)).value, throwsAssertionError); final RestorableTimeOfDay property = RestorableTimeOfDay(const TimeOfDay(hour: 20, minute: 4));
addTearDown(() => property.dispose());
expect(() => property.value, throwsAssertionError);
}); });
testWidgets('work when not in restoration scope', (WidgetTester tester) async { testWidgets('work when not in restoration scope', (WidgetTester tester) async {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() { void main() {
testWidgets('value is not accessible when not registered', (WidgetTester tester) async { testWidgets('value is not accessible when not registered', (WidgetTester tester) async {
...@@ -25,6 +26,10 @@ void main() { ...@@ -25,6 +26,10 @@ void main() {
expect(() => _TestRestorableValue().value, throwsAssertionError); expect(() => _TestRestorableValue().value, throwsAssertionError);
}); });
testWidgetsWithLeakTracking('$RestorableProperty dispatches creation in constructor', (WidgetTester widgetTester) async {
expect(()=> RestorableDateTimeN(null).dispose(), dispatchesMemoryEvents(RestorableDateTimeN));
});
testWidgets('work when not in restoration scope', (WidgetTester tester) async { testWidgets('work when not in restoration scope', (WidgetTester tester) async {
await tester.pumpWidget(const _RestorableWidget()); await tester.pumpWidget(const _RestorableWidget());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment