| // Flutter code sample for {{element}} |
| // |
| {{description}} |
| |
| {{code-dartImports}} |
| |
| import 'package:flutter/material.dart'; |
| {{code-imports}} |
| |
| void main() => runApp(const MyApp()); |
| |
| /// This is the main application widget. |
| class MyApp extends StatelessWidget { |
| const MyApp({Key? key}) : super(key: key); |
| |
| @override |
| Widget build(BuildContext context) { |
| return WidgetsApp( |
| title: 'Flutter Code Sample', |
| color: const Color(0xffffffff), |
| builder: (BuildContext context, Widget? child) { |
| return const Center( |
| child: MyStatefulWidget(restorationId: 'main'), |
| ); |
| }, |
| ); |
| } |
| } |
| {{code-preamble}} |
| |
| /// This is the stateful widget that the main application instantiates. |
| class MyStatefulWidget extends StatefulWidget { |
| const MyStatefulWidget({Key? key, this.restorationId}) : super(key: key); |
| |
| final String? restorationId; |
| |
| @override |
| State<MyStatefulWidget> 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}} |
| } |