1+ import 'dart:math' as math;
2+
13import 'package:flutter/material.dart' ;
2- import 'package:flutter_test/flutter_test.dart' ;
34import 'package:flutter/rendering.dart' ;
45import 'package:flutter/widgets.dart' ;
6+ import 'package:flutter_test/flutter_test.dart' ;
57import 'package:getwidget/getwidget.dart' ;
68
7- import 'dart:math' as math;
8-
99class TestPaintingContext implements PaintingContext {
1010 final List <Invocation > invocations = < Invocation > [];
1111 @override
@@ -15,8 +15,6 @@ class TestPaintingContext implements PaintingContext {
1515}
1616
1717void main () {
18- // ------------------------- align
19-
2018 testWidgets ('AnimatedAlign.debugFillProperties' , (WidgetTester tester) async {
2119 final GFAnimation box = GFAnimation (
2220 duration: const Duration (seconds: 2 ),
@@ -70,8 +68,6 @@ void main() {
7068 expect (tester.getTopRight (find.byKey (alignKey)), const Offset (800 , 400 ));
7169 });
7270
73- // ------------------- container
74-
7571 testWidgets ('AnimatedContainer.debugFillProperties' ,
7672 (WidgetTester tester) async {
7773 final GFAnimation container = GFAnimation (
@@ -122,23 +118,23 @@ void main() {
122118 testWidgets ('AnimatedContainer testing over animate ' ,
123119 (WidgetTester tester) async {
124120 await tester.pumpWidget (const GFAnimation (
125- duration: const Duration (milliseconds: 300 ),
121+ duration: Duration (milliseconds: 300 ),
126122 type: GFAnimationType .container,
127123 color: Colors .teal,
128124 ));
129125 expect (tester.binding.transientCallbackCount, 0 );
130126 await tester.pump (const Duration (seconds: 1 ));
131127 expect (tester.binding.transientCallbackCount, 0 );
132128 await tester.pumpWidget (const GFAnimation (
133- duration: const Duration (milliseconds: 300 ),
129+ duration: Duration (milliseconds: 300 ),
134130 type: GFAnimationType .container,
135131 color: Colors .teal,
136132 ));
137133 expect (tester.binding.transientCallbackCount, 0 );
138134 await tester.pump (const Duration (seconds: 1 ));
139135 expect (tester.binding.transientCallbackCount, 0 );
140136 await tester.pumpWidget (const GFAnimation (
141- duration: const Duration (milliseconds: 300 ),
137+ duration: Duration (milliseconds: 300 ),
142138 type: GFAnimationType .container,
143139 color: Colors .teal,
144140 ));
@@ -147,7 +143,7 @@ void main() {
147143 await tester.pump (const Duration (seconds: 1 ));
148144 expect (tester.binding.transientCallbackCount, 0 );
149145 await tester.pumpWidget (const GFAnimation (
150- duration: const Duration (milliseconds: 300 ),
146+ duration: Duration (milliseconds: 300 ),
151147 type: GFAnimationType .container,
152148 color: Colors .teal,
153149 ));
@@ -194,10 +190,10 @@ void main() {
194190 testWidgets ('Animation rerun' , (WidgetTester tester) async {
195191 await tester.pumpWidget (Center (
196192 child: GFAnimation (
197- duration: Duration (milliseconds: 200 ),
193+ duration: const Duration (milliseconds: 200 ),
198194 type: GFAnimationType .container,
199195 child: Container (
200- child: Text ('X' , textDirection: TextDirection .ltr),
196+ child: const Text ('X' , textDirection: TextDirection .ltr),
201197 width: 100 ,
202198 height: 100 ,
203199 ))));
@@ -212,7 +208,7 @@ void main() {
212208 duration: const Duration (milliseconds: 200 ),
213209 type: GFAnimationType .container,
214210 child: Container (
215- child: Text ('X' , textDirection: TextDirection .ltr),
211+ child: const Text ('X' , textDirection: TextDirection .ltr),
216212 width: 200 ,
217213 height: 200 ,
218214 ))));
@@ -230,7 +226,7 @@ void main() {
230226 child: GFAnimation (
231227 duration: const Duration (milliseconds: 200 ),
232228 child: Container (
233- child: Text ('X' , textDirection: TextDirection .ltr),
229+ child: const Text ('X' , textDirection: TextDirection .ltr),
234230 width: 200 ,
235231 height: 200 ,
236232 ))));
@@ -252,8 +248,8 @@ void main() {
252248 const Center (
253249 child: GFAnimation (
254250 type: GFAnimationType .size,
255- duration: const Duration (milliseconds: 200 ),
256- child: const SizedBox (
251+ duration: Duration (milliseconds: 200 ),
252+ child: SizedBox (
257253 width: 100 ,
258254 height: 100 ,
259255 ),
@@ -268,9 +264,9 @@ void main() {
268264 child: GFAnimation (
269265 width: 200 ,
270266 height: 200 ,
271- duration: const Duration (milliseconds: 200 ),
267+ duration: Duration (milliseconds: 200 ),
272268 type: GFAnimationType .size,
273- child: const SizedBox (
269+ child: SizedBox (
274270 width: 200 ,
275271 height: 200 ,
276272 ),
@@ -291,11 +287,11 @@ void main() {
291287 await tester.pumpWidget (
292288 const Center (
293289 child: GFAnimation (
294- duration: const Duration (milliseconds: 200 ),
290+ duration: Duration (milliseconds: 200 ),
295291 type: GFAnimationType .size,
296292 width: 200 ,
297293 height: 200 ,
298- child: const SizedBox (
294+ child: SizedBox (
299295 width: 100 ,
300296 height: 100 ,
301297 ),
@@ -323,9 +319,9 @@ void main() {
323319 width: 100 ,
324320 height: 100 ,
325321 child: GFAnimation (
326- duration: const Duration (milliseconds: 200 ),
322+ duration: Duration (milliseconds: 200 ),
327323 type: GFAnimationType .size,
328- child: const SizedBox (
324+ child: SizedBox (
329325 width: 100 ,
330326 height: 100 ,
331327 ),
@@ -343,9 +339,9 @@ void main() {
343339 width: 100 ,
344340 height: 100 ,
345341 child: GFAnimation (
346- duration: const Duration (milliseconds: 200 ),
342+ duration: Duration (milliseconds: 200 ),
347343 type: GFAnimationType .size,
348- child: const SizedBox (
344+ child: SizedBox (
349345 width: 200 ,
350346 height: 200 ,
351347 ),
@@ -364,21 +360,21 @@ void main() {
364360 await tester.pumpWidget (
365361 const Center (
366362 child: AnimatedSize (
367- duration: const Duration (milliseconds: 200 ),
368- vsync: const TestVSync (),
369- child: const SizedBox (
363+ duration: Duration (milliseconds: 200 ),
364+ vsync: TestVSync (),
365+ child: SizedBox (
370366 width: 100 ,
371367 height: 100 ,
372368 ),
373369 ),
374370 ),
375371 );
376372 await tester.pumpWidget (
377- Center (
373+ const Center (
378374 child: GFAnimation (
379- duration: const Duration (milliseconds: 200 ),
375+ duration: Duration (milliseconds: 200 ),
380376 type: GFAnimationType .size,
381- child: const SizedBox (
377+ child: SizedBox (
382378 width: 200 ,
383379 height: 100 ,
384380 ),
@@ -392,11 +388,11 @@ void main() {
392388 testWidgets ('does not run animation unnecessarily' ,
393389 (WidgetTester tester) async {
394390 await tester.pumpWidget (
395- Center (
391+ const Center (
396392 child: GFAnimation (
397- duration: const Duration (milliseconds: 200 ),
393+ duration: Duration (milliseconds: 200 ),
398394 type: GFAnimationType .size,
399- child: const SizedBox (
395+ child: SizedBox (
400396 width: 100 ,
401397 height: 100 ,
402398 ),
@@ -414,14 +410,13 @@ void main() {
414410 }
415411 });
416412
417- // --------------------- rotate
418-
419- testWidgets ('RotationTransition maintains chosen alignment during animation' , (WidgetTester tester) async {
420-
413+ testWidgets ('RotationTransition maintains chosen alignment during animation' ,
414+ (WidgetTester tester) async {
421415 AnimationController controller;
422416 Animation <double > animation;
423417
424- controller = AnimationController (duration: const Duration (seconds: 5 ), vsync: const TestVSync ());
418+ controller = AnimationController (
419+ duration: const Duration (seconds: 5 ), vsync: const TestVSync ());
425420 animation = CurvedAnimation (parent: controller, curve: Curves .linear);
426421
427422 final Widget widget = GFAnimation (
@@ -433,7 +428,8 @@ void main() {
433428 );
434429
435430 await tester.pumpWidget (widget);
436- RotationTransition actualRotatedBox = tester.widget (find.byType (RotationTransition ));
431+ RotationTransition actualRotatedBox =
432+ tester.widget (find.byType (RotationTransition ));
437433 Alignment actualAlignment = actualRotatedBox.alignment;
438434 expect (actualAlignment, Alignment .topRight);
439435
@@ -445,11 +441,11 @@ void main() {
445441 });
446442
447443 testWidgets ('RotationTransition animates' , (WidgetTester tester) async {
448-
449444 AnimationController controller;
450445 Animation <double > animation;
451446
452- controller = AnimationController (duration: const Duration (seconds: 5 ), vsync: const TestVSync ());
447+ controller = AnimationController (
448+ duration: const Duration (seconds: 5 ), vsync: const TestVSync ());
453449 animation = CurvedAnimation (parent: controller, curve: Curves .linear);
454450
455451 final Widget widget = GFAnimation (
@@ -459,19 +455,11 @@ void main() {
459455 alignment: Alignment .topRight,
460456 child: const Text ('Rotation' , textDirection: TextDirection .ltr),
461457 );
462- // RotationTransition(
463- // alignment: Alignment.topRight,
464- // turns: controller,
465- // child: const Text(
466- // 'Rotation',
467- // textDirection: TextDirection.ltr,
468- // ),
469- // );
470458
471459 await tester.pumpWidget (widget);
472460 Transform actualRotatedBox = tester.widget (find.byType (Transform ));
473461 Matrix4 actualTurns = actualRotatedBox.transform;
474- expect (actualTurns, equals (Matrix4 .rotationZ (0.0 )));
462+ expect (actualTurns, equals (Matrix4 .rotationZ (0 )));
475463
476464 controller.value = 0.5 ;
477465 await tester.pump ();
@@ -486,9 +474,39 @@ void main() {
486474 expect (actualTurns, Matrix4 .rotationZ (math.pi * 1.5 ));
487475 });
488476
477+ testWidgets ('ScaleTransition animates' , (WidgetTester tester) async {
478+ AnimationController controller;
479+ Animation <double > animation;
489480
490- // ------------------------- scale
481+ controller = AnimationController (
482+ duration: const Duration (seconds: 5 ), vsync: const TestVSync ());
483+ animation = CurvedAnimation (parent: controller, curve: Curves .linear);
484+
485+ final Widget widget = GFAnimation (
486+ turnsAnimation: animation,
487+ controller: controller,
488+ type: GFAnimationType .scaleTransition,
489+ alignment: Alignment .topRight,
490+ child: const Text ('Scale' , textDirection: TextDirection .rtl),
491+ );
491492
493+ await tester.pumpWidget (widget);
494+ Transform actualRotatedBox = tester.widget (find.byType (Transform ));
495+ Matrix4 actualTurns = actualRotatedBox.transform;
496+ expect (actualTurns, equals (Matrix4 .rotationZ (0 )));
497+
498+ controller.value = 0.5 ;
499+ await tester.pump ();
500+ actualRotatedBox = tester.widget (find.byType (Transform ));
501+ actualTurns = actualRotatedBox.transform;
502+ expect (actualTurns, Matrix4 .rotationZ (math.pi));
503+
504+ controller.value = 0.75 ;
505+ await tester.pump ();
506+ actualRotatedBox = tester.widget (find.byType (Transform ));
507+ actualTurns = actualRotatedBox.transform;
508+ expect (actualTurns, Matrix4 .rotationZ (math.pi * 1.5 ));
509+ });
492510}
493511
494512class TestApp extends StatefulWidget {
0 commit comments