Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions lib/components/toast/gf_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GFToast extends StatefulWidget {
this.animationDuration = const Duration(milliseconds: 300),
this.duration = const Duration(milliseconds: 300),
this.textStyle = const TextStyle(color: Colors.white70),
this. autoDismissDuration= const Duration(milliseconds: 3000),
}) : super(key: key);

/// child of type [Widget]is alternative to text key. text will get priority over child
Expand Down Expand Up @@ -51,6 +52,9 @@ class GFToast extends StatefulWidget {
///type of [Duration] which takes the duration of the animation
final Duration duration;

///type of [Duration] which takes the duration of the autoDismiss
final Duration autoDismissDuration;

/// type of [Alignment] used to align the text inside the toast
final Alignment alignment;

Expand All @@ -74,37 +78,43 @@ class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
curve: Curves.easeIn,
);

animationController.forward();
fadeanimationController = AnimationController(
vsync: this,
duration: widget.animationDuration,
)..addListener(() => setState(() {}));
fadeanimation = Tween<double>(
begin: 0,
end: 1,
).animate(fadeanimationController);
Timer(widget.duration, () {
fadeanimationController.forward();
});

fadeanimation = Tween<double>(
begin: 1,
end: 0,
).animate(fadeanimationController);
fadeanimation.addStatusListener((AnimationStatus state) {
if (fadeanimation.isCompleted && widget.autoDismiss) {
setState(() {
hideToast = true;
});
}
});
if(mounted) {
animationController.forward();
fadeanimationController = AnimationController(
vsync: this,
duration: widget.animationDuration,
)
..addListener(() => setState(() {}));
fadeanimation = Tween<double>(
begin: 0,
end: 1,
).animate(fadeanimationController);
Timer(widget.duration, () {
if(mounted){
fadeanimationController.forward();
}
});
fadeanimation = Tween<double>(
begin: 1,
end: 0,
).animate(fadeanimationController);
fadeanimation.addStatusListener((AnimationStatus state) {
if (fadeanimation.isCompleted && widget.autoDismiss) {
setState(() {
hideToast = true;
});
}
});
}

super.initState();
}

@override
void dispose() {
animationController.dispose();
fadeanimationController.dispose();

super.dispose();
}

Expand Down