Skip to content

Commit f5fc600

Browse files
committed
toast is in progress
1 parent 9c921a7 commit f5fc600

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

lib/components/toast/gf_toast.dart

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class GFToast extends StatefulWidget {
1515
this.backgroundColor,
1616
this.text,
1717
this.width,
18-
this.type= GFToastType.basic,
19-
20-
18+
this.type = GFToastType.basic,
19+
this.autoDismiss = true,
20+
this.duration = const Duration(seconds: 2),
2121
this.textStyle = const TextStyle(color: Colors.white70),
2222
}) : super(key: key);
2323

@@ -36,75 +36,84 @@ class GFToast extends StatefulWidget {
3636
/// textStyle of type [textStyle] will be applicable to text only and not for the child
3737
final TextStyle textStyle;
3838

39-
/// width od type [double] used to control the width od the [GFToast]
39+
/// width of type [double] used to control the width of the [GFToast]
4040
final double width;
4141

42-
final GFToastType type ;
43-
44-
42+
///type of [GFToastType] which takes the type ie, basic, rounded and fullWidth for the [GFToast]
43+
final GFToastType type;
4544

45+
///type of [bool] which takes bool values ie, true or false to automatically hide the [GFToast] message
46+
final bool autoDismiss;
4647

48+
///type of [Duration] which takes the duration of the fade in animation
49+
final Duration duration;
4750

4851
@override
4952
_GFToastState createState() => _GFToastState();
5053
}
5154

5255
class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
53-
AnimationController controller, _controller;
54-
Animation<Offset> offset, offset1;
55-
Animation<double> animation;
56-
Timer timer;
57-
58-
bool slide = false;
56+
AnimationController animationController, fadeanimationController;
57+
Animation<double> animation, fadeanimation;
5958

6059
@override
6160
void initState() {
62-
super.initState();
63-
64-
controller = AnimationController(
61+
animationController = AnimationController(
6562
duration: const Duration(milliseconds: 300), vsync: this);
66-
animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);
67-
_controller =
68-
AnimationController(vsync: this, duration: Duration(milliseconds: 200));
69-
offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0))
70-
.animate(_controller);
71-
72-
controller.forward();
73-
_controller.forward();
63+
animation =
64+
CurvedAnimation(parent: animationController, curve: Curves.easeIn);
65+
66+
animationController.forward();
67+
68+
fadeanimationController = AnimationController(
69+
vsync: this,
70+
duration: widget.duration,
71+
)..addListener(() => setState(() {}));
72+
fadeanimation = Tween<double>(
73+
begin: 0.0,
74+
end: 1.0,
75+
).animate(fadeanimationController);
76+
fadeanimationController.forward();
77+
fadeanimation = Tween<double>(
78+
begin: 1.0,
79+
end: 0.0,
80+
).animate(fadeanimationController);
81+
super.initState();
7482
}
7583

7684
@override
7785
void dispose() {
78-
controller.dispose();
86+
animationController.dispose();
87+
fadeanimationController.dispose();
7988
super.dispose();
8089
}
8190

8291
@override
8392
Widget build(BuildContext context) {
8493
return FadeTransition(
85-
opacity: animation,
94+
opacity: widget.autoDismiss ? fadeanimation : animation,
8695
child: Column(
8796
children: <Widget>[
8897
Container(
89-
width: widget.width ,
98+
width: widget.width,
9099
constraints: BoxConstraints(minHeight: 50.0),
91-
margin: widget.type == GFToastType.fullWidth ? EdgeInsets.only(left: 0, right: 0): EdgeInsets.only(left: 10, right: 10),
100+
margin: widget.type == GFToastType.fullWidth
101+
? EdgeInsets.only(left: 0, right: 0)
102+
: EdgeInsets.only(left: 10, right: 10),
92103
padding: EdgeInsets.all(10),
93104
decoration: BoxDecoration(
94-
// borderRadius: BorderRadius.all(Radius.circular(3)),
95-
borderRadius: widget.type == GFToastType.basic
96-
? BorderRadius.circular(0.0)
97-
: widget.type == GFToastType.rounded
98-
? BorderRadius.circular(10.0): BorderRadius.zero,
99-
color: widget.backgroundColor != null
100-
? getGFColor(widget.backgroundColor)
101-
: Color(0xff323232),
102-
boxShadow: [
103-
BoxShadow(
104-
color: Colors.black.withOpacity(0.40), blurRadius: 6.0
105-
)
106-
]
107-
),
105+
borderRadius: widget.type == GFToastType.basic
106+
? BorderRadius.circular(0.0)
107+
: widget.type == GFToastType.rounded
108+
? BorderRadius.circular(10.0)
109+
: BorderRadius.zero,
110+
color: widget.backgroundColor != null
111+
? getGFColor(widget.backgroundColor)
112+
: Color(0xff323232),
113+
boxShadow: [
114+
BoxShadow(
115+
color: Colors.black.withOpacity(0.40), blurRadius: 6.0)
116+
]),
108117
child: Row(
109118
children: <Widget>[
110119
Flexible(

0 commit comments

Comments
 (0)