|
| 1 | +/// |
| 2 | +/// Created by NieBin on 2019年6月9日 |
| 3 | +/// Github: https://github.com/nb312 |
| 4 | +/// Email: niebin312@gmail.com |
| 5 | +/// |
| 6 | +import "package:flutter/material.dart"; |
| 7 | +import 'package:flutter_widgets/const/_const.dart'; |
| 8 | + |
| 9 | +class PositionTransitionPage extends StatefulWidget { |
| 10 | + @override |
| 11 | + _PositionTransState createState() => _PositionTransState(); |
| 12 | +} |
| 13 | + |
| 14 | +class _PositionTransState extends State<PositionTransitionPage> |
| 15 | + with SingleTickerProviderStateMixin { |
| 16 | + Animation<RelativeRect> _rectAnim; |
| 17 | + AnimationController _controller; |
| 18 | + |
| 19 | + Widget _positionTrans() => PositionedTransition( |
| 20 | + rect: _rectAnim, |
| 21 | + child: Container( |
| 22 | + color: BLUE_DEEP, |
| 23 | + child: Text("Hello world"), |
| 24 | + ), |
| 25 | + ); |
| 26 | + |
| 27 | + Widget _positionClick() => FloatingActionButton( |
| 28 | + child: Text("position click"), |
| 29 | + onPressed: () { |
| 30 | + _controller.reset(); |
| 31 | + _controller.forward(); |
| 32 | + }, |
| 33 | + ); |
| 34 | + |
| 35 | + @override |
| 36 | + void initState() { |
| 37 | + _controller = |
| 38 | + AnimationController(vsync: this, duration: Duration(seconds: 3)); |
| 39 | + CurvedAnimation _curve = |
| 40 | + CurvedAnimation(parent: _controller, curve: Curves.easeOut); |
| 41 | + _rectAnim = RelativeRectTween( |
| 42 | + begin: RelativeRect.fromLTRB(00.0, 0.0, 0.0, 0.0), |
| 43 | + end: RelativeRect.fromLTRB(100.0, 100.0, 0, 00), |
| 44 | + ).animate(_curve) |
| 45 | + ..addListener(() { |
| 46 | + print("value = $_rectAnim"); |
| 47 | + }); |
| 48 | + |
| 49 | + super.initState(); |
| 50 | + } |
| 51 | + |
| 52 | + @override |
| 53 | + Widget build(BuildContext context) { |
| 54 | + return Scaffold( |
| 55 | + appBar: AppBar( |
| 56 | + title: Text(PageName.ANIM_POSITION_TRANS), |
| 57 | + ), |
| 58 | + body: Column( |
| 59 | + mainAxisAlignment: MainAxisAlignment.start, |
| 60 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 61 | + children: <Widget>[ |
| 62 | + Container( |
| 63 | + constraints: BoxConstraints.expand(width: 200, height: 200), |
| 64 | + color: RED_LIGHT, |
| 65 | + child: Stack( |
| 66 | + children: <Widget>[ |
| 67 | + _positionTrans(), |
| 68 | + ], |
| 69 | + ), |
| 70 | + ), |
| 71 | + _positionClick() |
| 72 | + ], |
| 73 | + ), |
| 74 | + ); |
| 75 | + } |
| 76 | +} |
0 commit comments