Add Sample code to SlideTransition (#41009)
This commit is contained in:
parent
43932aa2ca
commit
81e693a7fe
@ -101,6 +101,11 @@ follows:
|
|||||||
`stateful_widget_scaffold`, except that it wraps the stateful widget with a
|
`stateful_widget_scaffold`, except that it wraps the stateful widget with a
|
||||||
`Scaffold` _and_ a `Center`.
|
`Scaffold` _and_ 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
|
||||||
|
to contain the entire state class defined as:
|
||||||
|
`class _MyStatefulWidgetState extends State<MyStatefulWidget>`
|
||||||
|
|
||||||
- [`stateless_widget_scaffold`](stateless_widget_scaffold.tmpl) : Similar to
|
- [`stateless_widget_scaffold`](stateless_widget_scaffold.tmpl) : Similar to
|
||||||
`stateless_widget_material`, except that it wraps the stateless widget with a
|
`stateless_widget_material`, except that it wraps the stateless widget with a
|
||||||
`Scaffold`.
|
`Scaffold`.
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
// Flutter code sample for {{id}}
|
||||||
|
|
||||||
|
{{description}}
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
{{code-imports}}
|
||||||
|
|
||||||
|
void main() => runApp(new MyApp());
|
||||||
|
|
||||||
|
/// This Widget is the main application widget.
|
||||||
|
class MyApp extends StatelessWidget {
|
||||||
|
static const String _title = 'Flutter Code Sample';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
title: _title,
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text(_title)),
|
||||||
|
body: Center(
|
||||||
|
child: MyStatefulWidget(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{code-preamble}}
|
||||||
|
|
||||||
|
class MyStatefulWidget extends StatefulWidget {
|
||||||
|
MyStatefulWidget({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
{{code}}
|
@ -194,6 +194,51 @@ class _AnimatedState extends State<AnimatedWidget> {
|
|||||||
/// animated by a [CurvedAnimation] set to [Curves.elasticIn]:
|
/// animated by a [CurvedAnimation] set to [Curves.elasticIn]:
|
||||||
/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/slide_transition.mp4}
|
/// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/slide_transition.mp4}
|
||||||
///
|
///
|
||||||
|
/// {@tool snippet --template=stateful_widget_scaffold_center_freeform_state}
|
||||||
|
/// The following code implements the [SlideTransition] as seen in the video
|
||||||
|
/// above:
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// class _MyStatefulWidgetState extends State<MyStatefulWidget> with SingleTickerProviderStateMixin {
|
||||||
|
/// AnimationController _controller;
|
||||||
|
/// Animation<Offset> _offsetAnimation;
|
||||||
|
///
|
||||||
|
/// @override
|
||||||
|
/// void initState() {
|
||||||
|
/// super.initState();
|
||||||
|
/// _controller = AnimationController(
|
||||||
|
/// duration: const Duration(seconds: 2),
|
||||||
|
/// vsync: this,
|
||||||
|
/// )..repeat(reverse: true);
|
||||||
|
/// _offsetAnimation = Tween<Offset>(
|
||||||
|
/// begin: Offset.zero,
|
||||||
|
/// end: const Offset(1.5, 0.0),
|
||||||
|
/// ).animate(CurvedAnimation(
|
||||||
|
/// parent: _controller,
|
||||||
|
/// curve: Curves.elasticIn,
|
||||||
|
/// ));
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// @override
|
||||||
|
/// void dispose() {
|
||||||
|
/// super.dispose();
|
||||||
|
/// _controller.dispose();
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// @override
|
||||||
|
/// Widget build(BuildContext context) {
|
||||||
|
/// return SlideTransition(
|
||||||
|
/// position: _offsetAnimation,
|
||||||
|
/// child: const Padding(
|
||||||
|
/// padding: EdgeInsets.all(8.0),
|
||||||
|
/// child: FlutterLogo(size: 150.0),
|
||||||
|
/// ),
|
||||||
|
/// );
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
/// {@end-tool}
|
||||||
|
///
|
||||||
/// See also:
|
/// See also:
|
||||||
///
|
///
|
||||||
/// * [AlignTransition], an animated version of an [Align] that animates its
|
/// * [AlignTransition], an animated version of an [Align] that animates its
|
||||||
|
Loading…
x
Reference in New Issue
Block a user