Skip to content

Commit 01793c9

Browse files
authored
Merge pull request #68 from shravyackm/toast
Toast
2 parents 0d6bb2d + 27e5139 commit 01793c9

File tree

4 files changed

+338
-13
lines changed

4 files changed

+338
-13
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:getflutter/colors/gf_color.dart';
3+
4+
class GFAccordion extends StatefulWidget {
5+
6+
const GFAccordion(
7+
{Key key,
8+
this.child,
9+
this.content,
10+
this.titlebackgroundColor,
11+
this.collapsedIcon = const Icon(Icons.keyboard_arrow_down),
12+
this.expandedIcon =
13+
const Icon(Icons.keyboard_arrow_up, color: Colors.red),
14+
this.title,
15+
this.textStyle = const TextStyle(color: Colors.black, fontSize: 16),
16+
this.titlePadding,
17+
this.descriptionPadding,
18+
this.descriptionbackgroundColor,
19+
this.contentChild,
20+
this.margin})
21+
: super(key: key);
22+
23+
/// child of type [Widget]is alternative to title key. title will get priority over child
24+
final Widget child;
25+
26+
/// content of type[String] which shows the messages after the [GFAccordion] is expanded
27+
final String content;
28+
29+
/// contentChild of type [Widget]is alternative to content key. content will get priority over contentChild
30+
final Widget contentChild;
31+
32+
/// type of [Color] or [GFColor] which is used to change the background color of the [GFAccordion] title
33+
final dynamic titlebackgroundColor;
34+
35+
///collapsedIcon of type [Widget] which is used to show when the [GFAccordion] is collapsed
36+
final Widget collapsedIcon;
37+
38+
///expandedIcon of type[Widget] which is used when the [GFAccordion] is expanded
39+
final Widget expandedIcon;
40+
41+
/// text of type [String] is alternative to child. text will get priority over child
42+
final String title;
43+
44+
/// textStyle of type [textStyle] will be applicable to text only and not for the child
45+
final TextStyle textStyle;
46+
47+
///titlePadding of type [EdgeInsets] which is used to set the padding of the [GFAccordion] title
48+
final EdgeInsets titlePadding;
49+
50+
///descriptionPadding of type [EdgeInsets] which is used to set the padding of the [GFAccordion] description
51+
final EdgeInsets descriptionPadding;
52+
53+
/// type of [Color] or [GFColor] which is used to change the background color of the [GFAccordion] description
54+
final dynamic descriptionbackgroundColor;
55+
56+
///margin of type [EdgeInsets] which is used to set the margin of the [GFAccordion]
57+
final EdgeInsets margin;
58+
59+
@override
60+
_GFAccordionState createState() => _GFAccordionState();
61+
}
62+
63+
class _GFAccordionState extends State<GFAccordion>
64+
with TickerProviderStateMixin {
65+
AnimationController animationController;
66+
AnimationController controller;
67+
Animation<Offset> offset;
68+
69+
@override
70+
void initState() {
71+
super.initState();
72+
animationController =
73+
AnimationController(duration: Duration(seconds: 2), vsync: this);
74+
controller =
75+
AnimationController(vsync: this, duration: Duration(milliseconds: 300));
76+
offset = Tween(begin: Offset(0.0, -0.06), end: Offset.zero).animate(
77+
CurvedAnimation(
78+
parent: controller,
79+
curve: Curves.fastOutSlowIn,
80+
),
81+
);
82+
}
83+
84+
bool showAccordion = false;
85+
86+
@override
87+
Widget build(BuildContext context) {
88+
return Container(
89+
margin: widget.margin != null ? widget.margin : EdgeInsets.all(10),
90+
child: Column(
91+
crossAxisAlignment: CrossAxisAlignment.start,
92+
children: <Widget>[
93+
GestureDetector(
94+
onTap: () {
95+
setState(() {
96+
switch (controller.status) {
97+
case AnimationStatus.completed:
98+
controller.forward(from: 0);
99+
break;
100+
case AnimationStatus.dismissed:
101+
controller.forward();
102+
break;
103+
default:
104+
}
105+
showAccordion = !showAccordion;
106+
});
107+
},
108+
child: Container(
109+
color: widget.titlebackgroundColor != null
110+
? widget.titlebackgroundColor
111+
: Colors.white,
112+
padding: widget.titlePadding != null
113+
? widget.titlePadding
114+
: EdgeInsets.all(10),
115+
child: Row(
116+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
117+
children: <Widget>[
118+
Expanded(
119+
child: widget.title != null
120+
? Text(widget.title, style: widget.textStyle)
121+
: (widget.child ?? Container()),
122+
),
123+
showAccordion ? widget.expandedIcon : widget.collapsedIcon
124+
],
125+
),
126+
),
127+
),
128+
showAccordion
129+
? Container(
130+
width: MediaQuery.of(context).size.width,
131+
color: widget.descriptionbackgroundColor != null
132+
? widget.descriptionbackgroundColor
133+
: Colors.white70,
134+
padding: widget.descriptionPadding != null
135+
? widget.descriptionPadding
136+
: EdgeInsets.all(10),
137+
child: SlideTransition(
138+
position: offset,
139+
child: widget.content != null
140+
? Text(widget.content)
141+
: (widget.contentChild ?? Container()),
142+
))
143+
: Container()
144+
],
145+
),
146+
);
147+
}
148+
}

