Unverified Commit f89814b0 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Adding CupertinoApp Sample templates (#60929)

parent d4589e0c
...@@ -66,6 +66,11 @@ follows: ...@@ -66,6 +66,11 @@ follows:
its own, just the sections for `imports`, `main`, and `preamble`. You must its own, just the sections for `imports`, `main`, and `preamble`. You must
provide the `main` section in order to have a `main()`. 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) : - [`stateful_widget`](stateful_widget.tmpl) :
The default code block will be placed as the body of the `State` object of a The default code block will be placed as the body of the `State` object of a
`StatefulWidget` subclass. Because the default code block is placed as the body `StatefulWidget` subclass. Because the default code block is placed as the body
...@@ -77,7 +82,10 @@ follows: ...@@ -77,7 +82,10 @@ follows:
`build()` method, and any state variables. It also has an `imports` `build()` method, and any state variables. It also has an `imports`
section to import additional packages. Please only import things that are part section to import additional packages. Please only import things that are part
of flutter or part of default dependencies for a `flutter create` project. 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 - [`stateless_widget`](stateless_widget.tmpl) : Identical to the
`stateful_widget` template, except that the default code block is `stateful_widget` template, except that the default code block is
...@@ -85,21 +93,23 @@ follows: ...@@ -85,21 +93,23 @@ follows:
`StatelessWidget`. The `@override` before the build method is added by `StatelessWidget`. The `@override` before the build method is added by
the template, so must be omitted from the sample code. the template, so must be omitted from the sample code.
- [`stateful_widget_material`](stateful_widget_material.tmpl) : Similar to ### MaterialApp Templates
`stateful_widget`, except that it imports the material library, and uses
a `MaterialApp` instead of `WidgetsApp`.
- [`stateless_widget_material`](stateless_widget_material.tmpl) : Similar to These templates follow the same conventions as the `WidgetsApp` templates above, but use a
`stateless_widget`, except that it imports the material library, and uses `MaterialApp` instead. These templates import the material library.
a `MaterialApp` instead of `WidgetsApp`.
- [`stateful_widget_scaffold`](stateful_widget_scaffold.tmpl) : Similar to - [`stateful_widget_material`](stateful_widget_material.tmpl)
`stateful_widget_material`, except that it wraps the stateful widget with a
`Scaffold`. - [`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_center`](stateful_widget_scaffold_center.tmpl) : Similar to
`stateful_widget_scaffold`, except that it wraps the stateful widget with a `stateful_widget_scaffold`, except that it wraps the stateful widget with a `Center`.
`Scaffold` _and_ a `Center`.
- [`stateful_widget_scaffold_center_freeform_state`](stateful_widget_scaffold_center_freeform_state.tmpl) : - [`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 Similar to `stateful_widget_scaffold_center` except that the code block has
...@@ -111,6 +121,23 @@ follows: ...@@ -111,6 +121,23 @@ follows:
`Scaffold`. `Scaffold`.
- [`stateless_widget_scaffold_center`](stateless_widget_scaffold_center.tmpl) : Similar to - [`stateless_widget_scaffold_center`](stateless_widget_scaffold_center.tmpl) : Similar to
`stateless_widget_scaffold`, except that it wraps the stateless widget with a `stateless_widget_scaffold`, except that it wraps the stateless widget with a `Center`.
`Scaffold` _and_ 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`.
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
......
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -30,7 +30,7 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -30,7 +30,7 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _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<MyStatefulWidget> { class _MyStatefulWidgetState extends State<MyStatefulWidget> {
{{code}} {{code}}
} }
/// 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<MyStatefulWidget> {
{{code}}
}
/// 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<MyStatefulWidget> {
{{code}}
}
/// 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<MyStatefulWidget> with TickerProviderStateMixin {
{{code}}
}
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
...@@ -23,6 +23,7 @@ class MyApp extends StatelessWidget { ...@@ -23,6 +23,7 @@ class MyApp extends StatelessWidget {
{{code-preamble}} {{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget { class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key); MyStatefulWidget({Key key}) : super(key: key);
...@@ -30,6 +31,7 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -30,6 +31,7 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
} }
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _MyStatefulWidgetState extends State<MyStatefulWidget> {
{{code}} {{code}}
} }
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
...@@ -23,6 +23,7 @@ class MyApp extends StatelessWidget { ...@@ -23,6 +23,7 @@ class MyApp extends StatelessWidget {
{{code-preamble}} {{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget { class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key); MyStatefulWidget({Key key}) : super(key: key);
...@@ -30,6 +31,8 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -30,6 +31,8 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _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<MyStatefulWidget> with TickerProviderStateMixin { class _MyStatefulWidgetState extends State<MyStatefulWidget> with TickerProviderStateMixin {
{{code}} {{code}}
} }
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
...@@ -26,6 +26,7 @@ class MyApp extends StatelessWidget { ...@@ -26,6 +26,7 @@ class MyApp extends StatelessWidget {
{{code-preamble}} {{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget { class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key); MyStatefulWidget({Key key}) : super(key: key);
...@@ -33,6 +34,7 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -33,6 +34,7 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
} }
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _MyStatefulWidgetState extends State<MyStatefulWidget> {
{{code}} {{code}}
} }
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
...@@ -28,6 +28,7 @@ class MyApp extends StatelessWidget { ...@@ -28,6 +28,7 @@ class MyApp extends StatelessWidget {
{{code-preamble}} {{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget { class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key); MyStatefulWidget({Key key}) : super(key: key);
...@@ -35,6 +36,7 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -35,6 +36,7 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
} }
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> { class _MyStatefulWidgetState extends State<MyStatefulWidget> {
{{code}} {{code}}
} }
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
...@@ -28,6 +28,7 @@ class MyApp extends StatelessWidget { ...@@ -28,6 +28,7 @@ class MyApp extends StatelessWidget {
{{code-preamble}} {{code-preamble}}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget { class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key); MyStatefulWidget({Key key}) : super(key: key);
...@@ -35,4 +36,5 @@ class MyStatefulWidget extends StatefulWidget { ...@@ -35,4 +36,5 @@ class MyStatefulWidget extends StatefulWidget {
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
} }
/// This is the private State class that goes with MyStatefulWidget.
{{code}} {{code}}
/// 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<MyStatefulWidget> with TickerProviderStateMixin {
{{code}}
}
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
/// 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}}
}
/// 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}}
}
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
......
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
......
// Flutter code sample for {{element}} /// Flutter code sample for {{element}}
{{description}} {{description}}
...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
/// This Widget is the main application widget. /// This is the main application widget.
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample'; static const String _title = 'Flutter Code Sample';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment