-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AppAsyncSliverWidget and AppAsyncSliver classes
- Loading branch information
1 parent
32019ca
commit 6c57faf
Showing
6 changed files
with
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class AppInfiniteRotationAnimation extends StatefulWidget { | ||
const AppInfiniteRotationAnimation({ | ||
required this.isLoading, | ||
required this.child, | ||
this.duration = const Duration(milliseconds: 700), | ||
super.key, | ||
}); | ||
final bool isLoading; | ||
final Widget child; | ||
final Duration duration; | ||
|
||
@override | ||
State<AppInfiniteRotationAnimation> createState() => | ||
_AppInfiniteRotationAnimationState(); | ||
} | ||
|
||
class _AppInfiniteRotationAnimationState | ||
extends State<AppInfiniteRotationAnimation> | ||
with SingleTickerProviderStateMixin { | ||
late AnimationController _controller; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_controller = AnimationController( | ||
duration: widget.duration, | ||
vsync: this, | ||
); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(covariant AppInfiniteRotationAnimation oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
if (widget.isLoading != oldWidget.isLoading) { | ||
if (widget.isLoading) { | ||
_controller.repeat(); | ||
} else { | ||
_controller.animateTo(0).then((_) => _controller.stop()); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return RotationTransition( | ||
turns: _controller, | ||
child: widget.child, | ||
); | ||
} | ||
} |
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