mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Switch document generation to use the snippets package instead of the snippets code in the Flutter repo. In the process, some bugs in sample code analysis have been fixed, and I've fixed some more errors in the samples. This will allow the snippets package to be developed separately from the Flutter repo, and reduce the code in the Flutter repo. The snippets code is deleted in this PR. I also converted some comments in the snippet templates to be regular comments instead of doc comments, because having a doc comment block before the imports causes the Dart import sorter to lose the comment. They should have been regular comments in the first place. The snippets package resides in the assets-for-api-docs repo. The sample analysis has also been converted to be run in parallel, and I've bumped the Dartdoc version to 1.0.2.
50 lines
1.3 KiB
Cheetah
50 lines
1.3 KiB
Cheetah
// 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',
|
|
home: const 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 {
|
|
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}}
|
|
}
|