vascular_flutter 2.2.0
vascular_flutter: ^2.2.0 copied to clipboard
The Vascular flutter plugin. This package implements a cross-platform plugin interface to vascular's iOS and Android native SDKs. This allows core Vascular functionality to be implemented by Flutter a [...]
Vascular Flutter #
The Vascular Flutter SDK is a Dart client for Vascular APIs.
Installation #
Add the package to your app's pubspec.yaml:
dependencies:
vascular_flutter: ^2.2.0
Then install dependencies:
flutter pub get
Import the SDK:
import 'package:vascular_flutter/vascular_flutter.dart';
Initialize #
Create a Vascular client with your API key, app key, user ID, and endpoint:
final vascular = initializeApp(
apiKey,
appKey,
userId,
'https://api.example.com:443',
[Language.enUs, Language.nb],
);
If languages is not provided, the SDK defaults to Language.ENUK.
Session token #
To verify requests against your own authentication system, pass a getSessionToken callback when initializing the SDK. The SDK calls it before every request to get a fresh token, which is sent as a session-token header.
final vascular = initializeApp(
apiKey,
appKey,
userId,
endpoint,
[Language.enUs],
() async {
return await yourAuthService.getValidToken();
},
);
The callback is optional. When omitted, no session-token header is sent.
Usage #
All network operations are asynchronous and should be awaited.
Create user #
Creates a user. If userId is not provided, the SDK uses the user ID passed to initializeApp.
final createdUser = await vascular.CreateUser();
final createdOtherUser = await vascular.CreateUser(userId: otherUserId);
Returns:
{
userId: STRING,
inboxId: STRING,
metadata: STRING,
}
Get user #
Fetches a user. If userId is not provided, the SDK uses the user ID passed to initializeApp.
final user = await vascular.GetUser();
final otherUser = await vascular.GetUser(userId: otherUserId);
Returns:
{
uuid: STRING,
createdAt: STRING,
metadata: STRING,
}
Inbox #
Fetches the first inbox page.
final inbox = await vascular.Inbox();
final messages = inbox.messages;
Returns:
{
messages: [INBOX_MESSAGE],
newMessagesIds: [STRING],
readMessagesIds: [STRING],
next: STRING,
newInbox: INTEGER,
}
next is the pagination token used by InboxNext().
Next inbox page #
Fetches the next inbox page. Returns null when there is no next page.
final nextInbox = await vascular.InboxNext();
Returns:
{
messages: [INBOX_MESSAGE],
newMessagesIds: [STRING],
readMessagesIds: [STRING],
next: STRING,
newInbox: INTEGER,
}
// Or null when there is no next page.
null
Get message by ID #
Fetches one inbox message by ID.
final message = await vascular.GetMessageById(inbox.messages.first.uuid);
Returns:
{
uuid: STRING,
status: STATUS,
message: {
enUs: MESSAGE_DATA,
nb: MESSAGE_DATA,
},
provider: PROVIDER,
createdAt: TIMESTAMP,
expdate: TIMESTAMP,
type: TYPE,
}
Delivered messages count #
Returns the number of delivered messages for the current user.
final deliveredMessagesCount = await vascular.GetDeliveredMessages();
Returns:
INTEGER
Read messages #
Marks the given message IDs as read.
final messageIds = ['message-id-1', 'message-id-2'];
final status = await vascular.ReadMessages(messageIds);
Returns:
STRING
Open messages #
Marks the given message IDs as opened.
final messageIds = ['message-id-1', 'message-id-2'];
final status = await vascular.OpenMessages(messageIds);
Returns:
STRING
Delete message #
Deletes one message.
final status = await vascular.DeleteMessage(inbox.messages.first.uuid);
Returns:
STRING
Add tags #
Adds tags to the current user.
final status = await vascular.AddTags(['music', 'sport']);
Returns:
STRING
Delete tags #
Deletes matching tags from the current user. Tags that do not exist are ignored.
final status = await vascular.DeleteTags(['music', 'sport']);
Returns:
STRING
List tags #
Lists tags for the current user.
final tags = await vascular.Tags();
Returns:
[
{
uuid: STRING,
name: STRING,
createdAt: STRING,
}
]
Single-language message #
Use GetMessage to return and remove the first message from a localized message map.
final messageData = vascular.GetMessage(inbox.messages.first.message);
Multiple languages #
When you initialize the SDK with multiple languages, each inbox message can contain message data keyed by language name.
final vascular = initializeApp(
apiKey,
appKey,
userId,
endpoint,
[Language.enUs, Language.nb],
);
final inbox = await vascular.Inbox();
final message = inbox.messages.first;
final englishMessage = message.message[Language.enUs.name];
print(englishMessage?.title);
final norwegianMessage = message.message[Language.nb.name];
print(norwegianMessage?.title);
Returns:
{
title: STRING,
body: STRING,
media: {
thumbnail: STRING,
image: STRING,
},
actions: [
{
name: STRING,
value: STRING,
}
],
metadata: STRING,
language: LANGUAGE,
subTitle: STRING,
}
Data Structures #
Inbox message #
{
uuid: STRING,
status: STATUS,
message: {
enUs: MESSAGE_DATA,
nb: MESSAGE_DATA,
},
provider: PROVIDER,
createdAt: TIMESTAMP,
expdate: TIMESTAMP,
type: TYPE,
}
Message data #
{
title: STRING,
body: STRING,
media: {
thumbnail: STRING,
image: STRING,
},
actions: [
{
name: STRING,
value: STRING,
}
],
metadata: STRING,
language: LANGUAGE,
subTitle: STRING,
}
Enums #
Language #
Language.enUs
Language.enUk
Language.nb
Provider #
Provider.api
Provider.sfmc
Provider.dashboard
Status #
Status.delivered
Status.opened
Status.read
Status.deleted
Status.admin_delete
Type #
Type.info
Type.campaign
Type.payment
Type.notification