11import 'dart:math' ;
22import 'dart:ui' as ui;
3+ import 'dart:async' ;
34import 'package:flutter/foundation.dart' ;
45import 'package:flutter/widgets.dart' ;
56import 'package:flutter/animation.dart' ;
@@ -41,23 +42,30 @@ class DemoBody extends StatefulWidget {
4142class _DemoBodyState extends State <DemoBody > with TickerProviderStateMixin {
4243 AnimationController animationController;
4344 CharacterFactory characterFactory;
45+ bool drawChar = true ;
4446
4547 @override
4648 void initState () {
4749 super .initState ();
4850 animationController = new AnimationController (
49- vsync: this , duration: new Duration (seconds: 2 ));
51+ vsync: this , duration: new Duration (seconds: 1 ));
5052
5153 characterFactory = new CharacterFactory ();
5254
5355 animationController.addListener (() {
54- characterFactory.addPoint (animationController.value);
56+ if (drawChar) {
57+ characterFactory.addPoint (animationController.value);
58+ }
5559 });
5660
5761 animationController.addStatusListener ((status) {
5862 if (status == AnimationStatus .completed) {
59- if (characterFactory.step != - 1 ) {
60- characterFactory.step++ ;
63+ if (drawChar) {
64+ if (characterFactory.step != - 1 ) {
65+ characterFactory.step++ ;
66+ } else {
67+ drawChar = false ;
68+ }
6169 animationController.reset ();
6270 animationController.forward ();
6371 }
@@ -81,10 +89,17 @@ class _DemoBodyState extends State<DemoBody> with TickerProviderStateMixin {
8189 parent: animationController,
8290 curve: Curves .easeInOut,
8391 ),
84- builder: (context, child) => new CustomPaint (
85- size: widget.screenSize,
86- painter: new _DemoPainter (widget.screenSize,
87- characterFactory.offsetPoint, characterFactory.path),
92+ builder: (context, child) => new Container (
93+ child: drawChar
94+ ? new CustomPaint (
95+ size: widget.screenSize,
96+ painter: new _DemoPainter (widget.screenSize,
97+ characterFactory.offsetPoint, characterFactory.path),
98+ )
99+ : new Container (
100+ width: animationController.value * 200 ,
101+ child: new Image .asset ('images/icon.png' ),
102+ ),
88103 ),
89104 ),
90105 );
@@ -109,9 +124,9 @@ class _DemoPainter extends CustomPainter {
109124 canvas.drawPath (path, painter);
110125 canvas.drawCircle (offsetPoint, 10.0 , painter);
111126
112- canvas.drawLine (new Offset (0.0 , 100.0 ), new Offset (600 .0 , 100.0 ), painter);
113- canvas.drawLine (new Offset (0.0 , 150.0 ), new Offset (600 .0 , 150.0 ), painter);
114- canvas.drawLine (new Offset (0.0 , 200.0 ), new Offset (600 .0 , 200.0 ), painter);
127+ canvas.drawLine (new Offset (0.0 , 100.0 ), new Offset (550 .0 , 100.0 ), painter);
128+ canvas.drawLine (new Offset (0.0 , 150.0 ), new Offset (550 .0 , 150.0 ), painter);
129+ canvas.drawLine (new Offset (0.0 , 200.0 ), new Offset (550 .0 , 200.0 ), painter);
115130 }
116131
117132 @override
@@ -149,8 +164,8 @@ class CharacterFactory {
149164 tChar (time, 330.0 , 15 );
150165 sChar (time, 380.0 , 18 );
151166 oChar (time, 430.0 , 19 );
152- fChar (time, 490 .0 , 20 );
153- finish = tChar (time, 520 .0 , 22 );
167+ fChar (time, 480 .0 , 20 );
168+ finish = tChar (time, 510 .0 , 22 );
154169
155170 if (finish) {
156171 step = - 1 ;
@@ -247,7 +262,7 @@ class CharacterFactory {
247262 new Offset (20.0 + xOffset, 135.0 ),
248263 new Offset (20.0 + xOffset, 140.0 ),
249264 ], time);
250- } else if (step > stepOffset + 2 ) {
265+ } else if (step > stepOffset + 2 ) {
251266 return true ;
252267 }
253268 path.addRect (new Rect .fromCircle (center: offsetPoint, radius: 2.0 ));
@@ -376,5 +391,4 @@ class CharacterFactory {
376391 path.addRect (new Rect .fromCircle (center: offsetPoint, radius: 2.0 ));
377392 return false ;
378393 }
379-
380394}
0 commit comments