lib/components/alert/gf_alert.dart

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/widgets.dart';
3+
import 'package:getflutter/getflutter.dart';
4+
import 'package:getflutter/types/gf_alert_type.dart';
5+
6+
class GFAlert extends StatefulWidget {
7+
8+
/// Alert has to be wrap inside the body like [GFFloatingWidget]. See [GFFloatingWidget]
9+
GFAlert(
10+
{Key key,
11+
this.child,
12+
this.backgroundColor,
13+
this.content,
14+
this.width,
15+
this.type = GFAlertType.basic,
16+
this.alignment,
17+
this.contentChild,
18+
this.title,
19+
this.bottombar,
20+
this.animationDuration = const Duration(milliseconds: 300),
21+
this.textStyle = const TextStyle(color: Colors.black87),
22+
this.titleTextStyle = const TextStyle(
23+
color: Colors.black87, fontSize: 17, fontWeight: FontWeight.w500)})
24+
: super(key: key);
25+
26+
/// child of type [Widget]is alternative to text key. text will get priority over child
27+
final Widget child;
28+
29+
/// title of type [String] used to descripe the title of the [GFAlert]
30+
final String title;
31+
32+
/// child of type [Widget]is alternative to title key. title will get priority over contentchild
33+
final Widget contentChild;
34+
35+
/// title of type [String] used to describe the content of the [GFAlert]
36+
final String content;
37+
38+
final TextStyle titleTextStyle;
39+
40+
///pass color of type [Color] or [GFColor] for background of [GFAlert]
41+
final dynamic backgroundColor;
42+
43+
/// textStyle of type [textStyle] will be applicable to text only and not for the child
44+
final TextStyle textStyle;
45+
46+
/// width of type [double] used to control the width of the [GFAlert]
47+
final double width;
48+
49+
///type of [GFAlertType] which takes the type ie, basic, rounded and fullWidth for the [GFAlert]
50+
final GFAlertType type;
51+
52+
///type of [Duration] which takes the duration of the fade in animation
53+
final Duration animationDuration;
54+
55+
/// type of [Alignment] used to align the text inside the toast
56+
final Alignment alignment;
57+
58+
///type of [Widget] used for the buttons ie, OK, Cancel for the action in [GFAlert]
59+
final Widget bottombar;
60+
@override
61+
_GFAlertState createState() => _GFAlertState();
62+
}
63+
64+
class _GFAlertState extends State<GFAlert> with TickerProviderStateMixin {
65+
AnimationController animationController;
66+
Animation<double> animation;
67+
68+
@override
69+
void initState() {
70+
animationController = AnimationController(
71+
duration: const Duration(milliseconds: 300), vsync: this);
72+
animation = CurvedAnimation(
73+
parent: animationController, curve: Curves.fastOutSlowIn);
74+
75+
animationController.forward();
76+
super.initState();
77+
}
78+
79+
@override
80+
void dispose() {
81+
animationController.dispose();
82+
super.dispose();
83+
}
84+
85+
@override
86+
Widget build(BuildContext context) {
87+
return Stack(
88+
children: <Widget>[
89+
Container(
90+
height: MediaQuery.of(context).size.height,
91+
),
92+
FadeTransition(
93+
opacity: animation,
94+
child: Column(
95+
children: <Widget>[
96+
Container(
97+
width: widget.type == GFAlertType.fullWidth
98+
? MediaQuery.of(context).size.width
99+
: widget.width,
100+
constraints: BoxConstraints(minHeight: 50.0),
101+
margin: widget.type == GFAlertType.fullWidth
102+
? EdgeInsets.only(left: 0, right: 0)
103+
: EdgeInsets.only(left: 20, right: 20),
104+
padding: EdgeInsets.all(15),
105+
decoration: BoxDecoration(
106+
borderRadius: widget.type == GFAlertType.basic
107+
? BorderRadius.circular(3.0)
108+
: widget.type == GFAlertType.rounded
109+
? BorderRadius.circular(10.0)
110+
: BorderRadius.zero,
111+
color: widget.backgroundColor != null
112+
? GFColors.getGFColor(widget.backgroundColor)
113+
: GFColors.getGFColor(GFColor.white),
114+
boxShadow: [
115+
BoxShadow(
116+
color: Colors.black.withOpacity(0.40),
117+
blurRadius: 3.0)
118+
]),
119+
child: Column(
120+
crossAxisAlignment: CrossAxisAlignment.start,
121+
children: <Widget>[
122+
widget.title != null
123+
? Text(widget.title, style: widget.titleTextStyle)
124+
: (widget.child ?? Container()),
125+
SizedBox(
126+
height: 10,
127+
),
128+
Align(
129+
alignment: widget.alignment != null
130+
? widget.alignment
131+
: Alignment.topLeft,
132+
child: widget.content != null
133+
? Text(widget.content, style: widget.textStyle)
134+
: (widget.contentChild ?? Container()),
135+
),
136+
SizedBox(
137+
height: 10,
138+
),
139+
widget.bottombar != null ? widget.bottombar : Container(),
140+
],
141+
),
142+
),
143+
],
144+
),
145+
),
146+
],
147+
);
148+
}
149+
}

