Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Dec 13, 2023
1 parent 8f67802 commit 997c3f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
18 changes: 12 additions & 6 deletions lib/src/platform/src/background_android_isolate_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class BackgroundIsolateAndroidPlatform {
case PlatformMethod.pushOnBackgroundMessage:
return _onPushBackgroundMessage(call.arguments as RemoteMessage);
default:
throw PlatformException(code: 'invalid_method', message: 'No such method ${call.method}');
throw PlatformException(
code: 'invalid_method', message: 'No such method ${call.method}');
}
});
}

static final BackgroundIsolateAndroidPlatform _platform = BackgroundIsolateAndroidPlatform._internal();
static final BackgroundIsolateAndroidPlatform _platform =
BackgroundIsolateAndroidPlatform._internal();

/// @nodoc
/// Singleton instance of BackgroundIsolateAndroidPlatform
Expand All @@ -37,15 +39,19 @@ class BackgroundIsolateAndroidPlatform {
/// A method channel used to communicate with the user's app isolate
/// we explicitly launched when a RemoteMessage is received.
/// Used only on Android.
final MethodChannel _methodChannel = MethodChannel('io.ably.flutter.plugin.background', StandardMethodCodec(Codec()));
final MethodChannel _methodChannel = MethodChannel(
'io.ably.flutter.plugin.background', StandardMethodCodec(Codec()));

final PushNotificationEventsInternal _pushNotificationEvents = Push.notificationEvents as PushNotificationEventsInternal;
final PushNotificationEventsInternal _pushNotificationEvents =
Push.notificationEvents as PushNotificationEventsInternal;

Future<void> _onPushBackgroundMessage(RemoteMessage remoteMessage) async => _pushNotificationEvents.handleBackgroundMessage(remoteMessage);
Future<void> _onPushBackgroundMessage(RemoteMessage remoteMessage) async =>
_pushNotificationEvents.handleBackgroundMessage(remoteMessage);

/// @nodoc
/// Equivalent of [Platform.invokePlatformMethod] which cannot be used here
/// because we may not be able to acquire [Platform] instance here, so we
/// need to use a raw [MethodChannel] communication
Future<T?> invokeMethod<T>(String method, [dynamic arguments]) async => _methodChannel.invokeMethod<T>(method, arguments);
Future<T?> invokeMethod<T>(String method, [dynamic arguments]) async =>
_methodChannel.invokeMethod<T>(method, arguments);
}
2 changes: 1 addition & 1 deletion lib/src/platform/src/method_call_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AblyMethodCallHandler {
}

Future<Object?> _onPushBackgroundMessage(RemoteMessage remoteMessage) async {
_pushNotificationEvents.handleBackgroundMessage(remoteMessage);
await _pushNotificationEvents.handleBackgroundMessage(remoteMessage);
return null;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/src/platform/src/push_notification_events_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ class PushNotificationEventsInternal implements PushNotificationEvents {
/// Handles a RemoteMessage passed from the platform side.
Future<void> handleBackgroundMessage(RemoteMessage remoteMessage) async {
if (_onBackgroundMessage != null) {
dynamic onBackgroundMessageResult = _onBackgroundMessage!(remoteMessage);
final onBackgroundMessageResult = _onBackgroundMessage!(remoteMessage);
// ^^^ _onBackgroundMessage() can return void or Future<void>
if (onBackgroundMessageResult is Future) {
await onBackgroundMessageResult; // if it returns a Future we await on it.
if (onBackgroundMessageResult is Future) {
// if it returns a Future we await on it.
await onBackgroundMessageResult;
}
} else {
// ignore:avoid_print
Expand Down

0 comments on commit 997c3f2

Please sign in to comment.