DeviceInformationChange class abstract
The object that changes the device information.
The device information change can be used to
- modify the name of the device and/or
- modify its Firebase registration token or
- disable push notifications.
If neither name or fcmRegistrationToken are provided, the provided onSuccess function will be called when execute is invoked.
Usage example for changing device information:
[...]
Future<void> updateDeviceInformation({
required MobileAuthenticationClient client,
required String newName,
required String fcmToken,
}) async {
await client.operations.deviceInformationChange
.name(newName)
.fcmRegistrationToken(fcmToken)
.onSuccess(() {
// handle success
})
.onError((error) {
// handle error
})
.execute();
}
[...]
Synchronization with retry policy
The retry policy can be useful when updating the Firebase Cloud Messaging token. But since it is not known when the token will be updated, synchronization is necessary and should be done by the caller. Below a sample code is provided that solves the synchronization using the queue library and Completer.
import 'dart:async';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:queue/queue.dart';
class SampleAppMessagingService {
final Queue _queue = Queue();
SampleAppMessagingService() {
FirebaseMessaging.instance.onTokenRefresh.listen((token) {
_queue.add(() {
return _processNewToken(token, client);
});
});
}
Future<void> _processNewToken(
MobileAuthenticationClient client,
String fcmToken,
) async {
final completer = Completer();
ConstantRetryPolicy retryPolicy = ConstantRetryPolicy(
maxRetries: 5,
delayInSeconds: const Duration(seconds: 5),
);
client.operations.deviceInformationChange
.fcmRegistrationToken(fcmToken)
.retryPolicy(retryPolicy)
.onSuccess(() {
// Firebase registration token successfully updated
completer.complete();
})
.onError((error) {
// handle unsuccessful update
completer.completeError(error);
})
.execute()
.catchError((e) {
return completer.future;
}
}
- Inheritance
-
- Object
- HttpOperation<
DeviceInformationChange> - DeviceInformationChange
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
disablePushNotifications(
) → DeviceInformationChange - Disables the push notifications on the server side (i.e. the server will not send authentication push notifications).
-
execute(
) → Future< void> -
Executes the operation asynchronously.
inherited
-
fcmRegistrationToken(
String fcmRegistrationToken) → DeviceInformationChange - Specifies the new Firebase Cloud Messaging registration token.
-
name(
String name) → DeviceInformationChange - Specifies the new name of the device information.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
dynamic onError(DeviceInformationChangeError)) → DeviceInformationChange - Specifies the object that will be invoked if the dispatch device information change failed.
-
onSuccess(
Function onSuccess) → DeviceInformationChange - Specifies the object that will be invoked if the device information for the user was updated successfully.
-
requestHeaders(
RequestHeaders requestHeaders) → DeviceInformationChange -
Specifies the additional request headers that must be included in the HTTP
requests sent by the operation.
inherited
-
retryPolicy(
RetryPolicy retryPolicy) → DeviceInformationChange - Specifies the retry policy to be used.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited