diff --git a/dev/snippets/config/templates/README.md b/dev/snippets/config/templates/README.md index 3aad9ebceb..e52a341223 100644 --- a/dev/snippets/config/templates/README.md +++ b/dev/snippets/config/templates/README.md @@ -65,6 +65,11 @@ follows: This is a simple template for which you provide everything. It has no code of its own, just the sections for `imports`, `main`, and `preamble`. You must provide the `main` section in order to have a `main()`. + +### WidgetsApp Templates + +These templates create a `WidgetsApp` that encloses the snippet widget. These templates import +the widgets library. - [`stateful_widget`](stateful_widget.tmpl) : The default code block will be placed as the body of the `State` object of a @@ -77,7 +82,10 @@ follows: `build()` method, and any state variables. It also has an `imports` section to import additional packages. Please only import things that are part of flutter or part of default dependencies for a `flutter create` project. - It creates a `WidgetsApp` around the child stateful widget. + +- [`stateful_widget_ticker`](stateful_widget_ticker.tmpl) : Identical to the + `stateful_widget` template, with the addition of the `TickerProviderStateMixin` + class, enabling easy generation of animated samples. - [`stateless_widget`](stateless_widget.tmpl) : Identical to the `stateful_widget` template, except that the default code block is @@ -85,21 +93,23 @@ follows: `StatelessWidget`. The `@override` before the build method is added by the template, so must be omitted from the sample code. -- [`stateful_widget_material`](stateful_widget_material.tmpl) : Similar to - `stateful_widget`, except that it imports the material library, and uses - a `MaterialApp` instead of `WidgetsApp`. +### MaterialApp Templates -- [`stateless_widget_material`](stateless_widget_material.tmpl) : Similar to - `stateless_widget`, except that it imports the material library, and uses - a `MaterialApp` instead of `WidgetsApp`. +These templates follow the same conventions as the `WidgetsApp` templates above, but use a +`MaterialApp` instead. These templates import the material library. -- [`stateful_widget_scaffold`](stateful_widget_scaffold.tmpl) : Similar to - `stateful_widget_material`, except that it wraps the stateful widget with a - `Scaffold`. +- [`stateful_widget_material`](stateful_widget_material.tmpl) + +- [`stateful_widget_material_ticker`](stateful_widget_material_ticker.tmpl) + +- [`stateless_widget_material`](stateless_widget_material.tmpl) + +- [`stateful_widget_scaffold`](stateful_widget_scaffold.tmpl) : Adds a `Scaffold` widget as the home + of the enclosing `MaterialApp` to wrap the stateful widget snippet. The `Scaffold` widget contains + an `AppBar`. - [`stateful_widget_scaffold_center`](stateful_widget_scaffold_center.tmpl) : Similar to - `stateful_widget_scaffold`, except that it wraps the stateful widget with a - `Scaffold` _and_ a `Center`. + `stateful_widget_scaffold`, except that it wraps the stateful widget with a `Center`. - [`stateful_widget_scaffold_center_freeform_state`](stateful_widget_scaffold_center_freeform_state.tmpl) : Similar to `stateful_widget_scaffold_center` except that the code block has @@ -111,6 +121,23 @@ follows: `Scaffold`. - [`stateless_widget_scaffold_center`](stateless_widget_scaffold_center.tmpl) : Similar to - `stateless_widget_scaffold`, except that it wraps the stateless widget with a - `Scaffold` _and_ a `Center`. + `stateless_widget_scaffold`, except that it wraps the stateless widget with a `Center`. +### CupertinoApp Templates + +These templates follow the same conventions as the `WidgetsApp` templates above, but use a +`CupertinoApp` instead. These templates import the cupertino library. + +- [`stateful_widget_cupertino`](stateful_widget_cupertino.tmpl) + +- [`stateful_widget_cupertino_ticker`](stateful_widget_cupertino_ticker.tmpl) + +- [`stateless_widget_cupertino`](stateless_widget_cupertino.tmpl) + +- [`stateful_widget_cupertinoPageScaffold`](stateful_widget_cupertino_page_scaffold.tmpl) : Similar to + `stateful_widget_cupertino`, except that it wraps the stateful widget with a + `CupertinoPageScaffold`. + +- [`stateless_widget_cupertinoPageScaffold`](stateless_widget_cupertino_page_scaffold.tmpl) : Similar to + `stateless_widget_cupertino`, except that it wraps the stateless widget with a + `CupertinoPageScaffold`. diff --git a/dev/snippets/config/templates/freeform.tmpl b/dev/snippets/config/templates/freeform.tmpl index 99a2bf7f70..704c42126c 100644 --- a/dev/snippets/config/templates/freeform.tmpl +++ b/dev/snippets/config/templates/freeform.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} diff --git a/dev/snippets/config/templates/stateful_widget.tmpl b/dev/snippets/config/templates/stateful_widget.tmpl index a6ee714ab2..8a077f708b 100644 --- a/dev/snippets/config/templates/stateful_widget.tmpl +++ b/dev/snippets/config/templates/stateful_widget.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { @@ -30,7 +30,7 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } -// This is the private State class that goes with MyStatefulWidget. +/// This is the private State class that goes with MyStatefulWidget. class _MyStatefulWidgetState extends State { {{code}} } diff --git a/dev/snippets/config/templates/stateful_widget_cupertino.tmpl b/dev/snippets/config/templates/stateful_widget_cupertino.tmpl new file mode 100644 index 0000000000..e90f29dd4c --- /dev/null +++ b/dev/snippets/config/templates/stateful_widget_cupertino.tmpl @@ -0,0 +1,37 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/cupertino.dart'; + +{{code-imports}} + +void main() => runApp(new MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +{{code-preamble}} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + MyStatefulWidget({Key key}) : super(key: key); + + @override + _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { + {{code}} +} diff --git a/dev/snippets/config/templates/stateful_widget_cupertino_page_scaffold.tmpl b/dev/snippets/config/templates/stateful_widget_cupertino_page_scaffold.tmpl new file mode 100644 index 0000000000..e6120c4cef --- /dev/null +++ b/dev/snippets/config/templates/stateful_widget_cupertino_page_scaffold.tmpl @@ -0,0 +1,40 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/cupertino.dart'; + +{{code-imports}} + +void main() => runApp(new MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + title: _title, + home: CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar(middle: const Text(_title)), + child: MyStatefulWidget(), + ), + ); + } +} + +{{code-preamble}} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + MyStatefulWidget({Key key}) : super(key: key); + + @override + _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { + {{code}} +} diff --git a/dev/snippets/config/templates/stateful_widget_cupertino_ticker.tmpl b/dev/snippets/config/templates/stateful_widget_cupertino_ticker.tmpl new file mode 100644 index 0000000000..a847c821ea --- /dev/null +++ b/dev/snippets/config/templates/stateful_widget_cupertino_ticker.tmpl @@ -0,0 +1,38 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/cupertino.dart'; + +{{code-imports}} + +void main() => runApp(new MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +{{code-preamble}} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + MyStatefulWidget({Key key}) : super(key: key); + + @override + _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State with TickerProviderStateMixin { + {{code}} +} diff --git a/dev/snippets/config/templates/stateful_widget_material.tmpl b/dev/snippets/config/templates/stateful_widget_material.tmpl index 01731d57e2..6607a95f62 100644 --- a/dev/snippets/config/templates/stateful_widget_material.tmpl +++ b/dev/snippets/config/templates/stateful_widget_material.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; @@ -23,6 +23,7 @@ class MyApp extends StatelessWidget { {{code-preamble}} +/// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @@ -30,6 +31,7 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } +/// This is the private State class that goes with MyStatefulWidget. class _MyStatefulWidgetState extends State { {{code}} } diff --git a/dev/snippets/config/templates/stateful_widget_material_ticker.tmpl b/dev/snippets/config/templates/stateful_widget_material_ticker.tmpl index 89197e21a2..1680912606 100644 --- a/dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +++ b/dev/snippets/config/templates/stateful_widget_material_ticker.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; @@ -23,6 +23,7 @@ class MyApp extends StatelessWidget { {{code-preamble}} +/// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @@ -30,6 +31,8 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. class _MyStatefulWidgetState extends State with TickerProviderStateMixin { {{code}} } diff --git a/dev/snippets/config/templates/stateful_widget_scaffold.tmpl b/dev/snippets/config/templates/stateful_widget_scaffold.tmpl index d8968a0133..03fa3eaa50 100644 --- a/dev/snippets/config/templates/stateful_widget_scaffold.tmpl +++ b/dev/snippets/config/templates/stateful_widget_scaffold.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; @@ -26,6 +26,7 @@ class MyApp extends StatelessWidget { {{code-preamble}} +/// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @@ -33,6 +34,7 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } +/// This is the private State class that goes with MyStatefulWidget. class _MyStatefulWidgetState extends State { {{code}} } diff --git a/dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl b/dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl index 5317ccf108..2c557df5c8 100644 --- a/dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +++ b/dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; @@ -28,6 +28,7 @@ class MyApp extends StatelessWidget { {{code-preamble}} +/// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @@ -35,6 +36,7 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } +/// This is the private State class that goes with MyStatefulWidget. class _MyStatefulWidgetState extends State { {{code}} } diff --git a/dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl b/dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl index cc9fba7587..de21e80231 100644 --- a/dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl +++ b/dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; @@ -28,6 +28,7 @@ class MyApp extends StatelessWidget { {{code-preamble}} +/// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @@ -35,4 +36,5 @@ class MyStatefulWidget extends StatefulWidget { _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } +/// This is the private State class that goes with MyStatefulWidget. {{code}} diff --git a/dev/snippets/config/templates/stateful_widget_ticker.tmpl b/dev/snippets/config/templates/stateful_widget_ticker.tmpl new file mode 100644 index 0000000000..bd6e5b8f8b --- /dev/null +++ b/dev/snippets/config/templates/stateful_widget_ticker.tmpl @@ -0,0 +1,37 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/widgets.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: MyStatefulWidget(), + color: const Color(0xffffffff), + ); + } +} + +{{code-preamble}} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + MyStatefulWidget({Key key}) : super(key: key); + + @override + _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State with TickerProviderStateMixin { + {{code}} +} diff --git a/dev/snippets/config/templates/stateless_widget.tmpl b/dev/snippets/config/templates/stateless_widget.tmpl index 43901db1bc..ca4faed5a1 100644 --- a/dev/snippets/config/templates/stateless_widget.tmpl +++ b/dev/snippets/config/templates/stateless_widget.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { diff --git a/dev/snippets/config/templates/stateless_widget_cupertino.tmpl b/dev/snippets/config/templates/stateless_widget_cupertino.tmpl new file mode 100644 index 0000000000..42d2475c63 --- /dev/null +++ b/dev/snippets/config/templates/stateless_widget_cupertino.tmpl @@ -0,0 +1,33 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/cupertino.dart'; + +{{code-imports}} + +void main() => runApp(new MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + + +{{code-preamble}} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + MyStatelessWidget({Key key}) : super(key: key); + + @override + {{code}} +} diff --git a/dev/snippets/config/templates/stateless_widget_cupertino_page_scaffold.tmpl b/dev/snippets/config/templates/stateless_widget_cupertino_page_scaffold.tmpl new file mode 100644 index 0000000000..eeb4a6a3aa --- /dev/null +++ b/dev/snippets/config/templates/stateless_widget_cupertino_page_scaffold.tmpl @@ -0,0 +1,36 @@ +/// Flutter code sample for {{element}} + +{{description}} + +import 'package:flutter/cupertino.dart'; + +{{code-imports}} + +void main() => runApp(new MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + title: _title, + home: CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar(middle: const Text(_title)), + body: MyStatelessWidget(), + ), + ); + } +} + + +{{code-preamble}} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + MyStatelessWidget({Key key}) : super(key: key); + + @override + {{code}} +} diff --git a/dev/snippets/config/templates/stateless_widget_material.tmpl b/dev/snippets/config/templates/stateless_widget_material.tmpl index a79076f2c2..00a73dfe32 100644 --- a/dev/snippets/config/templates/stateless_widget_material.tmpl +++ b/dev/snippets/config/templates/stateless_widget_material.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; diff --git a/dev/snippets/config/templates/stateless_widget_scaffold.tmpl b/dev/snippets/config/templates/stateless_widget_scaffold.tmpl index 977f106dac..8da692c5b0 100644 --- a/dev/snippets/config/templates/stateless_widget_scaffold.tmpl +++ b/dev/snippets/config/templates/stateless_widget_scaffold.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample'; diff --git a/dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl b/dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl index 42dce92594..d8dca54235 100644 --- a/dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +++ b/dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl @@ -1,4 +1,4 @@ -// Flutter code sample for {{element}} +/// Flutter code sample for {{element}} {{description}} @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -/// This Widget is the main application widget. +/// This is the main application widget. class MyApp extends StatelessWidget { static const String _title = 'Flutter Code Sample';