Client class
*[<Null safety>](https://dart.dev/null-safety)*
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 createFromKeysusing 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.
read-onlyoverride
hashCode → int
The hash code for this object.
read-onlyinherited
keys → PrivateKeyBundle
read-only
runtimeType → Type
A representation of the runtime type of the object.
read-onlyinherited
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
encode(DecodedContent decoded) Future<EncodedContent>
This is called to encode the content
override
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
with address
.
If a conversationId
is specified then that will
distinguish multiple conversations with the same user.
A new conversationId
always creates a new conversation.
noSuchMethod(Invocation invocation) dynamic
Invoked when a non-existent 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 the DecodedMessage
to simplify optimistic local updates.
e.g. you can display the DecodedMessage
immediately
without having to wait for it to come back down the stream.
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
.
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<Object>> customCodecs = const []}) Future<Client>
This creates a new Client
using the saved keys
from a
previously successful authentication.
createFromWallet(Api api, Signer wallet, {List<Codec<Object>> customCodecs = const []}) Future<Client>
This creates a new Client
instance using the Signer to
trigger signature prompts to acquire user authentication keys.