138 lines
4.2 KiB
Dart
138 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:simplecloudnotifier/state/globals.dart';
|
|
import 'package:toastification/toastification.dart';
|
|
|
|
class Toaster {
|
|
// https://payamzahedi.com/toastification/
|
|
|
|
static const autoCloseDuration = Duration(seconds: 4);
|
|
static const alignment = Alignment.topCenter;
|
|
static const animationDuration = Duration(milliseconds: 200);
|
|
static final borderRadius = BorderRadius.circular(4.0);
|
|
|
|
static void simple(String title) {
|
|
print('[TOAST]: [[SIMPLE]] $title');
|
|
|
|
if (!Globals().appWidgetInitialized) {
|
|
print('[TOAST]: Cannot show simple-toast - app<widget> not initialized - skipping');
|
|
return;
|
|
}
|
|
|
|
toastification.show(
|
|
type: ToastificationType.success,
|
|
style: ToastificationStyle.simple,
|
|
title: Text(title),
|
|
description: Text(title),
|
|
autoCloseDuration: autoCloseDuration,
|
|
borderRadius: borderRadius,
|
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
|
alignment: alignment,
|
|
animationDuration: animationDuration,
|
|
pauseOnHover: false,
|
|
applyBlurEffect: true,
|
|
closeOnClick: true,
|
|
showProgressBar: false,
|
|
);
|
|
}
|
|
|
|
static void success(String title, String message) {
|
|
print('[TOAST]: [[SUCC]] $title:\n$message');
|
|
|
|
if (!Globals().appWidgetInitialized) {
|
|
print('[TOAST]: Cannot show succ-toast - app<widget> not initialized - skipping');
|
|
return;
|
|
}
|
|
|
|
toastification.show(
|
|
type: ToastificationType.success,
|
|
style: ToastificationStyle.flatColored,
|
|
title: Text(title),
|
|
description: Text(message),
|
|
autoCloseDuration: autoCloseDuration,
|
|
borderRadius: borderRadius,
|
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
|
alignment: alignment,
|
|
animationDuration: animationDuration,
|
|
pauseOnHover: false,
|
|
applyBlurEffect: true,
|
|
closeOnClick: true,
|
|
showProgressBar: false,
|
|
);
|
|
}
|
|
|
|
static void info(String title, String message) {
|
|
print('[TOAST]: [[INFO]] $title:\n$message');
|
|
|
|
if (!Globals().appWidgetInitialized) {
|
|
print('[TOAST]: Cannot show info-toast - app<widget> not initialized - skipping');
|
|
return;
|
|
}
|
|
|
|
toastification.show(
|
|
type: ToastificationType.info,
|
|
style: ToastificationStyle.flatColored,
|
|
title: Text(title),
|
|
description: Text(message),
|
|
autoCloseDuration: autoCloseDuration,
|
|
borderRadius: borderRadius,
|
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
|
alignment: alignment,
|
|
animationDuration: animationDuration,
|
|
pauseOnHover: false,
|
|
applyBlurEffect: true,
|
|
closeOnClick: true,
|
|
showProgressBar: false,
|
|
);
|
|
}
|
|
|
|
static void warn(String title, String message) {
|
|
print('[TOAST]: [[WARN]] $title:\n$message');
|
|
|
|
if (!Globals().appWidgetInitialized) {
|
|
print('[TOAST]: Cannot show warn-toast - app<widget> not initialized - skipping');
|
|
return;
|
|
}
|
|
|
|
toastification.show(
|
|
type: ToastificationType.warning,
|
|
style: ToastificationStyle.flatColored,
|
|
title: Text(title),
|
|
description: Text(message),
|
|
autoCloseDuration: autoCloseDuration,
|
|
borderRadius: borderRadius,
|
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
|
alignment: alignment,
|
|
animationDuration: animationDuration,
|
|
pauseOnHover: false,
|
|
applyBlurEffect: true,
|
|
closeOnClick: true,
|
|
showProgressBar: false,
|
|
);
|
|
}
|
|
|
|
static void error(String title, String message) {
|
|
print('[TOAST]: [[ERROR]] $title:\n$message');
|
|
|
|
if (!Globals().appWidgetInitialized) {
|
|
print('[TOAST]: Cannot show error-toast - app<widget> not initialized - skipping');
|
|
return;
|
|
}
|
|
|
|
toastification.show(
|
|
type: ToastificationType.error,
|
|
style: ToastificationStyle.flatColored,
|
|
title: Text(title),
|
|
description: Text(message),
|
|
autoCloseDuration: autoCloseDuration,
|
|
borderRadius: borderRadius,
|
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
|
alignment: alignment,
|
|
animationDuration: animationDuration,
|
|
pauseOnHover: false,
|
|
applyBlurEffect: true,
|
|
closeOnClick: true,
|
|
showProgressBar: false,
|
|
);
|
|
}
|
|
}
|