import 'package:flutter/material.dart'; // import 'package:fluttertoast/fluttertoast.dart'; import 'package:toastification/toastification.dart'; import 'package:nhancepolicy/logger.dart'; class ToastHelper { static void showSuccessToast(BuildContext context, String message) { toastification.show( context: context, type: ToastificationType.success, style: ToastificationStyle.flatColored, autoCloseDuration: const Duration(seconds: 2), title: Text( message, maxLines: 3, // ✅ allow wrapping overflow: TextOverflow.visible, softWrap: true, ), // you can also use RichText widget for title and description parameters // description: RichText( // text: const TextSpan(text: 'This is a sample toast message. ')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 100), animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: child, ); }, icon: const Icon(Icons.check), primaryColor: Colors.green, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButtonShowType: CloseButtonShowType.onHover, closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (toastItem) => logDebug('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => logDebug('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => logDebug('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => logDebug('Toast ${toastItem.id} dismissed'), ), ); } static void showWarningToast(BuildContext context, String message) { toastification.show( context: context, type: ToastificationType.warning, style: ToastificationStyle.flatColored, autoCloseDuration: const Duration(seconds: 2), title: Text(message), // you can also use RichText widget for title and description parameters // description: RichText( // text: const TextSpan(text: 'This is a sample toast message. ')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 100), animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: child, ); }, icon: const Icon(Icons.warning), primaryColor: Colors.amberAccent, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButtonShowType: CloseButtonShowType.onHover, closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (toastItem) => logDebug('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => logDebug('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => logDebug('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => logDebug('Toast ${toastItem.id} dismissed'), ), ); } static void showErrorToast(BuildContext context, String message) { toastification.show( context: context, type: ToastificationType.error, style: ToastificationStyle.flatColored, autoCloseDuration: const Duration(seconds: 2), title: Text( message, maxLines: 3, // ✅ allow wrapping overflow: TextOverflow.visible, softWrap: true, ), // you can also use RichText widget for title and description parameters // description: RichText( // text: const TextSpan(text: 'This is a sample toast message. ')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 100), animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: child, ); }, icon: const Icon(Icons.error), primaryColor: Colors.redAccent, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButtonShowType: CloseButtonShowType.onHover, closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (toastItem) => logDebug('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => logDebug('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => logDebug('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => logDebug('Toast ${toastItem.id} dismissed'), ), ); // _showToast(context, message, Colors.red); } static void showErrorToast2( BuildContext context, String message, String decmessage) { toastification.show( context: context, type: ToastificationType.error, style: ToastificationStyle.flatColored, autoCloseDuration: const Duration(seconds: 2), title: Text(message), // you can also use RichText widget for title and description parameters description: RichText(text: TextSpan(text: decmessage)), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 100), animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: child, ); }, icon: const Icon(Icons.error), primaryColor: Colors.redAccent, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButtonShowType: CloseButtonShowType.onHover, closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (toastItem) => logDebug('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => logDebug('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => logDebug('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => logDebug('Toast ${toastItem.id} dismissed'), ), ); // _showToast(context, message, Colors.red); } static void showInfoToast(BuildContext context, String message) { toastification.show( context: context, type: ToastificationType.info, style: ToastificationStyle.flatColored, autoCloseDuration: const Duration(seconds: 2), title: Text(message), // you can also use RichText widget for title and description parameters // description: RichText( // text: const TextSpan(text: 'This is a sample toast message. ')), alignment: Alignment.topRight, direction: TextDirection.ltr, animationDuration: const Duration(milliseconds: 100), animationBuilder: (context, animation, alignment, child) { return FadeTransition( opacity: animation, child: child, ); }, icon: const Icon(Icons.info), primaryColor: Colors.lightBlue, backgroundColor: Colors.white, foregroundColor: Colors.black, padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), borderRadius: BorderRadius.circular(12), boxShadow: const [ BoxShadow( color: Color(0x07000000), blurRadius: 16, offset: Offset(0, 16), spreadRadius: 0, ) ], showProgressBar: true, closeButtonShowType: CloseButtonShowType.onHover, closeOnClick: false, pauseOnHover: true, dragToClose: true, applyBlurEffect: true, callbacks: ToastificationCallbacks( onTap: (toastItem) => logDebug('Toast ${toastItem.id} tapped'), onCloseButtonTap: (toastItem) => logDebug('Toast ${toastItem.id} close button tapped'), onAutoCompleteCompleted: (toastItem) => logDebug('Toast ${toastItem.id} auto complete completed'), onDismissed: (toastItem) => logDebug('Toast ${toastItem.id} dismissed'), ), ); // _showToast(context, message, Colors.red); } static void _showToast(BuildContext context, String message, Color color) { // Fluttertoast.showToast( // msg: message, // toastLength: Toast.LENGTH_SHORT, // gravity: ToastGravity.TOP, // timeInSecForIosWeb: 5, // backgroundColor: color, // textColor: Colors.white, // fontSize: 16.0, // ); } }