More restoration documentation (#63438)

This commit is contained in:
Ian Hickson
2020-08-21 10:51:05 -07:00
committed by GitHub
parent c7ebb2b75f
commit 39be8a40b5
3 changed files with 126 additions and 0 deletions

View File

@@ -87,6 +87,11 @@ the widgets library.
`stateful_widget` template, with the addition of the `TickerProviderStateMixin`
class, enabling easy generation of animated samples.
- [`stateful_widget_restoration`](stateful_widget_restoration.tmpl) : Similar to
the `stateful_widget` template, but the widget also imports `RestorationMixin`
and has a `restorationId` field which it uses to implement the `restorationId`
getter on the `State`.
- [`stateless_widget`](stateless_widget.tmpl) : Identical to the
`stateful_widget` template, except that the default code block is
inserted as a method (which should be the `build` method) in a

View File

@@ -0,0 +1,46 @@
/// Flutter code sample for {{element}}
{{description}}
import 'package:flutter/material.dart';
{{code-imports}}
void main() => runApp(new MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return WidgetsApp(
title: 'Flutter Code Sample',
home: Center(
child: MyStatefulWidget(restorationId: 'main'),
),
color: const Color(0xffffffff),
);
}
}
{{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key, this.restorationId}) : super(key: key);
final String restorationId;
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
/// RestorationProperty objects can be used because of RestorationMixin.
class _MyStatefulWidgetState extends State<MyStatefulWidget> with RestorationMixin {
// In this example, the restoration ID for the mixin is passed in through
// the [StatefulWidget]'s constructor.
@override
String get restorationId => widget.restorationId;
{{code}}
}