Skip to content

Commit c677216

Browse files
authored
Merge pull request #56 from shravyackm/toast
Toast
2 parents 819ac5d + c2d9b75 commit c677216

File tree

5 files changed

+119
-63
lines changed

5 files changed

+119
-63
lines changed

lib/components/badge/gf_badge.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GFBadge extends StatefulWidget {
3939
this.shape = GFBadgeShape.standard,
4040
this.color = GFColor.danger,
4141
this.textColor = GFColor.white,
42-
this.size = GFSize.medium,
42+
this.size = GFSize.small,
4343
this.border,
4444
this.text,
4545
this.child,

lib/components/badge/gf_icon_badge.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class GFIconBadge extends StatefulWidget {
2727
}
2828

2929
class _GFIconBadgeState extends State<GFIconBadge> {
30-
double size;
31-
3230
@override
3331
Widget build(BuildContext context) {
3432
return Container(
@@ -37,8 +35,9 @@ class _GFIconBadgeState extends State<GFIconBadge> {
3735
children: <Widget>[
3836
widget.child ?? Container(),
3937
new Positioned(
40-
top: 2,
41-
left: 22,
38+
// top: 2,
39+
// left: 22,
40+
right: 0,
4241
child: widget.counterChild ?? Container(),
4342
),
4443
],

lib/components/button/gf_icon_button.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ class _GFIconButtonState extends State<GFIconButton> {
226226
this.width = 35.0;
227227
this.iconPixel = 18.0;
228228
} else if (widget.size == GFSize.large) {
229-
print('her');
230229
this.height = 40.0;
231230
this.width = 40.0;
232231
this.iconPixel = 18.0;

lib/components/toast/gf_toast.dart

Lines changed: 114 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
33
import 'package:flutter/widgets.dart';
44
import 'package:getflutter/colors/gf_color.dart';
55
import 'package:getflutter/components/toast/gf_floating_widget.dart';
6+
import 'package:getflutter/types/gf_toast_type.dart';
67

78
class GFToast extends StatefulWidget {
89
///Creates [GFToast] that can be used to display quick warning or error messages.
@@ -14,6 +15,11 @@ class GFToast extends StatefulWidget {
1415
this.backgroundColor,
1516
this.text,
1617
this.width,
18+
this.type = GFToastType.basic,
19+
this.autoDismiss = true,
20+
this.alignment,
21+
this.animationDuration = const Duration(seconds: 2),
22+
this.duration = const Duration(seconds: 2),
1723
this.textStyle = const TextStyle(color: Colors.white70),
1824
}) : super(key: key);
1925

@@ -32,86 +38,137 @@ class GFToast extends StatefulWidget {
3238
/// textStyle of type [textStyle] will be applicable to text only and not for the child
3339
final TextStyle textStyle;
3440

35-
/// width od type [double] used to control the width od the [GFToast]
41+
/// width of type [double] used to control the width of the [GFToast]
3642
final double width;
3743

44+
///type of [GFToastType] which takes the type ie, basic, rounded and fullWidth for the [GFToast]
45+
final GFToastType type;
46+
47+
///type of [bool] which takes bool values ie, true or false to automatically hide the [GFToast] message
48+
final bool autoDismiss;
49+
50+
///type of [Duration] which takes the duration of the fade in animation
51+
final Duration animationDuration;
52+
53+
///type of [Duration] which takes the duration of the animation
54+
final Duration duration;
55+
56+
/// type of [Alignment] used to align the text inside the toast
57+
final Alignment alignment;
58+
3859
@override
3960
_GFToastState createState() => _GFToastState();
4061
}
4162

4263
class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
43-
AnimationController controller, _controller;
44-
Animation<Offset> offset, offset1;
45-
Animation<double> animation;
46-
Timer timer;
47-
48-
bool slide = false;
64+
AnimationController animationController, fadeanimationController;
65+
Animation<double> animation, fadeanimation;
66+
bool hideToast = false;
4967

5068
@override
5169
void initState() {
52-
super.initState();
70+
animationController = AnimationController(
71+
duration: const Duration(milliseconds: 2000), vsync: this);
72+
animation =
73+
CurvedAnimation(parent: animationController, curve: Curves.easeIn);
5374

54-
controller = AnimationController(
55-
duration: const Duration(milliseconds: 300), vsync: this);
56-
animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);
57-
_controller =
58-
AnimationController(vsync: this, duration: Duration(milliseconds: 200));
59-
offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0))
60-
.animate(_controller);
61-
controller.forward();
62-
_controller.forward();
75+
animationController.forward();
76+
77+
fadeanimationController = AnimationController(
78+
vsync: this,
79+
duration: widget.animationDuration,
80+
)..addListener(() => setState(() {}));
81+
fadeanimation = Tween<double>(
82+
begin: 0.0,
83+
end: 1.0,
84+
).animate(fadeanimationController);
85+
Timer(widget.duration, () {
86+
fadeanimationController.forward();
87+
});
88+
89+
fadeanimation = Tween<double>(
90+
begin: 1.0,
91+
end: 0.0,
92+
).animate(fadeanimationController);
93+
94+
fadeanimation.addStatusListener((AnimationStatus state) {
95+
if (fadeanimation.isCompleted && widget.autoDismiss) {
96+
setState(() {
97+
hideToast = true;
98+
});
99+
}
100+
});
101+
super.initState();
63102
}
64103

65104
@override
66105
void dispose() {
67-
controller.dispose();
106+
animationController.dispose();
107+
fadeanimationController.dispose();
68108
super.dispose();
69109
}
70110

71111
@override
72112
Widget build(BuildContext context) {
73-
return FadeTransition(
74-
opacity: animation,
75-
child: Column(
76-
children: <Widget>[
77-
Container(
78-
width: widget.width != null ? widget.width : null,
79-
constraints: BoxConstraints(minHeight: 50.0),
80-
// width: 100,
81-
margin: EdgeInsets.only(left: 10, right: 10),
82-
padding: EdgeInsets.all(10),
83-
decoration: BoxDecoration(
84-
borderRadius: BorderRadius.all(Radius.circular(3)),
85-
color: widget.backgroundColor != null
86-
? GFColors.getGFColor(widget.backgroundColor)
87-
: Color(0xff323232),
88-
),
89-
child: Row(
113+
return hideToast
114+
? Container()
115+
: FadeTransition(
116+
opacity: widget.autoDismiss ? fadeanimation : animation,
117+
child: Column(
90118
children: <Widget>[
91-
Flexible(
92-
flex: 7,
93-
fit: FlexFit.tight,
94-
child: widget.text != null
95-
? Text(widget.text, style: widget.textStyle)
96-
: (widget.child ?? Container()),
97-
),
98-
SizedBox(
99-
width: 10,
119+
Container(
120+
width: widget.type == GFToastType.fullWidth
121+
? MediaQuery.of(context).size.width
122+
: widget.width,
123+
constraints: BoxConstraints(minHeight: 50.0),
124+
margin: widget.type == GFToastType.fullWidth
125+
? EdgeInsets.only(left: 0, right: 0)
126+
: EdgeInsets.only(left: 10, right: 10),
127+
padding: EdgeInsets.all(10),
128+
decoration: BoxDecoration(
129+
borderRadius: widget.type == GFToastType.basic
130+
? BorderRadius.circular(0.0)
131+
: widget.type == GFToastType.rounded
132+
? BorderRadius.circular(10.0)
133+
: BorderRadius.zero,
134+
color: widget.backgroundColor != null
135+
? GFColors.getGFColor(widget.backgroundColor)
136+
: Color(0xff323232),
137+
boxShadow: [
138+
BoxShadow(
139+
color: Colors.black.withOpacity(0.40),
140+
blurRadius: 6.0)
141+
]),
142+
child: Row(
143+
children: <Widget>[
144+
Flexible(
145+
flex: 7,
146+
fit: FlexFit.tight,
147+
child: Align(
148+
alignment: widget.alignment != null
149+
? widget.alignment
150+
: Alignment.topLeft,
151+
child: widget.text != null
152+
? Text(widget.text, style: widget.textStyle)
153+
: (widget.child ?? Container()),
154+
)),
155+
SizedBox(
156+
width: 10,
157+
),
158+
widget.button != null
159+
? Flexible(
160+
flex: 4,
161+
fit: FlexFit.tight,
162+
child: Align(
163+
alignment: Alignment.topRight,
164+
child: widget.button,
165+
))
166+
: Container()
167+
],
168+
),
100169
),
101-
widget.button != null
102-
? Flexible(
103-
flex: 4,
104-
fit: FlexFit.tight,
105-
child: Align(
106-
alignment: Alignment.topRight,
107-
child: widget.button,
108-
))
109-
: Container()
110170
],
111171
),
112-
),
113-
],
114-
),
115-
);
172+
);
116173
}
117174
}

lib/types/gf_toast_type.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum GFToastType { basic, rounded, fullWidth }

0 commit comments

Comments
 (0)