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:
parent
cc13f8a0f3
commit
faa624e9f8
@ -6,26 +6,28 @@
|
|||||||
# sudo archlinux-java set java-17-openjdk
|
# sudo archlinux-java set java-17-openjdk
|
||||||
#
|
#
|
||||||
|
|
||||||
|
java:
|
||||||
|
sudo archlinux-java set java-17-openjdk
|
||||||
|
java -version
|
||||||
|
|
||||||
# runs app locally (linux)
|
# runs app locally (linux)
|
||||||
run-linux: gen
|
run-linux: java gen
|
||||||
dart run build_runner build
|
dart run build_runner build
|
||||||
_JAVA_OPTIONS="" flutter run -d linux
|
_JAVA_OPTIONS="" flutter run -d linux
|
||||||
|
|
||||||
# runs app locally (web | not really supported)
|
# runs app locally (web | not really supported)
|
||||||
run-web: gen
|
run-web: java gen
|
||||||
dart run build_runner build
|
dart run build_runner build
|
||||||
_JAVA_OPTIONS="" flutter run -d chrome
|
_JAVA_OPTIONS="" flutter run -d chrome
|
||||||
|
|
||||||
# runs on android device (must have network adb enabled teh correct IP)
|
# runs on android device (must have network adb enabled teh correct IP)
|
||||||
run-android: gen
|
run-android: java gen
|
||||||
ping -c1 10.10.10.177
|
ping -c1 10.10.10.177
|
||||||
adb connect 10.10.10.177:5555
|
adb connect 10.10.10.177:5555
|
||||||
flutter pub run build_runner build
|
flutter pub run build_runner build
|
||||||
_JAVA_OPTIONS="" flutter run -d 10.10.10.177:5555
|
_JAVA_OPTIONS="" flutter run -d 10.10.10.177:5555
|
||||||
|
|
||||||
install-release: gen
|
install-release: java gen
|
||||||
# Install on Pixel 7a
|
# Install on Pixel 7a
|
||||||
flutter build apk --release
|
flutter build apk --release
|
||||||
flutter run --release -d 35221JEHN07157
|
flutter run --release -d 35221JEHN07157
|
||||||
@ -41,7 +43,7 @@ test:
|
|||||||
fix:
|
fix:
|
||||||
dart fix --apply
|
dart fix --apply
|
||||||
|
|
||||||
gen:
|
gen: java
|
||||||
./_utils/inc_buildnum.sh
|
./_utils/inc_buildnum.sh
|
||||||
dart run build_runner build
|
dart run build_runner build
|
||||||
dart run git_stamp git_stamp --build-type lite --limit 2
|
dart run git_stamp git_stamp --build-type lite --limit 2
|
||||||
|
@ -205,7 +205,7 @@ void main() async {
|
|||||||
|
|
||||||
final appLaunchNotification = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
final appLaunchNotification = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||||
if (appLaunchNotification != null) {
|
if (appLaunchNotification != null) {
|
||||||
// Use has launched SCN by clicking on a loca notifiaction, if it was a summary or message notifiaction open the corresponding screen
|
// Use has launched SCN by clicking on a local notifiaction, if it was a summary or message notifiaction open the corresponding screen
|
||||||
// This is android only
|
// This is android only
|
||||||
//TODO same on iOS, somehow??
|
//TODO same on iOS, somehow??
|
||||||
ApplicationLog.info('App launched by notification: ${appLaunchNotification.notificationResponse?.id}');
|
ApplicationLog.info('App launched by notification: ${appLaunchNotification.notificationResponse?.id}');
|
||||||
@ -216,6 +216,8 @@ void main() async {
|
|||||||
|
|
||||||
ApplicationLog.debug('[INIT] Application started');
|
ApplicationLog.debug('[INIT] Application started');
|
||||||
|
|
||||||
|
Globals().appWidgetInitialized = true;
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -17,6 +17,8 @@ class Globals {
|
|||||||
|
|
||||||
bool _initialized = false;
|
bool _initialized = false;
|
||||||
|
|
||||||
|
bool appWidgetInitialized = false;
|
||||||
|
|
||||||
String appName = '';
|
String appName = '';
|
||||||
String packageName = '';
|
String packageName = '';
|
||||||
String version = '';
|
String version = '';
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:simplecloudnotifier/state/globals.dart';
|
||||||
import 'package:toastification/toastification.dart';
|
import 'package:toastification/toastification.dart';
|
||||||
|
|
||||||
class Toaster {
|
class Toaster {
|
||||||
@ -10,6 +11,13 @@ class Toaster {
|
|||||||
static final borderRadius = BorderRadius.circular(4.0);
|
static final borderRadius = BorderRadius.circular(4.0);
|
||||||
|
|
||||||
static void simple(String title) {
|
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(
|
toastification.show(
|
||||||
type: ToastificationType.success,
|
type: ToastificationType.success,
|
||||||
style: ToastificationStyle.simple,
|
style: ToastificationStyle.simple,
|
||||||
@ -17,7 +25,7 @@ class Toaster {
|
|||||||
description: Text(title),
|
description: Text(title),
|
||||||
autoCloseDuration: autoCloseDuration,
|
autoCloseDuration: autoCloseDuration,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
closeButtonShowType: CloseButtonShowType.none,
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
animationDuration: animationDuration,
|
animationDuration: animationDuration,
|
||||||
pauseOnHover: false,
|
pauseOnHover: false,
|
||||||
@ -28,6 +36,13 @@ class Toaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void success(String title, String message) {
|
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(
|
toastification.show(
|
||||||
type: ToastificationType.success,
|
type: ToastificationType.success,
|
||||||
style: ToastificationStyle.flatColored,
|
style: ToastificationStyle.flatColored,
|
||||||
@ -35,7 +50,7 @@ class Toaster {
|
|||||||
description: Text(message),
|
description: Text(message),
|
||||||
autoCloseDuration: autoCloseDuration,
|
autoCloseDuration: autoCloseDuration,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
closeButtonShowType: CloseButtonShowType.none,
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
animationDuration: animationDuration,
|
animationDuration: animationDuration,
|
||||||
pauseOnHover: false,
|
pauseOnHover: false,
|
||||||
@ -46,6 +61,13 @@ class Toaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void info(String title, String message) {
|
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(
|
toastification.show(
|
||||||
type: ToastificationType.info,
|
type: ToastificationType.info,
|
||||||
style: ToastificationStyle.flatColored,
|
style: ToastificationStyle.flatColored,
|
||||||
@ -53,7 +75,7 @@ class Toaster {
|
|||||||
description: Text(message),
|
description: Text(message),
|
||||||
autoCloseDuration: autoCloseDuration,
|
autoCloseDuration: autoCloseDuration,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
closeButtonShowType: CloseButtonShowType.none,
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
animationDuration: animationDuration,
|
animationDuration: animationDuration,
|
||||||
pauseOnHover: false,
|
pauseOnHover: false,
|
||||||
@ -64,6 +86,13 @@ class Toaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void warn(String title, String message) {
|
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(
|
toastification.show(
|
||||||
type: ToastificationType.warning,
|
type: ToastificationType.warning,
|
||||||
style: ToastificationStyle.flatColored,
|
style: ToastificationStyle.flatColored,
|
||||||
@ -71,7 +100,7 @@ class Toaster {
|
|||||||
description: Text(message),
|
description: Text(message),
|
||||||
autoCloseDuration: autoCloseDuration,
|
autoCloseDuration: autoCloseDuration,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
closeButtonShowType: CloseButtonShowType.none,
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
animationDuration: animationDuration,
|
animationDuration: animationDuration,
|
||||||
pauseOnHover: false,
|
pauseOnHover: false,
|
||||||
@ -82,6 +111,13 @@ class Toaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void error(String title, String message) {
|
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(
|
toastification.show(
|
||||||
type: ToastificationType.error,
|
type: ToastificationType.error,
|
||||||
style: ToastificationStyle.flatColored,
|
style: ToastificationStyle.flatColored,
|
||||||
@ -89,7 +125,7 @@ class Toaster {
|
|||||||
description: Text(message),
|
description: Text(message),
|
||||||
autoCloseDuration: autoCloseDuration,
|
autoCloseDuration: autoCloseDuration,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
closeButtonShowType: CloseButtonShowType.none,
|
closeButton: ToastCloseButton(showType: CloseButtonShowType.none),
|
||||||
alignment: alignment,
|
alignment: alignment,
|
||||||
animationDuration: animationDuration,
|
animationDuration: animationDuration,
|
||||||
pauseOnHover: false,
|
pauseOnHover: false,
|
||||||
|
@ -2,7 +2,7 @@ name: simplecloudnotifier
|
|||||||
description: "Receive push messages"
|
description: "Receive push messages"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 2.0.0+481
|
version: 2.0.0+484
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.2.6 <4.0.0'
|
sdk: '>=3.2.6 <4.0.0'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user