-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add lifecycle methods to playanimation and customanimation
- Loading branch information
1 parent
f14fe9a
commit 4e73ff3
Showing
10 changed files
with
205 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:simple_animations/simple_animations.dart'; | ||
|
||
import './widget_tester_extension.dart'; | ||
|
||
void main() { | ||
testWidgets('CustomAnimation forward', (WidgetTester tester) async { | ||
var playing = false; | ||
final animation = MaterialApp( | ||
home: CustomAnimation<int>( | ||
control: CustomAnimationControl.play, | ||
duration: const Duration(days: 100), | ||
tween: IntTween(begin: 0, end: 100), | ||
builder: (context, child, value) => Container(), | ||
onStart: () => playing = true, | ||
onComplete: () => playing = false, | ||
)); | ||
|
||
expect(playing, false); | ||
|
||
await tester.addAnimationWidget(animation); | ||
await tester.wait(const Duration(days: 1)); | ||
expect(playing, true); | ||
|
||
await tester.wait(const Duration(days: 100)); | ||
expect(playing, false); | ||
}); | ||
|
||
testWidgets('CustomAnimation backwards', (WidgetTester tester) async { | ||
var playing = false; | ||
final animation = MaterialApp( | ||
home: CustomAnimation<int>( | ||
control: CustomAnimationControl.playReverse, | ||
startPosition: 1.0, | ||
duration: const Duration(days: 100), | ||
tween: IntTween(begin: 0, end: 100), | ||
builder: (context, child, value) => Container(), | ||
onStart: () => playing = true, | ||
onComplete: () => playing = false, | ||
)); | ||
|
||
expect(playing, false); | ||
|
||
await tester.addAnimationWidget(animation); | ||
await tester.wait(const Duration(days: 1)); | ||
expect(playing, true); | ||
|
||
await tester.wait(const Duration(days: 100)); | ||
expect(playing, false); | ||
}); | ||
|
||
testWidgets('PlayAnimation forward', (WidgetTester tester) async { | ||
var playing = false; | ||
final animation = MaterialApp( | ||
home: PlayAnimation<int>( | ||
duration: const Duration(days: 100), | ||
tween: IntTween(begin: 0, end: 100), | ||
builder: (context, child, value) => Container(), | ||
onStart: () => playing = true, | ||
onComplete: () => playing = false, | ||
)); | ||
|
||
expect(playing, false); | ||
|
||
await tester.addAnimationWidget(animation); | ||
await tester.wait(const Duration(days: 1)); | ||
expect(playing, true); | ||
|
||
await tester.wait(const Duration(days: 100)); | ||
expect(playing, false); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ignore_for_file: avoid_print | ||
//@start | ||
import 'package:flutter/material.dart'; | ||
import 'package:simple_animations/simple_animations.dart'; | ||
|
||
var widget = CustomAnimation<Color?>( | ||
onStart: () => print('Animation started'), | ||
onComplete: () => print('Animation complete'), | ||
tween: ColorTween(begin: Colors.red, end: Colors.blue), | ||
builder: (context, child, value) { | ||
return Container(color: value, width: 100, height: 100); | ||
}, | ||
); | ||
//@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ignore_for_file: avoid_print | ||
//@start | ||
import 'package:flutter/material.dart'; | ||
import 'package:simple_animations/simple_animations.dart'; | ||
|
||
var widget = PlayAnimation<Color?>( | ||
// Track animation status | ||
onStart: () => print('Animation started'), | ||
onComplete: () => print('Animation complete'), | ||
tween: ColorTween(begin: Colors.red, end: Colors.blue), | ||
builder: (context, child, value) => | ||
Container(color: value, width: 100, height: 100), | ||
); | ||
//@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters