Official Persistence Client for Stream Chat
The official persistence client for Stream Chat, a service for building chat applications.
Quick Links
- Register to get an API key for Stream Chat
- Flutter Chat Tutorial
- Documentation
- V10 Migration Guide
Changelog
Check out the changelog on pub.dev to see the latest changes in the package.
Overview
This package provides a persistence client for fetching and saving chat data locally. It is powered by Drift (SQLite) and plugs into any of the Stream Chat Flutter packages to add offline storage and optimistic UI updates.
Add Dependency
Add this to your pubspec.yaml, using the latest version :
dependencies:
stream_chat_persistence: ^10.0.0
Then run:
flutter pub get
Usage
- Create a new instance of
StreamChatPersistenceClient, providinglogLevelandconnectionMode:
final chatPersistentClient = StreamChatPersistenceClient(
logLevel: Level.INFO,
connectionMode: ConnectionMode.regular,
);
- Pass the instance to the
StreamChatClient:
final client = StreamChatClient(
apiKey,
logLevel: Level.INFO,
)..chatPersistenceClient = chatPersistentClient;
And you are ready to go.
Flutter Web
Due to Drift's web backend you need to include the sql.js library. Add the following to your web/index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script defer src="sql-wasm.js"></script>
<script defer src="main.dart.js" type="application/javascript"></script>
</head>
<body></body>
</html>
You can grab the latest version of sql-wasm.js and sql-wasm.wasm from the sql.js releases and copy them into your /web folder.
Contributing
We welcome code changes that improve this library or fix a problem. Please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on GitHub. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.