Skip to content

Commit 198f01c

Browse files
committed
creates a callback for the toggle collapsed event
1 parent b32d9ae commit 198f01c

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

lib/components/accordian/gf_accordian.dart

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ class GFAccordion extends StatefulWidget {
1919
this.titleborder = const Border(),
2020
this.contentBorder = const Border(),
2121
this.margin,
22-
this.showAccordion = false})
22+
this.showAccordion = false,
23+
this.onToggleCollapsed})
2324
: super(key: key);
2425

26+
final Function(bool) onToggleCollapsed;
27+
2528
/// controls if the accordion should be collapsed or not making it possible to be controlled from outside
2629
final bool showAccordion;
2730

@@ -119,18 +122,7 @@ class _GFAccordionState extends State<GFAccordion>
119122
children: <Widget>[
120123
GestureDetector(
121124
onTap: () {
122-
setState(() {
123-
switch (controller.status) {
124-
case AnimationStatus.completed:
125-
controller.forward(from: 0);
126-
break;
127-
case AnimationStatus.dismissed:
128-
controller.forward();
129-
break;
130-
default:
131-
}
132-
showAccordion = !showAccordion;
133-
});
125+
_toggleCollapsed();
134126
},
135127
child: Container(
136128
decoration: BoxDecoration(
@@ -171,4 +163,22 @@ class _GFAccordionState extends State<GFAccordion>
171163
],
172164
),
173165
);
166+
167+
void _toggleCollapsed() {
168+
setState(() {
169+
switch (controller.status) {
170+
case AnimationStatus.completed:
171+
controller.forward(from: 0);
172+
break;
173+
case AnimationStatus.dismissed:
174+
controller.forward();
175+
break;
176+
default:
177+
}
178+
showAccordion = !showAccordion;
179+
});
180+
if (widget.onToggleCollapsed != null) {
181+
widget.onToggleCollapsed(showAccordion);
182+
}
183+
}
174184
}

0 commit comments

Comments
 (0)