RestorableProperty should dispatch creation in constructor. (#133883)
This commit is contained in:
parent
a3362a9ff8
commit
248645a2b2
@ -454,6 +454,13 @@ class _RootRestorationScopeState extends State<RootRestorationScope> {
|
||||
/// * [RestorationManager], which describes how state restoration works in
|
||||
/// Flutter.
|
||||
abstract class RestorableProperty<T> extends ChangeNotifier {
|
||||
/// Creates a [RestorableProperty].
|
||||
RestorableProperty(){
|
||||
if (kFlutterMemoryAllocationsEnabled) {
|
||||
maybeDispatchObjectCreation();
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// property.
|
||||
|
@ -58,7 +58,9 @@ void main() {
|
||||
|
||||
group('RestorableTimeOfDay tests', () {
|
||||
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 {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('value is not accessible when not registered', (WidgetTester tester) async {
|
||||
@ -25,6 +26,10 @@ void main() {
|
||||
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 {
|
||||
await tester.pumpWidget(const _RestorableWidget());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user