-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5495cee
commit 76bab00
Showing
5 changed files
with
339 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ToolTipAction extends StatelessWidget { | ||
const ToolTipAction({ | ||
Key? key, | ||
this.actionOne, | ||
this.actionTwo, | ||
this.actionPadding, | ||
this.alignment = WrapAlignment.spaceBetween, | ||
this.crossAxisAlignment = WrapCrossAlignment.center, | ||
}) : actions = null, | ||
super(key: key); | ||
|
||
const ToolTipAction.customAction({ | ||
Key? key, | ||
this.actions, | ||
this.actionPadding, | ||
this.alignment = WrapAlignment.spaceBetween, | ||
this.crossAxisAlignment = WrapCrossAlignment.center, | ||
}) : actionOne = null, | ||
actionTwo = null, | ||
super(key: key); | ||
|
||
/// Define configuration of first action | ||
final ActionWidgetConfig? actionOne; | ||
|
||
/// Define configuration of second action | ||
final ActionWidgetConfig? actionTwo; | ||
|
||
/// Define padding of action widget | ||
final EdgeInsets? actionPadding; | ||
|
||
/// Define configuration of list of action | ||
final List<ActionWidgetConfig>? actions; | ||
|
||
/// Define alignment of actions | ||
final WrapAlignment alignment; | ||
|
||
/// Define crossAxisAlignment of actions | ||
final WrapCrossAlignment crossAxisAlignment; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: actionPadding ?? EdgeInsets.zero, | ||
child: Wrap( | ||
alignment: alignment, | ||
crossAxisAlignment: crossAxisAlignment, | ||
children: actions != null | ||
? [for (final action in actions!) getActionWidget(action)] | ||
: [getActionWidget(actionOne), getActionWidget(actionTwo)], | ||
), | ||
); | ||
} | ||
|
||
Widget getActionWidget(ActionWidgetConfig? actionWidgetConfig) { | ||
if (actionWidgetConfig == null) return const SizedBox(); | ||
return GestureDetector( | ||
onTap: actionWidgetConfig.onActionTap, | ||
child: Container( | ||
decoration: actionWidgetConfig.decoration, | ||
padding: actionWidgetConfig.padding, | ||
margin: actionWidgetConfig.margin, | ||
child: Text( | ||
actionWidgetConfig.actionTitle, | ||
style: actionWidgetConfig.textStyle, | ||
maxLines: 1, | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ActionWidgetConfig { | ||
const ActionWidgetConfig({ | ||
Key? key, | ||
required this.actionTitle, | ||
this.decoration, | ||
this.padding, | ||
this.margin, | ||
this.textStyle, | ||
required this.onActionTap, | ||
}); | ||
|
||
/// Defines title of action | ||
final String actionTitle; | ||
|
||
/// Defines decoration of action | ||
final BoxDecoration? decoration; | ||
|
||
/// Provide padding to the action | ||
final EdgeInsets? padding; | ||
|
||
/// Provide margin to the action | ||
final EdgeInsets? margin; | ||
|
||
/// Define text style of action | ||
final TextStyle? textStyle; | ||
|
||
/// Called when user tap on action | ||
final VoidCallback onActionTap; | ||
} |
Oops, something went wrong.