Add stateful_widget_animation snippet template (#33295)
This commit is contained in:
@@ -86,3 +86,8 @@ follows:
|
||||
- [`stateless_widget_scaffold`](stateless_widget_scaffold.tmpl) : Similar to
|
||||
`stateless_widget_material`, except that it wraps the stateless widget with a
|
||||
Scaffold.
|
||||
|
||||
- [`stateful_widget_animation`](stateful_widget_animation.tmpl) : Similar to
|
||||
`stateful_widget`, except that it declares an `AnimationController` instance
|
||||
variable called `_controller`, and it properly initializes the controller
|
||||
in `initState()` and properly disposes of the controller in `dispose()`.
|
||||
|
||||
53
dev/snippets/config/templates/stateful_widget_animation.tmpl
Normal file
53
dev/snippets/config/templates/stateful_widget_animation.tmpl
Normal file
@@ -0,0 +1,53 @@
|
||||
// Flutter code sample for {{id}}
|
||||
|
||||
{{description}}
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
{{code-imports}}
|
||||
|
||||
void main() => runApp(new MyApp());
|
||||
|
||||
/// This Widget 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.
|
||||
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 1),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
{{code}}
|
||||
}
|
||||
Reference in New Issue
Block a user