Skip to content

User Guide: SDKs > Flutter SDK > Invoking Messaging Service

Invoking Messaging Service

A developer should register with Google Cloud Messaging (GCM) to get the device token that is used to register with Volt Foundry Messaging. Also, a developer should fetch the deviceId and user-friendlyId to create an instance of the messaging service.

The following are the methods you can use for a messaging service.

  1. Register
  2. Unregister
  3. Update Geo Location
  4. Fetch All Messages
  5. Mark Message as Read
  6. Get Message Content

Register

// Sample code to register for the messaging service
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fcmId = "<Your fcmId here>";
var deviceId = "<Your deviceId here>";
var ufId = "<Your ufId here>";
voltmxSdkFlutter.register(fcmId, deviceId, ufId, onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});

Note : Call these methods only after successful completion of voltmxSdkFlutter.initializeSDK. For more details, refer to the Init method.

Unregister

// Sample code to unregister from the messaging service
var voltmxSdkFlutter = VoltmxSdkFlutter();
voltmxSdkFlutter.unregister(
onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});

Update geo location

// Sample code to update geo location
var voltmxSdkFlutter = VoltmxSdkFlutter();
var latitude = "<Your latitude here>";
var longitude = "<Your longitude here>";
var locationName = "<Your locationName here>";
voltmxSdkFlutter.updateGeoLocation(latitude, longitude, locationName, onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});

Fetch all messages

// Sample code to fetch all the messages
var voltmxSdkFlutter = VoltmxSdkFlutter();
int startIndex = 0;
int pageSize = 10;
voltmxSdkFlutter.fetchAllMessages(startIndex, pageSize,
onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});

Note: Fetch all messages api returns only part of a message. To get full content of the message, use the Get message Content method below.

Mark message as read

// Sample code to mark message as Read
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fetchId = "<Your fetchId here>";
voltmxSdkFlutter.markMessageRead(fetchId, onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});

Get message content

// Sample code to get message content
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fetchId = "<Your fetchId here>";
voltmxSdkFlutter.fetchMessageContent(fetchId, onSuccess: (response) {
    // Handle the success case here
}, onFailure: (response) {
    // Handle the failure case here
});