Fix crash when a requests fails in non-widget mode (aka on background-receive): Cannot show toasts without an UI
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:simplecloudnotifier/state/globals.dart';
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
class Toaster {
|
||||
@@ -10,6 +11,13 @@ class Toaster {
|
||||
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,
|
||||
@@ -17,7 +25,7 @@ class Toaster {
|
||||
description: Text(title),
|
||||
autoCloseDuration: autoCloseDuration,
|
||||
borderRadius: borderRadius,
|
||||
closeButtonShowType: CloseButtonShowType.none,
|
||||
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||
alignment: alignment,
|
||||
animationDuration: animationDuration,
|
||||
pauseOnHover: false,
|
||||
@@ -28,6 +36,13 @@ class Toaster {
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -35,7 +50,7 @@ class Toaster {
|
||||
description: Text(message),
|
||||
autoCloseDuration: autoCloseDuration,
|
||||
borderRadius: borderRadius,
|
||||
closeButtonShowType: CloseButtonShowType.none,
|
||||
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||
alignment: alignment,
|
||||
animationDuration: animationDuration,
|
||||
pauseOnHover: false,
|
||||
@@ -46,6 +61,13 @@ class Toaster {
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -53,7 +75,7 @@ class Toaster {
|
||||
description: Text(message),
|
||||
autoCloseDuration: autoCloseDuration,
|
||||
borderRadius: borderRadius,
|
||||
closeButtonShowType: CloseButtonShowType.none,
|
||||
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||
alignment: alignment,
|
||||
animationDuration: animationDuration,
|
||||
pauseOnHover: false,
|
||||
@@ -64,6 +86,13 @@ class Toaster {
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -71,7 +100,7 @@ class Toaster {
|
||||
description: Text(message),
|
||||
autoCloseDuration: autoCloseDuration,
|
||||
borderRadius: borderRadius,
|
||||
closeButtonShowType: CloseButtonShowType.none,
|
||||
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||
alignment: alignment,
|
||||
animationDuration: animationDuration,
|
||||
pauseOnHover: false,
|
||||
@@ -82,6 +111,13 @@ class Toaster {
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -89,7 +125,7 @@ class Toaster {
|
||||
description: Text(message),
|
||||
autoCloseDuration: autoCloseDuration,
|
||||
borderRadius: borderRadius,
|
||||
closeButtonShowType: CloseButtonShowType.none,
|
||||
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||
alignment: alignment,
|
||||
animationDuration: animationDuration,
|
||||
pauseOnHover: false,
|
||||
|
Reference in New Issue
Block a user