Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding onTap on ExpandablePanel #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lib/expandable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ class ExpandablePanel extends StatelessWidget {
/// Builds an Expandable object, optional
final ExpandableBuilder? builder;

/// Callback when [ExpandablePanel] state changes,
/// return **true** value on [ExpandablePanel] expanded
final Function(bool)? onTap;

/// An optional controller. If not specified, a default controller will be
/// obtained from a surrounding [ExpandableNotifier]. If that does not exist,
/// the controller will be created with the initial state of [initialExpanded].
Expand All @@ -514,6 +518,7 @@ class ExpandablePanel extends StatelessWidget {
this.controller,
this.builder,
this.theme,
this.onTap
}) : super(key: key);

@override
Expand All @@ -535,7 +540,7 @@ class ExpandablePanel extends StatelessWidget {
Widget wrapWithExpandableButton(
{required Widget? widget, required bool wrap}) {
return wrap
? ExpandableButton(child: widget, theme: theme)
? ExpandableButton(child: widget, theme: theme, onTap: onTap)
: widget ?? Container();
}

Expand Down Expand Up @@ -591,6 +596,10 @@ class ExpandablePanel extends StatelessWidget {
onTap: () {
final controller = ExpandableController.of(context);
controller?.toggle();

if(onTap != null) {
onTap!(controller?.expanded ?? false);
}
},
);
}
Expand Down Expand Up @@ -751,8 +760,9 @@ class _ExpandableIconState extends State<ExpandableIcon>
class ExpandableButton extends StatelessWidget {
final Widget? child;
final ExpandableThemeData? theme;
final Function(bool)? onTap;

ExpandableButton({this.child, this.theme});
ExpandableButton({this.child, this.theme, this.onTap});

@override
Widget build(BuildContext context) {
Expand All @@ -761,13 +771,25 @@ class ExpandableButton extends StatelessWidget {

if (theme.useInkWell!) {
return InkWell(
onTap: controller?.toggle,
onTap: () {
controller?.toggle();

if(onTap != null) {
onTap!(controller?.expanded ?? false);
}
},
child: child,
borderRadius: theme.inkWellBorderRadius!,
);
} else {
return GestureDetector(
onTap: controller?.toggle,
onTap: () {
controller?.toggle();

if(onTap != null) {
onTap!(controller?.expanded ?? false);
}
},
child: child,
);
}
Expand Down