Skip to content

Commit 95b0124

Browse files
authored
Add imports section to sample code templates, and more docs. (flutter#25184)
Adds documentation for the stateless widget template, and adds an "imports" section to both templates.
1 parent 2b819dd commit 95b0124

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

dev/snippets/config/templates/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ syntax inside of the dartdoc comment for a Flutter class/variable/enum/etc.:
1010
/// above" or "see the code below", since the location of the description may
1111
/// change in the future. You can use dartdoc [Linking] in the description, and
1212
/// __Markdown__ too.
13+
///
1314
/// ```dart preamble
1415
/// class Foo extends StatelessWidget {
1516
/// const Foo({this.value = ''});
@@ -48,9 +49,17 @@ additional burden, since all code will also be compiled to be sure it compiles).
4849
The templates available for using as an argument to the snippets tool are as
4950
follows:
5051

51-
- __`stateful_widget`__ : Takes a `preamble` in addition to the default code
52+
- [`stateful_widget`](stateful_widget.tmpl) :
53+
The default code block will be placed as the body of the `State` object of a
54+
StatefulWidget subclass. Because the default code block is placed as the body
55+
of a stateful widget, you will need to implement the `build()` function, and any
56+
state variables. It also has a `preamble` in addition to the default code
5257
block, which will be placed at the top level of the Dart file, so bare
53-
function calls are not allowed in the preamble. The default code block is
54-
placed as the body of a stateful widget, so you will need to implement the
55-
build() function, and any state variables.
56-
58+
function calls are not allowed in the preamble. It also has an `imports`
59+
section to import additional packages. Please only import things that are part
60+
of flutter or part of default dependencies for a `flutter create` project.
61+
62+
- [`stateless_widget`](stateless_widget.tmpl) :
63+
Identical to the `stateful_widget` template, except that the default code
64+
block is inserted as the return value for a pre-existing `build` function in a
65+
StatelessWidget, instead of being at the class level.

dev/snippets/config/templates/stateful_widget.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import 'package:flutter/material.dart';
44

5+
{{code-imports}}
6+
57
void main() => runApp(new MyApp());
68

79
class MyApp extends StatelessWidget {

dev/snippets/config/templates/stateless_widget.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import 'package:flutter/material.dart';
44

5+
{{code-imports}}
6+
57
void main() => runApp(new MyApp());
68

79
class MyApp extends StatelessWidget {

0 commit comments

Comments
 (0)