Client class
This is the top-level entrypoint to the XMTP flutter SDK.
This client provides access to every user Conversation. See listConversations, streamConversations.
It also allows the user to create a new Conversation. See newConversation.
And once a Conversation has been acquired, it can be used to listMessages, streamMessages, and sendMessage.
Creating a Client Instance
The client has two constructors: createFromWallet and createFromKeys.
The first time a user uses a new device they should call createFromWallet. This will prompt them to sign a message that either creates a new identity (if they're new) or enables their existing identity (if they've used XMTP before). When this succeeds it configures the client with a bundle of keys that can be stored securely on the device.
var client = await Client.createFromWallet(wallet);
await mySecureStorage.save(client.keys);
The second time a user launches the app they should call createFromKeys using the stored keys from their previous session.
var keys = await mySecureStorage.load();
var client = await Client.createFromKeys(keys);
Caching / Offline Storage
The two primary models Conversation and DecodedMessage are designed with offline storage in mind. See the example app for a demonstration. TODO: consider adding offline storage support to the SDK itself.
Each Conversation is uniquely identified by its Conversation.topic. And each DecodedMessage is uniquely identified by its DecodedMessage.id. See note re "Offline Storage" atop DecodedMessage.
- Implemented types
Properties
- address → EthereumAddress
-
final
- contentType → ContentTypeId
-
This completes the implementation of the Codec interface.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- keys → PrivateKeyBundle
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canMessage(
String address) → Future< bool> -
Whether or not we can send messages to
address
. -
decode(
EncodedContent encoded) → Future< DecodedContent> -
These use all registered codecs to decode and encode content.
override
-
decryptConversation(
Envelope envelope) → Future< Conversation?> -
This decrypts a
Conversation
from anenvelope
. -
decryptMessage(
Conversation conversation, Message message) → Future< DecodedMessage?> -
This decrypts and decodes the
message
belonging toconversation
. -
encode(
DecodedContent decoded) → Future< EncodedContent> -
This is called to encode the content
override
-
fallback(
DecodedContent content) → String? -
This may provide text that can be displayed instead of the content.
It can be used in contexts that do not support rendering a content type.
override
-
listBatchMessages(
Iterable< Conversation> conversations, {Iterable<Pagination> ? paginations, DateTime? start, DateTime? end, int? limit, SortDirection sort = xmtp.SortDirection.SORT_DIRECTION_DESCENDING}) → Future<List< DecodedMessage> > -
This lists messages sent to the
conversations
. This is identical to listMessages except it pulls messages from multiple conversations in a single call. -
listConversations(
{DateTime? start, DateTime? end, int? limit, SortDirection? sort = xmtp.SortDirection.SORT_DIRECTION_DESCENDING}) → Future< List< Conversation> > - This lists all the Conversations for the user.
-
listMessages(
Conversation conversation, {DateTime? start, DateTime? end, int? limit, SortDirection sort = xmtp.SortDirection.SORT_DIRECTION_DESCENDING}) → Future< List< DecodedMessage> > -
This lists messages sent to the
conversation
. -
newConversation(
String address, {String conversationId = "", Map< String, String> metadata = const <String, String>{}}) → Future<Conversation> -
This creates or resumes a
Conversation
withaddress
. If aconversationId
is specified then that will distinguish multiple conversations with the same user. A newconversationId
always creates a new conversation. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sendMessage(
Conversation conversation, Object content, {ContentTypeId? contentType}) → Future< DecodedMessage> -
This sends a new message to the
conversation
. It returns theDecodedMessage
to simplify optimistic local updates. e.g. you can display theDecodedMessage
immediately without having to wait for it to come back down the stream. -
sendMessageEncoded(
Conversation conversation, EncodedContent encoded) → Future< DecodedMessage?> -
This sends the already
encoded
message to theconversation
. This is identical to sendMessage but can be helpful when you have already encoded the message to send. If it cannot be decoded then it still sends but this returnsnull
. -
streamBatchMessages(
Iterable< Conversation> conversations) → Stream<DecodedMessage> -
This exposes a stream of new messages sent to any of the
conversations
. -
streamConversations(
) → Stream< Conversation> -
This exposes a stream of new
Conversation
s for the user. -
streamMessages(
Conversation conversation) → Stream< DecodedMessage> -
This exposes a stream of new messages sent to the
conversation
. For streaming multiple conversations, see streamBatchMessages. -
terminate(
) → Future< void> - Terminate this client.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
createFromKeys(
Api api, PrivateKeyBundle keys, {List< Codec< customCodecs = const []}) → Future<Object> >Client> -
This creates a new
Client
using the savedkeys
from a previously successful authentication. -
createFromWallet(
Api api, Signer wallet, {List< Codec< customCodecs = const []}) → Future<Object> >Client> -
This creates a new
Client
instance using the Signer to trigger signature prompts to acquire user authentication keys.