enrollment-app/lib/customAppBar/toastHelper.dart
2026-02-05 19:15:46 +05:30

281 lines
10 KiB
Dart
Executable File

import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';
import 'package:toastification/toastification.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) => print('Toast ${toastItem.id} tapped'),
onCloseButtonTap: (toastItem) =>
print('Toast ${toastItem.id} close button tapped'),
onAutoCompleteCompleted: (toastItem) =>
print('Toast ${toastItem.id} auto complete completed'),
onDismissed: (toastItem) => print('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) => print('Toast ${toastItem.id} tapped'),
onCloseButtonTap: (toastItem) =>
print('Toast ${toastItem.id} close button tapped'),
onAutoCompleteCompleted: (toastItem) =>
print('Toast ${toastItem.id} auto complete completed'),
onDismissed: (toastItem) => print('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),
// 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) => print('Toast ${toastItem.id} tapped'),
onCloseButtonTap: (toastItem) =>
print('Toast ${toastItem.id} close button tapped'),
onAutoCompleteCompleted: (toastItem) =>
print('Toast ${toastItem.id} auto complete completed'),
onDismissed: (toastItem) => print('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) => print('Toast ${toastItem.id} tapped'),
onCloseButtonTap: (toastItem) =>
print('Toast ${toastItem.id} close button tapped'),
onAutoCompleteCompleted: (toastItem) =>
print('Toast ${toastItem.id} auto complete completed'),
onDismissed: (toastItem) => print('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) => print('Toast ${toastItem.id} tapped'),
onCloseButtonTap: (toastItem) =>
print('Toast ${toastItem.id} close button tapped'),
onAutoCompleteCompleted: (toastItem) =>
print('Toast ${toastItem.id} auto complete completed'),
onDismissed: (toastItem) => print('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,
// );
}
}