100 lines
2.9 KiB
Dart
100 lines
2.9 KiB
Dart
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:toastification/toastification.dart';
|
|
|
|
class ToasterService extends GetxService {
|
|
static ToasterService get to => Get.find();
|
|
|
|
void show({
|
|
required String title,
|
|
required String message,
|
|
ToastificationType type = ToastificationType.info,
|
|
ToastificationStyle style = ToastificationStyle.flat,
|
|
AlignmentGeometry alignment = Alignment.bottomLeft,
|
|
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
|
|
Duration? autoCloseDuration = const Duration(seconds: 2),
|
|
}) {
|
|
if (Get.context?.mounted != true) return;
|
|
|
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
|
toastification.show(
|
|
context: Get.context,
|
|
type: type,
|
|
style: style,
|
|
title: Text(title),
|
|
description: Text(message),
|
|
alignment: alignment,
|
|
autoCloseDuration: autoCloseDuration,
|
|
closeOnClick: false,
|
|
callbacks: callbacks,
|
|
);
|
|
});
|
|
}
|
|
|
|
void info({
|
|
required String title,
|
|
required String message,
|
|
ToastificationStyle style = ToastificationStyle.flat,
|
|
AlignmentGeometry alignment = Alignment.bottomLeft,
|
|
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
|
|
Duration? autoCloseDuration = const Duration(seconds: 2),
|
|
}) {
|
|
show(
|
|
title: title,
|
|
message: message,
|
|
style: style,
|
|
alignment: alignment,
|
|
callbacks: callbacks,
|
|
autoCloseDuration: autoCloseDuration,
|
|
);
|
|
}
|
|
|
|
void waring({
|
|
required String title,
|
|
required String message,
|
|
ToastificationStyle style = ToastificationStyle.flat,
|
|
AlignmentGeometry alignment = Alignment.bottomLeft,
|
|
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
|
|
Duration? autoCloseDuration = const Duration(seconds: 2),
|
|
}) {
|
|
show(
|
|
title: title,
|
|
message: message,
|
|
style: style,
|
|
alignment: alignment,
|
|
callbacks: callbacks,
|
|
autoCloseDuration: autoCloseDuration,
|
|
);
|
|
}
|
|
|
|
void success({
|
|
required String title,
|
|
required String message,
|
|
ToastificationStyle style = ToastificationStyle.flat,
|
|
AlignmentGeometry alignment = Alignment.bottomLeft,
|
|
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
|
|
Duration? autoCloseDuration = const Duration(seconds: 2),
|
|
}) {
|
|
show(
|
|
title: title,
|
|
message: message,
|
|
type: ToastificationType.success,
|
|
);
|
|
}
|
|
|
|
void error({
|
|
required String title,
|
|
required String message,
|
|
ToastificationStyle style = ToastificationStyle.flat,
|
|
AlignmentGeometry alignment = Alignment.bottomLeft,
|
|
ToastificationCallbacks callbacks = const ToastificationCallbacks(),
|
|
Duration? autoCloseDuration = const Duration(seconds: 2),
|
|
}) {
|
|
show(
|
|
title: title,
|
|
message: message,
|
|
type: ToastificationType.error,
|
|
);
|
|
}
|
|
}
|