This section provides API reference details for the Push Messaging module in the Flutter unified plugin.
enablePush
Enables push messaging.
Syntax
PushModule.enablePush();
Returns
Future<void>
Example
import 'package:sfmc_push/sfmc_push.dart';
await PushModule.requestSdk();
await PushModule.enablePush();
See Also
disablePush
Disables push messaging.
Syntax
PushModule.disablePush();
Returns
Future<void>
Example
import 'package:sfmc_push/sfmc_push.dart';
await PushModule.requestSdk();
await PushModule.disablePush();
See Also
isPushEnabled
Returns the state of the pushEnabled flag.
Syntax
PushModule.isPushEnabled();
Returns
Future<bool>- A future that indicates whether push messaging is enabled.
Example
import 'package:sfmc_push/sfmc_push.dart';
await PushModule.requestSdk();
final enabled = await PushModule.isPushEnabled();
See Also
getPushToken
Returns the token that Marketing Cloud uses to send push messages to the device.
Syntax
PushModule.getPushToken();
Returns
Future<String?>- A future that completes with the push token string, ornull.
Example
import 'package:sfmc_push/sfmc_push.dart';
await PushModule.requestSdk();
final token = await PushModule.getPushToken();
See Also
pushTokenStream
A broadcast stream of push token updates. Emits a new token string when the push token changes.
Syntax
PushModule.pushTokenStream;
Returns
Stream<String?>
Example
import 'package:sfmc_push/sfmc_push.dart';
await PushModule.requestSdk();
final sub = PushModule.pushTokenStream.listen((token) {
print('Token updated: $token');
});
await sub.cancel();