TF-3487 Create retriable failure state and toast

This commit is contained in:
DatDang
2025-02-24 10:37:07 +07:00
committed by Dat H. Pham
parent e595aa02a0
commit 91dddff18d
6 changed files with 245 additions and 2 deletions
+118
View File
@@ -184,4 +184,122 @@ class AppToast {
: (duration ?? const Duration(seconds: 3)),
);
}
void showToastMessageWithMultipleActions(
BuildContext context,
String message,
{
List<({
String? actionName,
Function? onActionClick,
Widget? actionIcon
})> actions = const [],
Widget? leadingIcon,
String? leadingSVGIcon,
Color? leadingSVGIconColor,
double? maxWidth,
bool infinityToast = false,
Color? backgroundColor,
Color? textColor,
Color? textActionColor,
TextStyle? textStyle,
EdgeInsets? padding,
TextAlign? textAlign,
Duration? duration,
}
) {
final responsiveUtils = Get.find<ResponsiveUtils>();
List<Widget> trailingWidgets = [];
for (var action in actions) {
if (action.actionName == null) continue;
if (action.actionIcon == null) {
trailingWidgets.add(PointerInterceptor(
child: TextButton(
onPressed: () {
ToastView.dismiss();
action.onActionClick?.call();
},
child: Text(
action.actionName!,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal,
color: textActionColor ?? Colors.white
),
),
),
));
} else {
trailingWidgets.add(PointerInterceptor(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
ToastView.dismiss();
action.onActionClick?.call();
},
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
action.actionIcon!,
Text(
action.actionName!,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal,
color: textActionColor ?? Colors.white
),
)
],
),
),
),
),
));
}
}
Widget? leadingWidget;
if (leadingIcon != null) {
leadingWidget = PointerInterceptor(child: leadingIcon);
} else {
if (leadingSVGIcon != null) {
leadingWidget = PointerInterceptor(
child: SvgPicture.asset(
leadingSVGIcon,
width: 24,
height: 24,
fit: BoxFit.fill,
colorFilter: leadingSVGIconColor?.asFilter(),
)
);
}
}
TMailToast.showToast(
message,
context,
maxWidth: maxWidth ?? responsiveUtils.getMaxWidthToast(context),
toastPosition: ToastPosition.BOTTOM,
textStyle: textStyle ?? TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal,
color: textColor ?? AppColor.primaryColor
),
backgroundColor: backgroundColor ?? Colors.white,
trailing: Row(children: trailingWidgets),
leading: leadingWidget,
padding: padding,
textAlign: textAlign,
toastDuration: infinityToast
? null
: (duration ?? const Duration(seconds: 3)),
);
}
}