showMessage method
Future<void>
showMessage({
- String type = "info",
- String? message,
- Map? props,
- GestureTapCallback? onTap,
- BuildContext? context,
Builds a dialog displaying message
.
Implementation
Future<void> showMessage(
{String type = "info",
String? message,
Map? props,
GestureTapCallback? onTap,
BuildContext? context}) async {
if (message == null || message.isEmpty) {
return;
}
Color bgColor;
Color textColor;
switch (type) {
case "success":
bgColor = Colors.green;
textColor = Colors.white;
break;
case "warning":
bgColor = Colors.yellow.shade600;
textColor = Colors.black87;
break;
case "error":
bgColor = Colors.red.shade600;
textColor = Colors.white;
break;
default:
bgColor = Colors.blue.shade600;
textColor = Colors.white;
break;
}
context ??= appContext;
final widget = GestureDetector(
onTap: () {
appNavigator.pop();
if (onTap != null) {
onTap();
}
},
child: Text(properties.getText(message, "errorMessage")),
);
showGeneralDialog(
context: context,
barrierLabel: "",
barrierDismissible: true,
barrierColor: Colors.transparent,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, anim1, anim2) {
return SafeArea(
child: AlertDialog(
content: widget,
contentTextStyle: TextStyle(color: textColor, fontSize: 15),
contentPadding: const EdgeInsets.fromLTRB(24, 14, 24, 14),
alignment: Alignment.topCenter,
backgroundColor: bgColor,
elevation: 5,
));
},
transitionBuilder: (context, anim1, anim2, child) {
return SlideTransition(
position: Tween(begin: const Offset(0, -0.2), end: const Offset(0, 0))
.animate(anim1),
child: child,
);
},
);
}