showFlashMessage static method

void showFlashMessage({
  1. required String title,
  2. List<FlashAction>? actions,
  3. required String message,
  4. FlashType type = FlashType.info,
  5. Color backgroundColor = ColorHelper.white,
  6. Icon? icon,
  7. FlashPosition position = FlashPosition.top,
  8. EdgeInsets margin = const EdgeInsets.symmetric(vertical: 50, horizontal: 50),
  9. BorderRadius borderRadius = const BorderRadius.all(Radius.circular(2)),
  10. bool barrierDismissible = true,
  11. Duration duration = const Duration(seconds: 5),
})

Implementation

static void showFlashMessage({
  required String title,
  List<FlashAction>? actions,
  required String message,
  FlashType type = FlashType.info,
  Color backgroundColor = ColorHelper.white,
  Icon? icon,
  FlashPosition position = FlashPosition.top,
  EdgeInsets margin =
      const EdgeInsets.symmetric(vertical: 50, horizontal: 50),
  BorderRadius borderRadius = const BorderRadius.all(Radius.circular(2)),
  bool barrierDismissible = true,
  Duration duration = const Duration(seconds: 5),
}) {
  if (navigatorKey.currentContext == null) {
    return;
  }

  final context = navigatorKey.currentContext!;
  Widget icon;

  switch (type) {
    case FlashType.success:
      icon = const CircleAvatar(
          radius: 12,
          backgroundColor: ColorHelper.green,
          child: Icon(
            Icons.check,
            color: ColorHelper.white,
            size: 18,
          ));
      break;
    case FlashType.warning:
      icon = const CircleAvatar(
          radius: 12,
          backgroundColor: ColorHelper.goldIcon,
          child: Icon(
            Icons.warning,
            color: ColorHelper.white,
            size: 18,
          ));
      break;
    case FlashType.error:
      icon = const CircleAvatar(
          radius: 12,
          backgroundColor: ColorHelper.red02,
          child: Icon(
            Icons.close,
            color: ColorHelper.white,
            size: 18,
          ));
      break;
    case FlashType.info:
      icon = const CircleAvatar(
          radius: 12,
          backgroundColor: ColorHelper.alertInfo,
          child: Icon(
            Icons.info_outline_rounded,
            color: ColorHelper.white,
            size: 18,
          ));
    case FlashType.info:
    default:
      icon = const SizedBox();
  }
  showFlash<bool>(
    context: context,
    barrierDismissible: barrierDismissible,
    duration: duration,
    builder: (context, controller) {
      return FlashBar(
        padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 9),
        behavior: FlashBehavior.floating,
        clipBehavior: Clip.antiAlias,
        margin:  EdgeInsets.symmetric(
          vertical:context.isMobile?20: 70,),
        shape: RoundedRectangleBorder(borderRadius: borderRadius),
        controller: controller,
        position: position,

        content: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            icon,
            8.SpaceY,
            Expanded(
              child: Text(message,
                  style: const TextStyle(
                      color: ColorHelper.neutralMediumText,
                      fontSize: 14,
                      fontWeight: FontWeight.w400)),
            ),
            8.SpaceY,
            InkWell(
              onTap: () {
                controller.dismiss(true);
              },
              child: const Icon(
                Icons.close,
                color: ColorHelper.genericBorderColor,
              ),
            )
          ],
        ),
        // shadowColor: Color.fromRGBO(53, 90, 236, 0.1),
        elevation: 3,
        surfaceTintColor: Colors.white,
        // content: Text(message,
        //     style: const TextStyle(
        //         color: Colors.white,
        //         fontSize: 14,
        //         fontWeight: FontWeight.w400)),
        backgroundColor: Colors.white,
        actions: actions?.map(
          (action) {
            return TextButton(
              onPressed: action.onPressed == null
                  ? () {
                      controller.dismiss(true);
                    }
                  : () {
                      controller.dismiss(true);
                      action.onPressed!();
                    },
              child: Text(
                action.label,
                style: TextStyle(
                    color: action.textColor ?? ColorHelper.primaryColor2),
              ),
            );
          },
        ).toList(),
      );
    },
  );
}