showToast method

Future<void> showToast(
  1. dynamic message, {
  2. MessageType type = MessageType.info,
  3. Duration duration = const Duration(seconds: 3),
})

Implementation

Future<void> showToast(
  dynamic message, {
  MessageType type = MessageType.info,
  Duration duration = const Duration(seconds: 3),
}) async {
  unawaited(HapticFeedback.lightImpact());
  try {
    return await showFlash(
      context: this,
      duration: duration,
      builder: (context, controller) {
        return FlashBar(
          controller: controller,
          shouldIconPulse: true,
          position: FlashPosition.top,
          behavior: FlashBehavior.floating,
          padding: EdgeInsets.zero,
          shadowColor: type.color.withValues(alpha: 0.05),
          content: Container(
            decoration: ShapeDecoration(
              color: type.color.withValues(alpha: 0.05),
              shape: RoundedSuperellipseBorder(
                borderRadius: const BorderRadius.all(
                  Radius.circular(12.0),
                ),
                side: BorderSide(
                  color: type.color,
                  width: Spacing.d1,
                  strokeAlign: BorderSide.strokeAlignInside,
                ),
              ),
            ),
            child: Row(
              children: [
                Spacing.h16,
                type.icon,
                Spacing.h8,
                Expanded(
                  child: Padding(
                    padding: EdgeInsets.symmetric(
                      vertical: Spacing.d16,
                    ),
                    child: Text(
                      '$message',
                      style: TextStyle(
                        color: type.color,
                      ),
                    ),
                  ),
                ),
                Spacing.h16,
              ],
            ),
          ),
        );
      },
    );
  } catch (_) {}
}