Unverified Commit 088b6062 authored by Matt Sullivan's avatar Matt Sullivan Committed by GitHub

Added sample code to AnimatedWidget (#27803)

* Added sample to AnimatedWidget

* Updated AnimatedWidget example to use listenable from parent

* Made progress private and changed widget name
parent 30784895
......@@ -23,6 +23,58 @@ export 'package:flutter/rendering.dart' show RelativeRect;
/// [AnimatedWidget] is most useful for widgets that are otherwise stateless. To
/// use [AnimatedWidget], simply subclass it and implement the build function.
///
///{@tool sample}
///
/// This code defines a widget called `Spinner` that spins a green square
/// continually. It is built with an [AnimatedWidget].
///
/// ```dart
/// class Spinner extends StatefulWidget {
/// @override
/// _SpinnerState createState() => _SpinnerState();
/// }
///
/// class _SpinnerState extends State<Spinner> with TickerProviderStateMixin {
/// AnimationController _controller;
///
/// @override
/// void initState() {
/// super.initState();
/// _controller = AnimationController(
/// duration: const Duration(seconds: 10),
/// vsync: this,
/// )..repeat();
/// }
///
/// @override
/// void dispose() {
/// _controller.dispose();
/// super.dispose();
/// }
///
/// @override
/// Widget build(BuildContext context) {
/// return SpinningContainer(controller: _controller);
/// }
/// }
///
/// class SpinningContainer extends AnimatedWidget {
/// const SpinningContainer({Key key, AnimationController controller})
/// : super(key: key, listenable: controller);
///
/// Animation<double> get _progress => listenable;
///
/// @override
/// Widget build(BuildContext context) {
/// return Transform.rotate(
/// angle: _progress.value * 2.0 * math.pi,
/// child: Container(width: 200.0, height: 200.0, color: Colors.green),
/// );
/// }
/// }
/// ```
/// {@end-tool}
///
/// For more complex case involving additional state, consider using
/// [AnimatedBuilder].
///
......
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