lib/components/toast/gf_floating_widget.dart

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class GFFloatingWidget extends StatefulWidget {
99
this.child,
1010
this.horizontalPosition,
1111
this.verticalPosition,
12+
this.color,
13+
this.blur=false,
1214
this.body})
1315
: super(key: key);
1416

@@ -24,6 +26,17 @@ class GFFloatingWidget extends StatefulWidget {
2426
/// verticalPosition of type [double] which aligns the child vertically across the body
2527
final double verticalPosition;
2628

29+
30+
final dynamic color;
31+
32+
final bool blur;
33+
34+
35+
36+
37+
38+
39+
2740
@override
2841
_GFFloatingWidgetState createState() => _GFFloatingWidgetState();
2942
}
@@ -39,19 +52,33 @@ class _GFFloatingWidgetState extends State<GFFloatingWidget> {
3952
height: MediaQuery.of(context).size.height,
4053
child: widget.body ?? Container(),
4154
),
42-
Positioned(
43-
top:
44-
widget.verticalPosition != null ? widget.verticalPosition : 0.0,
45-
left: widget.horizontalPosition != null
46-
? widget.horizontalPosition
47-
: 0.0,
48-
right: widget.horizontalPosition != null
49-
? widget.horizontalPosition
50-
: 0.0,
51-
child: Container(
52-
width: MediaQuery.of(context).size.width,
53-
child: widget.child ?? Container(),
54-
)),
55+
Container(
56+
// color: widget.child!=null? widget.color: null,
57+
child: Stack(
58+
children: <Widget>[
59+
Positioned(
60+
child:Container(
61+
alignment: Alignment.topLeft,
62+
// color: widget.child!=null? widget.color: null,
63+
color: widget.blur?Colors.black38:null,
64+
child: Stack(
65+
children: <Widget>[
66+
Positioned( top:
67+
widget.verticalPosition != null ? widget.verticalPosition : 0.0,
68+
left: widget.horizontalPosition != null
69+
? widget.horizontalPosition
70+
: 0.0,
71+
right: widget.horizontalPosition != null
72+
? widget.horizontalPosition
73+
: 0.0,child: widget.child??Container(),)
74+
],
75+
)
76+
)
77+
),
78+
],
79+
)
80+
)
81+
5582
],
5683
);
5784
}

lib/types/gf_alert_type.dart

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

0 commit comments

Comments
 (0)