---
url: https://talkjs.com/docs/Data_APIs/Flutter/TalkSession
title: 'TalkSession'
minidoc-source: dart
---

This is the entry point to the TalkJS Flutter Data API.

## getTalkSession
/** Returns a TalkSession option for the specified App ID and User ID.
Backed by a registry, so calling this function twice with the same app and user returns the same session object both times. A new session will be created if the old one encountered an error or got garbage collected.
The `token` and `tokenFetcher` properties are ignored if there is already a session for that user in the registry.
@param appId Your app's unique TalkJS ID. Get it from the **Settings** page of the [dashboard](/dashboard).
@param userId The `id` of the user you want to connect and act as. Any messages you send will be sent as this user.
@param token A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId. */
Future<TalkSession>getTalkSession({required String appId, required String userId, String? token})

## TalkSession
class TalkSession {
/** The unique TalkJS ID that you passed when calling [getTalkSession] */
final String appId;

/** A reference to the user this session is connected as
This is immutable. If you want to connect as a different user, call [getTalkSession] again to get a new session.
Equivalent to calling [TalkSession.user] with the current user's ID. */
final UserRef currentUser;

/** Get a reference to a user
@param id The ID of the user that you want to reference
@return A [UserRef] for the user with that ID */
Future<UserRef>user(String id)

/** Get a reference to a conversation
@param id The ID of the conversation that you want to reference
@return A [ConversationRef] for the conversation with that ID */
Future<ConversationRef>conversation(String id)

/** Subscribes to the most recently active conversations for the current user */
ConversationListSubscription subscribeConversations(void Function(List<ConversationSnapshot>snapshot, bool loadedAll) onSnapshot)

/** Attaches a handler that will be called when the session encounters an error
Returns a callback which detaches your handler */
ErrorSubscription onError(void Function(Exception error) handler)

/** Upload a generic file without any additional metadata.
This function does not send any message, it only uploads the file and returns a file token. To send the file in a message, pass the file token in a [SendFileBlock] when calling [ConversationRef.send].
[See the documentation](/docs/Reference/Concepts/Message_Content/#sending-message-content) for more information about sending files in messages.
If the file is a video, image, audio file, or voice recording, use one of the other functions like [uploadImage] instead.
@param data The binary file data. Usually a [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
@param metadata Information about the file
@return A file token that can be used to send the file in a message. */
Future<String>uploadFile(Uint8List data, GenericFileMetadata metadata)

/** Upload an image with image-specific metadata.
This is a variant of [TalkSession.uploadFile] used for images.
@param data The binary image data. Usually a [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
@param metadata Information about the image.
@return A file token that can be used to send the image in a message. */
Future<String>uploadImage(Uint8List data, ImageFileMetadata metadata)

/** Upload a video with video-specific metadata.
This is a variant of [TalkSession.uploadFile] used for videos.
@param data The binary video data. Usually a [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
@param metadata Information about the video.
@return A file token that can be used to send the video in a message. */
Future<String>uploadVideo(Uint8List data, VideoFileMetadata metadata)

/** Upload an audio file with audio-specific metadata.
This is a variant of [TalkSession.uploadFile] used for audio files.
@param data The binary audio data. Usually a [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
@param metadata Information about the audio file.
@return A file token that can be used to send the audio file in a message. */
Future<String>uploadAudio(Uint8List data, AudioFileMetadata metadata)

/** Upload a voice recording with voice-specific metadata.
This is a variant of [TalkSession.uploadFile] used for voice recordings.
@param data The binary audio data. Usually a [File](https://developer.mozilla.org/en-US/docs/Web/API/File).
@param metadata Information about the voice recording.
@return A file token that can be used to send the audio file in a message. */
Future<String>uploadVoice(Uint8List data, VoiceRecordingFileMetadata metadata)
}

## ErrorSubscription
class ErrorSubscription {
Future<void>unsubscribe()
}

## GenericFileMetadata
class GenericFileMetadata {
/** The name of the file including extension. */
final String filename;

GenericFileMetadata({required String filename})
}

## ImageFileMetadata
class ImageFileMetadata {
/** The name of the file including extension. */
final String filename;

/** The width of the image in pixels, if known. */
int? width;

/** The height of the image in pixels, if known. */
int? height;

ImageFileMetadata({required String filename, int? width, int? height})
}

## VideoFileMetadata
class VideoFileMetadata {
/** The name of the file including extension. */
final String filename;

/** The width of the video in pixels, if known. */
int? width;

/** The height of the video in pixels, if known. */
int? height;

/** The duration of the video in seconds, if known. */
double? duration;

VideoFileMetadata({required String filename, int? width, int? height, double? duration})
}

## AudioFileMetadata
class AudioFileMetadata {
/** The name of the file including extension. */
final String filename;

/** The duration of the audio file in seconds, if known. */
double? duration;

AudioFileMetadata({required String filename, double? duration})
}

## VoiceRecordingFileMetadata
class VoiceRecordingFileMetadata {
/** The name of the file including extension. */
final String filename;

/** The duration of the recording in seconds, if known. */
double? duration;

VoiceRecordingFileMetadata({required String filename, double? duration})
}