Skip to content

Commit b6f0516

Browse files
committed
gf-accordian in progress
1 parent 668b96e commit b6f0516

File tree

1 file changed

+140
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)