Skip to content

Instantly share code, notes, and snippets.

@a7me63azzab
Created October 15, 2023 08:19
Show Gist options
  • Save a7me63azzab/d7430a78488515ba903230f340552860 to your computer and use it in GitHub Desktop.
Save a7me63azzab/d7430a78488515ba903230f340552860 to your computer and use it in GitHub Desktop.
Toast
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:rest_water_23/gen/assets.gen.dart';
import 'package:rest_water_23/presentation/core/navigation_services.dart';
enum MessageType { success, fail, warning }
void showToast(String msg, {int duration = 2, MessageType msgType = MessageType.fail, bool backFromScreen = false, bool closeLoading = false}) async {
if (msg.isNotEmpty) {
ScaffoldMessenger.of(NavigationService.navigatorKey.currentContext!).clearSnackBars();
ScaffoldMessenger.of(NavigationService.navigatorKey.currentContext!).showSnackBar(
SnackBar(
behavior: SnackBarBehavior.floating,
margin: EdgeInsetsDirectional.only(bottom: 50.h, start: 40.w, end: 40.w),
elevation: 0,
backgroundColor: Colors.white,
clipBehavior: Clip.antiAlias,
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r), side: BorderSide(color: getBgColor(msgType))),
content: Container(
decoration: BoxDecoration(
color: getBgColor(msgType).withOpacity(.1),
borderRadius: BorderRadius.circular(8.r),
),
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Row(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 5.r, vertical: 7.h),
decoration: BoxDecoration(color: getBgColor(msgType).withOpacity(.1), shape: BoxShape.circle),
child: Center(
child: SvgPicture.asset(
Assets.icons.svg.logo,
fit: BoxFit.scaleDown,
height: 12.h,
width: 12.h,
// color: getBgColor(msgType),
),
),
),
SizedBox(
width: 6.w,
),
Expanded(
child: Text(msg, maxLines: 5, overflow: TextOverflow.ellipsis, textAlign: TextAlign.start, softWrap: true, style: TextStyle(fontSize: 12.sp, color: getBgColor(msgType))),
),
],
),
),
),
);
}
}
Color getBgColor(MessageType msgType) {
return msgType == MessageType.success
? const Color(0xff29CA8C)
: msgType == MessageType.warning
? const Color(0xffE9C200)
: const Color(0xffF02B2B);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment