diff --git a/.github/workflows/docusaurus.yml b/.github/workflows/docusaurus.yml
new file mode 100644
index 00000000..f46fa893
--- /dev/null
+++ b/.github/workflows/docusaurus.yml
@@ -0,0 +1,20 @@
+name: docusaurus
+
+on:
+ push:
+ branches:
+ - master
+ - develop
+ paths:
+ - docusaurus/**
+jobs:
+ push_docusaurus:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: push
+ uses: GetStream/push-stream-chat-docusaurus-action@main
+ with:
+ target-branch: ${{ github.ref == 'refs/heads/master' && 'production' || 'staging' }}
+ env:
+ DOCUSAURUS_GH_TOKEN: ${{ secrets.DOCUSAURUS_GH_TOKEN }}
\ No newline at end of file
diff --git a/.github/workflows/scripts/install-flutter.sh b/.github/workflows/scripts/install-flutter.sh
deleted file mode 100755
index 247d2797..00000000
--- a/.github/workflows/scripts/install-flutter.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-BRANCH=$1
-
-if [ "$BRANCH" == "dev" ]
-then
- # TODO Flutter dev branch is currently broken so we're unable to test MacOS.
- echo "TODO: Skipping macOS testing due to Flutter dev branch issue. Switching branch to stable."
- BRANCH=stable
-fi
-
-git clone https://github.com/flutter/flutter.git --depth 1 -b $BRANCH _flutter
-echo "::add-path::$GITHUB_WORKSPACE/_flutter/bin"
\ No newline at end of file
diff --git a/.github/workflows/scripts/install-tools.sh b/.github/workflows/scripts/install-tools.sh
deleted file mode 100755
index 087cfecb..00000000
--- a/.github/workflows/scripts/install-tools.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-
-flutter pub global activate melos
-echo "::add-path::$HOME/.pub-cache/bin"
-echo "::add-path::$GITHUB_WORKSPACE/_flutter/.pub-cache/bin"
-echo "::add-path::$GITHUB_WORKSPACE/_flutter/bin/cache/dart-sdk/bin"
\ No newline at end of file
diff --git a/.github/workflows/scripts/coverage.sh b/.github/workflows/scripts/remove-from-coverage.sh
similarity index 69%
rename from .github/workflows/scripts/coverage.sh
rename to .github/workflows/scripts/remove-from-coverage.sh
index edff4ae4..c6850e89 100755
--- a/.github/workflows/scripts/coverage.sh
+++ b/.github/workflows/scripts/remove-from-coverage.sh
@@ -3,4 +3,4 @@
# Fast fail the script on failures.
set -e
-pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$' -r '\.freezed\.dart$'
\ No newline at end of file
+pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$' -r '\.freezed\.dart$'
diff --git a/.github/workflows/stream_flutter_workflow.yml b/.github/workflows/stream_flutter_workflow.yml
index aa621854..0baaaff7 100644
--- a/.github/workflows/stream_flutter_workflow.yml
+++ b/.github/workflows/stream_flutter_workflow.yml
@@ -2,6 +2,7 @@ name: stream_flutter_workflow
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
+ flutter_version: "2.2.2"
on:
pull_request:
@@ -9,97 +10,114 @@ on:
branches:
- master
- develop
- paths-ignore:
- - 'docs/**'
jobs:
analyze:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - name: "Git Checkout"
+ uses: actions/checkout@v2
with:
fetch-depth: 0
- - name: 'Install Flutter'
- run: ./.github/workflows/scripts/install-flutter.sh stable
- - name: 'Install Tools'
+ - name: Cache Flutter dependencies
+ uses: actions/cache@v2
+ with:
+ path: /opt/hostedtoolcache/flutter
+ key: ${{ env.flutter_version }}-flutter
+ - name: "Install Flutter"
+ uses: subosito/flutter-action@v1
+ with:
+ flutter-version: ${{ env.flutter_version }}
+ - name: "Install Tools"
run: |
- ./.github/workflows/scripts/install-tools.sh
- flutter pub global activate tuneup
- - name: 'Bootstrap Workspace'
+ flutter pub global activate melos
+ - name: "Bootstrap Workspace"
run: melos bootstrap
- - name: 'Dart Analyze'
+ - name: "Dart Analyze"
run: |
- melos exec -c 3 --ignore="*example*" -- \
- tuneup check
- - name: 'Pub Check'
+ melos run analyze
+ - name: "Pub Check"
if: github.ref == 'refs/heads/master'
run: |
- melos exec -c 1 --no-private --ignore="*example*" -- \
- pub publish --dry-run
+ melos run lint:pub
+
format:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- - uses: actions/checkout@v2
+ - name: "Git Checkout"
+ uses: actions/checkout@v2
with:
fetch-depth: 0
- - name: 'Install Flutter'
- run: ./.github/workflows/scripts/install-flutter.sh stable
- - name: 'Install Tools'
- run: |
- ./.github/workflows/scripts/install-tools.sh
- - name: 'Bootstrap Workspace'
+ - name: Cache Flutter dependencies
+ uses: actions/cache@v2
+ with:
+ path: /opt/hostedtoolcache/flutter
+ key: ${{ env.flutter_version }}-flutter
+ - name: "Install Flutter"
+ uses: subosito/flutter-action@v1
+ with:
+ flutter-version: ${{ env.flutter_version }}
+ - name: "Install Tools"
+ run: flutter pub global activate melos
+ - name: "Bootstrap Workspace"
run: melos bootstrap
- - name: 'Dart'
+ - name: "Melos Format"
+ run: melos run format
+ - name: "Validate Formatting"
run: |
- melos exec -c 1 -- \
- flutter format .
./.github/workflows/scripts/validate-formatting.sh
test:
- runs-on: ubuntu-latest
+ runs-on: macos-latest
timeout-minutes: 15
steps:
- - uses: actions/checkout@v2
+ - name: "Git Checkout"
+ uses: actions/checkout@v2
with:
fetch-depth: 0
- - name: 'Install Flutter'
- run: ./.github/workflows/scripts/install-flutter.sh stable
- - name: 'Install Tools'
+ - name: Cache Flutter dependencies
+ uses: actions/cache@v2
+ with:
+ path: /Users/runner/hostedtoolcache/flutter
+ key: ${{ env.flutter_version }}-flutter
+ - name: "Install Flutter"
+ uses: subosito/flutter-action@v1
+ with:
+ flutter-version: ${{ env.flutter_version }}
+ - name: "Install Tools"
run: |
- ./.github/workflows/scripts/install-tools.sh
- flutter pub global activate coverage
- flutter pub global activate remove_from_coverage
- - name: 'Bootstrap Workspace'
+ flutter pub global activate melos
+ pub global activate remove_from_coverage
+ - name: "Bootstrap Workspace"
run: melos bootstrap
- - name: 'Dart Test'
- run: |
- cd packages/stream_chat
- flutter pub run test --coverage coverage/
- format_coverage --lcov --in=coverage/ --out=coverage/lcov.info --packages=.packages --report-on=lib
- - name: 'Flutter Test'
- run: |
- melos exec -c 3 --flutter --dir-exists=test --ignore="*example*" --ignore="*web*" -- \
- flutter test --coverage
- - name: CodeCov
- run: |
- melos exec -c 3 --fail-fast --dir-exists=test --ignore="*example*" --ignore="*web*" -- \
- "\$MELOS_ROOT_PATH/.github/workflows/scripts/coverage.sh"
- bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
- - uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
+ - name: "Flutter Test"
+ run: melos run test:all
+ - name: "Collect Coverage"
+ run: melos run coverage:ignore-file --no-select
+ - name: "Upload Coverage"
+ uses: codecov/codecov-action@v1
+ with:
+ token: ${{secrets.CODECOV_TOKEN}}
+ files: packages/*/coverage/lcov.info
+ - name: "Stream Chat Coverage Check"
+ uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
with:
path: packages/stream_chat/coverage/lcov.info
- min_coverage: 40
- - uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
+ min_coverage: 80
+ - name: "Stream Chat Persistence Coverage Check"
+ uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
with:
path: packages/stream_chat_persistence/coverage/lcov.info
min_coverage: 95
- - uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
+ - name: "Stream Chat Flutter Core Coverage Check"
+ uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
with:
path: packages/stream_chat_flutter_core/coverage/lcov.info
min_coverage: 90
- - uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
+ - name: "Stream Chat Flutter Coverage Check"
+ uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
with:
path: packages/stream_chat_flutter/coverage/lcov.info
- min_coverage: 16
+ min_coverage: 67
\ No newline at end of file
diff --git a/packages/stream_chat_flutter_core/analysis_options.yaml b/analysis_options.yaml
similarity index 90%
rename from packages/stream_chat_flutter_core/analysis_options.yaml
rename to analysis_options.yaml
index 545d5492..71604a87 100644
--- a/packages/stream_chat_flutter_core/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,11 +1,14 @@
analyzer:
exclude:
- - lib/**/*.g.dart
- - lib/**/*.freezed.dart
- - example/*
- - test/*
+ - packages/*/lib/**/*.g.dart
+ - packages/*/lib/src/emoji
+ - packages/*/lib/**/*.freezed.dart
+
linter:
rules:
+ # these rules are documented on and in the same order as
+ # the Dart Lint rules page to make maintenance easier
+ # https://github.com/dart-lang/linter/blob/master/example/all.yaml
- always_use_package_imports
- avoid_empty_else
- avoid_relative_lib_imports
@@ -42,7 +45,6 @@ linter:
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_return_types_on_setters
- - avoid_returning_null
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
@@ -138,8 +140,7 @@ linter:
- package_names
- sort_pub_dependencies
- # To be added when null-safe:
- # - cast_nullable_to_non_nullable
- #- unnecessary_null_checks
- # - tighten_type_of_initializing_formals
- # - null_check_on_nullable_type_parameter
\ No newline at end of file
+ - cast_nullable_to_non_nullable
+ - unnecessary_null_checks
+ - tighten_type_of_initializing_formals
+ - null_check_on_nullable_type_parameter
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/assets/channel_header.png b/docusaurus/docs/Flutter/assets/channel_header.png
new file mode 100644
index 00000000..98f41c61
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_header.png differ
diff --git a/docusaurus/docs/Flutter/assets/channel_header_custom_title.png b/docusaurus/docs/Flutter/assets/channel_header_custom_title.png
new file mode 100644
index 00000000..65a9ee75
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_header_custom_title.png differ
diff --git a/docusaurus/docs/Flutter/assets/channel_list_header.png b/docusaurus/docs/Flutter/assets/channel_list_header.png
new file mode 100644
index 00000000..6f112db9
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_list_header.png differ
diff --git a/docusaurus/docs/Flutter/assets/channel_list_header_custom_subtitle.png b/docusaurus/docs/Flutter/assets/channel_list_header_custom_subtitle.png
new file mode 100644
index 00000000..3c779857
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_list_header_custom_subtitle.png differ
diff --git a/docusaurus/docs/Flutter/assets/channel_list_view.png b/docusaurus/docs/Flutter/assets/channel_list_view.png
new file mode 100644
index 00000000..a4390c2e
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_list_view.png differ
diff --git a/docusaurus/docs/Flutter/assets/channel_preview.png b/docusaurus/docs/Flutter/assets/channel_preview.png
new file mode 100644
index 00000000..39f5629b
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/channel_preview.png differ
diff --git a/docusaurus/docs/Flutter/assets/chat_basics.png b/docusaurus/docs/Flutter/assets/chat_basics.png
new file mode 100644
index 00000000..4eb0aa67
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/chat_basics.png differ
diff --git a/docusaurus/docs/Flutter/assets/dashboard_firebase_enable.jpeg b/docusaurus/docs/Flutter/assets/dashboard_firebase_enable.jpeg
new file mode 100644
index 00000000..e4696ec8
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/dashboard_firebase_enable.jpeg differ
diff --git a/docusaurus/docs/Flutter/assets/dashboard_firebase_key.jpeg b/docusaurus/docs/Flutter/assets/dashboard_firebase_key.jpeg
new file mode 100644
index 00000000..87243e91
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/dashboard_firebase_key.jpeg differ
diff --git a/docusaurus/docs/Flutter/assets/dashboard_save_changes.jpeg b/docusaurus/docs/Flutter/assets/dashboard_save_changes.jpeg
new file mode 100644
index 00000000..1c58a93e
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/dashboard_save_changes.jpeg differ
diff --git a/docusaurus/docs/Flutter/assets/firebase_project_settings.jpeg b/docusaurus/docs/Flutter/assets/firebase_project_settings.jpeg
new file mode 100644
index 00000000..4fbc6521
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/firebase_project_settings.jpeg differ
diff --git a/docusaurus/docs/Flutter/assets/location_sharing_example.jpg b/docusaurus/docs/Flutter/assets/location_sharing_example.jpg
new file mode 100644
index 00000000..7f220379
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/location_sharing_example.jpg differ
diff --git a/docusaurus/docs/Flutter/assets/location_sharing_example_message.jpg b/docusaurus/docs/Flutter/assets/location_sharing_example_message.jpg
new file mode 100644
index 00000000..707f1388
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/location_sharing_example_message.jpg differ
diff --git a/docusaurus/docs/Flutter/assets/location_sharing_example_message_thumbnail.jpg b/docusaurus/docs/Flutter/assets/location_sharing_example_message_thumbnail.jpg
new file mode 100644
index 00000000..e2b7d624
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/location_sharing_example_message_thumbnail.jpg differ
diff --git a/docusaurus/docs/Flutter/assets/message_input.png b/docusaurus/docs/Flutter/assets/message_input.png
new file mode 100644
index 00000000..d63cfbb3
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_input.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_input_change_position.png b/docusaurus/docs/Flutter/assets/message_input_change_position.png
new file mode 100644
index 00000000..859107d2
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_input_change_position.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_input_quoted_message.png b/docusaurus/docs/Flutter/assets/message_input_quoted_message.png
new file mode 100644
index 00000000..c1fda223
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_input_quoted_message.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_list_view.png b/docusaurus/docs/Flutter/assets/message_list_view.png
new file mode 100644
index 00000000..4f9be344
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_list_view.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_list_view_pin.png b/docusaurus/docs/Flutter/assets/message_list_view_pin.png
new file mode 100644
index 00000000..0b6f1c39
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_list_view_pin.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_list_view_threads.png b/docusaurus/docs/Flutter/assets/message_list_view_threads.png
new file mode 100644
index 00000000..2c938766
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_list_view_threads.png differ
diff --git a/docusaurus/docs/Flutter/assets/message_search_list_view.png b/docusaurus/docs/Flutter/assets/message_search_list_view.png
new file mode 100644
index 00000000..b13f5bdc
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/message_search_list_view.png differ
diff --git a/docusaurus/docs/Flutter/assets/sdk_title.png b/docusaurus/docs/Flutter/assets/sdk_title.png
new file mode 100644
index 00000000..4d92e891
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/sdk_title.png differ
diff --git a/docusaurus/docs/Flutter/assets/server_key.png b/docusaurus/docs/Flutter/assets/server_key.png
new file mode 100644
index 00000000..f11d6fb5
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/server_key.png differ
diff --git a/docusaurus/docs/Flutter/assets/swipe_channel.png b/docusaurus/docs/Flutter/assets/swipe_channel.png
new file mode 100644
index 00000000..44f13ca5
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/swipe_channel.png differ
diff --git a/docusaurus/docs/Flutter/assets/user_list_view.png b/docusaurus/docs/Flutter/assets/user_list_view.png
new file mode 100644
index 00000000..4beffacc
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/user_list_view.png differ
diff --git a/docusaurus/docs/Flutter/assets/using_theme.jpg b/docusaurus/docs/Flutter/assets/using_theme.jpg
new file mode 100644
index 00000000..b835d931
Binary files /dev/null and b/docusaurus/docs/Flutter/assets/using_theme.jpg differ
diff --git a/docusaurus/docs/Flutter/basics/_category_.json b/docusaurus/docs/Flutter/basics/_category_.json
new file mode 100644
index 00000000..76d33569
--- /dev/null
+++ b/docusaurus/docs/Flutter/basics/_category_.json
@@ -0,0 +1,4 @@
+{
+ "label": "Introduction",
+ "position": 1
+}
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/basics/choose_package.mdx b/docusaurus/docs/Flutter/basics/choose_package.mdx
new file mode 100644
index 00000000..8be73f01
--- /dev/null
+++ b/docusaurus/docs/Flutter/basics/choose_package.mdx
@@ -0,0 +1,55 @@
+---
+id: choose_package
+sidebar_position: 2
+title: Choosing The Right Flutter Package
+---
+
+### Why the SDK is split into different packages
+
+Different applications need different levels of customization and integration with the Stream Chat SDK.
+To do this, the Flutter SDK is split into three different packages which build upon the last and give
+varying levels of control to the developer. The higher level packages offer better compatibility out of the
+box while the lower level SDKs offer fine grained control. There is also a separate package for persistence
+which allows you persist data locally which works with all packages.
+
+### How do I choose?
+
+#### The case for stream_chat_flutter
+
+For the quickest way to integrate Stream Chat with your app, the UI SDK (`stream_chat_flutter`) is the
+way to go. `stream_chat_flutter` contains prebuilt components that manage most operations like data
+fetching, pagination, sending a message, and more. This ensures you have a nearly out-of-the-box
+experience adding chat to your applications. It is also possible to use this in conjunction with
+lower level operations of the SDK to get the best of both worlds.
+
+:::note
+The package allows customization of components to a large extent making it easy to tweak the theme
+to match your app colors and such. If you require any additional feature or customization, feel free
+to request this through our support channels.
+:::
+
+Summary:
+
+For the quickest and easiest way to add Chat to your app with prebuilt UI components, use stream_chat_flutter
+
+
+#### The case for stream_chat_flutter_core
+
+If your application involves UI that does not fit in with the stream_chat_flutter components, stream_chat_flutter_core
+strips away the UI associated with the components and provides the data fetching and manipulation
+capabilities while supplying builders for UI. This allows you to implement your own UI and themes
+completely independently while not worrying about writing functions for data and pagination.
+
+Summary:
+
+For implementing your own custom UI while not having to worry about lower level API calls, use stream_chat_flutter_core.
+
+#### The case for stream_chat
+
+The stream_chat package is the Low-level Client (LLC) of Stream Chat in Flutter. This package wraps
+the underlying functionality of Stream Chat and allows the most customization in terms of UI, data,
+and architecture.
+
+Summary:
+
+For the most control over the SDK and dealing with low level calls to the API, use stream_chat.
diff --git a/docusaurus/docs/Flutter/basics/introduction.mdx b/docusaurus/docs/Flutter/basics/introduction.mdx
new file mode 100644
index 00000000..4c45855c
--- /dev/null
+++ b/docusaurus/docs/Flutter/basics/introduction.mdx
@@ -0,0 +1,71 @@
+---
+slug: /
+id: introduction
+sidebar_position: 1
+title: About The Flutter SDK
+---
+Exploring The Basics Of Stream Chat
+
+
+
+Stream Chat is a service that helps you easily build a full chat experience in your Flutter (and more) apps.
+
+This section of the documentation focuses on our Flutter SDK which helps you easily
+ship high quality messaging experiences in apps and programs built with the [Flutter toolkit made
+by Google](https://flutter.dev).
+
+The Stream Chat Flutter SDK comprises of four different packages to choose from ranging from ones
+giving you complete control to ones that give you a rich out-of-the-box chat experience.
+
+The packages that make up the Stream Chat SDK are:
+
+1. Low Level Client (stream_chat): a pure Dart package that can be used on any Dart project.
+It provides a low-level client to access the Stream Chat service.
+2. Core (stream_chat_flutter_core): provides business logic to fetch common things required
+for integrating Stream Chat into your application.
+The core package allows more customisation and hence provides business logic but no UI components.
+3. UI (stream_chat_flutter): this library includes both a low-level chat SDK and a set of
+reusable and customisable UI components.
+4. Persistence (stream_chat_persistence): provides a persistence client for fetching and
+saving chat data locally.
+
+We recommend building prototypes using the full UI package since it contains UI widgets already
+integrated with Stream's API. [stream_chat_flutter](https://pub.dev/packages/stream_chat_flutter)
+is the fastest way to get up and running using Stream chat in your app.
+
+The Flutter SDK enables you to build any type of chat or messaging experience for Android, iOS, Web
+and Desktop.
+
+If you're building a very custom UI and would prefer a more lean package,
+our [core package](https://pub.dev/packages/stream_chat_flutter) will be suited to this use case. Core allows you to build custom,
+expressive UIs while retaining the benefits of our full Flutter SDK.
+APIs for accessing and controlling users, sending messages, etc are seamlessly integrated into
+this package and accessible via providers and builders.
+
+Before going into the docs, let's take a small detour to look at how the elements of Stream Chat are structured.
+
+There are two core elements in chat, Users and Channels.
+Channels are groups of one or more users that can message each other.
+In an app, you need to have a user connected to query channels.
+
+There is no specific distinction between a chat between two people and a group chat,
+but there is a way to create a unique chat between a certain number of people by creating a distinct channel.
+
+
+
+In essence, a normal two-person chat would be a distinct channel created with two members (you cannot add or delete members in this channel), whereas a group created with two people would simply be a non distinct channel (possible to add or remove members).
+
+Note: It is also possible to add more than two people in a distinct channel which retains the same add/removal properties and resembles the Slack DMs where you can DM one or more people as well.
+
+In summary, if you were creating a Whatsapp-like app, the first screen would be a list of channels - which on opening would show a list of messages that were sent by the users in the Channel.
+
+While this is a simplistic overview of the service, the Flutter SDK handles the UI and more time consuming things (media upload, offline storage, theming, etc.) for you.
+
+Before reading the docs, consider trying our [online API tour](https://getstream.io/chat/get_started/),
+it is a nice way to learn how the API works.
+It's in-browser so Javascript-based but the ideas are pretty much the same as Dart.
+
+You may also like to look at the [Flutter tutorial](https://getstream.io/chat/flutter/tutorial/)
+which focuses on using the UI package to get Stream Chat integrated into a Flutter app.
+
+Further sections break down each individual packages and explain several common operations.
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/guides/_category_.json b/docusaurus/docs/Flutter/guides/_category_.json
new file mode 100644
index 00000000..cb58ac0d
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/_category_.json
@@ -0,0 +1,4 @@
+{
+ "label": "Guides",
+ "position": 2
+}
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx b/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx
new file mode 100644
index 00000000..0c427713
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/adding_custom_attachments.mdx
@@ -0,0 +1,260 @@
+---
+id: adding_custom_attachments
+sidebar_position: 4
+title: Adding Custom Attachments
+---
+
+Adding Your Own Types Of Attachments To A Message
+
+### Introduction
+
+Stream Chat supports attachment types like images, video and files by default. You can also add your
+own types of attachments through the SDK such as location, audio, etc.
+
+This involves doing three things:
+
+1) Rendering the attachment thumbnail in the `MessageInput`
+
+2) Sending a message with the custom attachment
+
+3) Rendering the custom message attachment
+
+To do this, let's check out an example to add location sharing to Stream Chat.
+
+### Location Sharing
+
+Let's build an example of location sharing option in the app:
+
+
+
+* Show a "Share Location" button next to MessageInput Textfield.
+
+* When the user presses this button, it should fetch the current location coordinates of the user, and send a message on the channel as follows:
+
+```dart
+Message(
+ text: 'This is my location',
+ attachments: [
+ Attachment(
+ uploadState: UploadState.success(),
+ type: 'location',
+ extraData: {
+ 'latitude': 'fetched_latitude',
+ 'longitude': 'fetched_longitude',
+ },
+ ),
+ ],
+)
+```
+
+For our example, we are going to use [geolocator](https://pub.dev/packages/geolocator) library.
+Please check their [setup instructions](https://pub.dev/packages/geolocator) on their docs.
+
+NOTE: If you are testing on iOS simulator, you will need to set some dummy coordinates, as mentioned [here](https://stackoverflow.com/a/31238119/7489541).
+Also don't forget to enable "location update" capability in background mode, from XCode.
+
+On the receiver end, `location` type attachment should be rendered in map view, in the `MessageListView`.
+We are going to use [Google Static Maps API](https://developers.google.com/maps/documentation/maps-static/overview) to render the map in the message.
+You can use other libraries as well such as [google_maps_flutter](https://pub.dev/packages/google_maps_flutter).
+
+First, we add a button which when clicked fetches and shares location into the `MessageInput`:
+
+```dart
+MessageInput(
+ actions: [
+ InkWell(
+ child: Icon(
+ Icons.location_on,
+ size: 20.0,
+ color: StreamChatTheme.of(context).colorTheme.grey,
+ ),
+ onTap: () {
+ var channel = StreamChannel.of(context).channel;
+ var user = StreamChat.of(context).user;
+
+ _determinePosition().then((value) {
+ channel.sendMessage(
+ Message(
+ text: 'This is my location',
+ attachments: [
+ Attachment(
+ uploadState: UploadState.success(),
+ type: 'location',
+ extraData: {
+ 'latitude': value.latitude.toString(),
+ 'longitude': value.longitude.toString(),
+ },
+ ),
+ ],
+ ),
+ );
+ }).catchError((err) {
+ print('Error getting location!');
+ });
+ },
+ ),
+ ],
+),
+
+Future _determinePosition() async {
+ bool serviceEnabled;
+ LocationPermission permission;
+
+ serviceEnabled = await Geolocator.isLocationServiceEnabled();
+ if (!serviceEnabled) {
+ return Future.error('Location services are disabled.');
+ }
+
+ permission = await Geolocator.checkPermission();
+ if (permission == LocationPermission.denied) {
+ permission = await Geolocator.requestPermission();
+ if (permission == LocationPermission.deniedForever) {
+ return Future.error(
+ 'Location permissions are permanently denied, we cannot request permissions.');
+ }
+
+ if (permission == LocationPermission.denied) {
+ return Future.error(
+ 'Location permissions are denied');
+ }
+ }
+
+ return await Geolocator.getCurrentPosition();
+}
+```
+
+Next, we build the Static Maps URL (Add your API key before using the code snippet):
+
+```dart
+ String _buildMapAttachment(String lat, String long) {
+ var baseURL = 'https://maps.googleapis.com/maps/api/staticmap?';
+ var url = Uri(
+ scheme: 'https',
+ host: 'maps.googleapis.com',
+ port: 443,
+ path: '/maps/api/staticmap',
+ queryParameters: {
+ 'center': '${lat},${long}',
+ 'zoom': '15',
+ 'size': '600x300',
+ 'maptype': 'roadmap',
+ 'key': 'YOUR_API_KEY',
+ 'markers': 'color:red|${lat},${long}'
+ });
+
+ return url.toString();
+ }
+```
+
+And then modify the MessageListView and tell it how to build a location attachment:
+
+```dart
+MessageListView(
+ customAttachmentBuilders: {
+ 'location': (context, message, attachments) {
+ var attachmentWidget = Image.network(
+ _buildMapAttachment(
+ attachments[0].extraData['latitude'],
+ attachments[0].extraData['longitude'],
+ ),
+ );
+
+ return wrapAttachmentWidget(context, attachmentWidget, null, true, BorderRadius.circular(8.0));
+ }
+ },
+),
+```
+
+This gives us the final location attachment:
+
+
+
+Additionally, you can also add a thumbnail if a message has a location attachment (unlike in this case, where we sent the message directly).
+
+To do this, we will:
+
+1) Add an attachment instead of sending a message
+
+2) Customize the `MessageInput`
+
+First, we add the attachment when the location button is clicked:
+
+```dart
+ GlobalKey _messageInputKey = GlobalKey();
+
+ MessageInput(
+ key: _messageInputKey,
+ actions: [
+ InkWell(
+ child: Icon(
+ Icons.location_on,
+ size: 20.0,
+ color: StreamChatTheme.of(context).colorTheme.grey,
+ ),
+ onTap: () {
+ _determinePosition().then((value) {
+ _messageInputKey.currentState.addAttachment(
+ Attachment(
+ uploadState: UploadState.success(),
+ type: 'location',
+ extraData: {
+ 'latitude': value.latitude.toString(),
+ 'longitude': value.longitude.toString(),
+ },
+ ),
+ );
+ }).catchError((err) {
+ print('Error getting location!');
+ });
+ },
+ ),
+ ],
+ ),
+```
+
+After this, we can build the thumbnail:
+
+```dart
+MessageInput(
+ key: _messageInputKey,
+ actions: [
+ InkWell(
+ child: Icon(
+ Icons.location_on,
+ size: 20.0,
+ color: StreamChatTheme.of(context).colorTheme.grey,
+ ),
+ onTap: () {
+ _determinePosition().then((value) {
+ _messageInputKey.currentState.addAttachment(
+ Attachment(
+ uploadState: UploadState.success(),
+ type: 'location',
+ extraData: {
+ 'latitude': value.latitude.toString(),
+ 'longitude': value.longitude.toString(),
+ },
+ ),
+ );
+ }).catchError((err) {
+ print('Error getting location!');
+ });
+ },
+ ),
+ ],
+ attachmentThumbnailBuilders: {
+ 'location': (context, attachment) {
+ return Image.network(
+ _buildMapAttachment(
+ attachment.extraData['latitude'],
+ attachment.extraData['longitude'],
+ ),
+ );
+ },
+ },
+),
+```
+
+And we can see the thumbnails in the MessageInput:
+
+
diff --git a/docusaurus/docs/Flutter/guides/adding_local_data_persistence.mdx b/docusaurus/docs/Flutter/guides/adding_local_data_persistence.mdx
new file mode 100644
index 00000000..21ec99ce
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/adding_local_data_persistence.mdx
@@ -0,0 +1,6 @@
+---
+id: local_data_persistence
+sidebar_position: 2
+title: Adding Local Data Persistence
+---
+
diff --git a/docusaurus/docs/Flutter/guides/adding_push_notifcations.mdx b/docusaurus/docs/Flutter/guides/adding_push_notifcations.mdx
new file mode 100644
index 00000000..529f03cb
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/adding_push_notifcations.mdx
@@ -0,0 +1,234 @@
+---
+id: adding_push_notifications
+sidebar_position: 3
+title: Adding Push Notifications
+---
+
+Adding Push Notifications To Your Application
+
+### Introduction
+
+Push notifications are a core part of the experience for a messaging app. Users often need to be notified
+of new messages and old notifications sometimes need to be updated silently as well.
+
+This guide details how to add push notifications to your app.
+
+Make sure to check [this section](https://getstream.io/chat/docs/flutter-dart/push_introduction/?language=dart) of the docs to read about the push delivery logic.
+
+### Setup FCM
+
+To integrate push notifications in your Flutter app you need to use the package [firebase_messaging](https://pub.dev/packages/firebase_messaging).
+
+
+Follow the [Firebase documentation](https://firebase.flutter.dev/docs/messaging/overview/) to know how to set up the plugin for both Android and iOS.
+
+
+Once that's done FCM should be able to send push notifications to your devices.
+
+### Integration with Stream
+
+#### Step 1
+
+From the [Firebase Console](https://console.firebase.google.com/), select the project your app belongs to.
+
+#### Step 2
+
+Click on the gear icon next to `Project Overview` and navigate to **Project settings**
+
+
+
+#### Step 3
+
+Navigate to the `Cloud Messaging` tab
+
+#### Step 4
+
+Under `Project Credentials`, locate the `Server key` and copy it
+
+
+
+#### Step 5
+
+Upload the `Server Key` in your chat dashboard
+
+
+
+
+
+
+:::note
+We are setting up the Android section, but this will work for both Android and iOS if you're using Firebase for both of them!
+:::
+
+#### Step 6
+
+Save your push notification settings changes
+
+
+
+**OR**
+
+Upload the `Server Key` via API call using a backend SDK
+
+```js
+await client.updateAppSettings({
+ firebase_config: {
+ server_key: 'server_key',
+ notification_template: `{"message":{"notification":{"title":"New messages","body":"You have {{ unread_count }} new message(s) from {{ sender.name }}"},"android":{"ttl":"86400s","notification":{"click_action":"OPEN_ACTIVITY_1"}}}}`,
+ data_template: `{"sender":"{{ sender.id }}","channel":{"type": "{{ channel.type }}","id":"{{ channel.id }}"},"message":"{{ message.id }}"}`
+ },
+});
+```
+
+### Registering a device at Stream Backend
+
+Once you configure Firebase server key and set it up on Stream dashboard a device that is supposed to receive push notifications needs to be registered at Stream backend. This is usually done by listening for Firebase device token updates and passing them to the backend as follows:
+
+```dart
+firebaseMessaging.onTokenRefresh.listen((token) {
+ client.addDevice(token, PushProvider.firebase);
+});
+```
+
+### Possible issues
+
+
+We only send push notifications when the user doesn't have any active websocket connection (which is established when you call `client.connectUser`). If you set the [onBackgroundEventReceived](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChat/onBackgroundEventReceived.html) property of the StreamChat widget, when your app goes to background, your device will keep the ws connection alive for 1 minute, and so within this period, you won't receive any push notification.
+
+Make sure to read the [general push docs](https://getstream.io/chat/docs/flutter-dart/push_introduction/?language=dart) in order to avoid known gotchas that may make your relationship with notifications go bad 😢
+
+### Testing if Push Notifications are Setup Correctly
+
+If you're not sure if you've set up push notifications correctly (e.g. you don't always receive them, they work unreliably), you can follow these steps to make sure your config is correct and working:
+
+1. Clone our repo for push testing git clone git@github.com:GetStream/chat-push-test.git
+
+2. `cd flutter`
+
+3. In folder run `flutter pub get`
+
+4. Input your api key and secret in `lib/main.dart`
+
+5. Change the bundle identifier/application ID and development team/user so you can run the app in your device (**do not** run on iOS simulator, Android emulator is fine)
+
+6. Add your `google-services.json/GoogleService-Info.plist`
+
+7. Run the app
+
+8. Accept push notification permission (iOS only)
+
+9. Tap on `Device ID` and copy it
+
+10. Send the app to background
+
+11. After configuring [stream-cli](https://github.com/GetStream/stream-cli) paste the following command on command line using your user ID
+
+```shell
+stream chat:push:test -u
+```
+
+You should get a test push notification
+
+### App in the background but still connected
+
+The [StreamChat](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChat-class.html) widget lets you define a [onBackgroundEventReceived](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChat/onBackgroundEventReceived.html) handler in order to handle events while the app is in the background, but the client is still connected.
+
+This is useful because it lets you keep the connection alive in cases in which the app goes in the background just for some seconds (eg: multitasking, picking pictures from the gallery...)
+
+You can even customize the [backgroundKeepAlive](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChat/backgroundKeepAlive.html) duration.
+
+In order to show notifications in such a case we suggest using the package [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications); follow the package guide to successfully set up the plugin.
+
+Once that's done you should set the [onBackgroundEventReceived](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChat/onBackgroundEventReceived.html); here is an example:
+
+```dart
+...
+StreamChat(
+ client: client,
+ onBackgroundEventReceived: (e) {
+ final currentUserId = client.state.user.id;
+ if (![
+ EventType.messageNew,
+ EventType.notificationMessageNew,
+ ].contains(event.type) ||
+ event.user.id == currentUserId) {
+ return;
+ }
+ if (event.message == null) return;
+ final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
+ final initializationSettingsAndroid =
+ AndroidInitializationSettings('launch_background');
+ final initializationSettingsIOS = IOSInitializationSettings();
+ final initializationSettings = InitializationSettings(
+ android: initializationSettingsAndroid,
+ iOS: initializationSettingsIOS,
+ );
+ await flutterLocalNotificationsPlugin.initialize(initializationSettings);
+ await flutterLocalNotificationsPlugin.show(
+ event.message.id.hashCode,
+ event.message.user.name,
+ event.message.text,
+ NotificationDetails(
+ android: AndroidNotificationDetails(
+ 'message channel',
+ 'Message channel',
+ 'Channel used for showing messages',
+ priority: Priority.high,
+ importance: Importance.high,
+ ),
+ iOS: IOSNotificationDetails(),
+ ),
+ );
+ },
+ child: ....
+);
+...
+```
+
+As you can see we generate a local notification whenever a message.new or notification.message_new event is received.
+
+:::note
+Using `flutter_local_notifications` is a great way to implement notifications while the is in foreground too! You can generate a local notification listening to events using the method `streamChatClient.on()` and react to the events you want.
+:::
+
+### Saving notification messages to the offline storage
+
+You may want to save received messages when you receive them via a notification so that later on when you open the app they're already there.
+
+To do this we need to update the push notification data payload at Stream Dashboard and clear the notification one:
+
+```json
+{
+ "message_id": "{{ message.id }}",
+ "channel_id": "{{ channel.id }}",
+ "channel_type": "{{ channel.type }}"
+}
+```
+
+Then we need to integrate the package [stream_chat_persistence](https://pub.dev/packages/stream_chat_persistence) in our app that exports a persistence client, learn [here](https://pub.dev/packages/stream_chat_persistence#usage) how to set it up.
+
+Then during the call `firebaseMessaging.configure(...)` we need to set the `onBackgroundMessage` parameter using a TOP-LEVEL or STATIC function to handle background messages; here is an example:
+
+```dart
+Future myBackgroundMessageHandler(message) async {
+ if (message.containsKey('data')) {
+ final data = message['data'];
+ final messageId = data['message_id'];
+ final channelId = data['channel_id'];
+ final channelType = data['channel_type'];
+ final cid = '$channelType:$channelId';
+
+ final client = StreamChatClient(apiKey);
+ final persistenceClient = StreamChatPersistenceClient();
+ await persistenceClient.connect(userId);
+
+ final message = await client.getMessage(messageId).then((res) => res.message);
+
+ await persistenceClient.updateMessages(cid, [message]);
+ persistenceClient.disconnect();
+
+ /// This can be done using the package flutter_local_notifications as we did before 👆
+ _showLocalNotification();
+ }
+}
+```
diff --git a/docusaurus/docs/Flutter/guides/introduction.mdx b/docusaurus/docs/Flutter/guides/introduction.mdx
new file mode 100644
index 00000000..fc8f385e
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/introduction.mdx
@@ -0,0 +1,5 @@
+---
+id: introduction
+sidebar_position: 1
+title: Introduction
+---
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx b/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx
new file mode 100644
index 00000000..394137bd
--- /dev/null
+++ b/docusaurus/docs/Flutter/guides/migration_guide_2_0.mdx
@@ -0,0 +1,298 @@
+---
+id: mig_guide_2_0
+sidebar_position: 5
+title: Migrating to 2.0 (Null-safety)
+---
+
+A Migration Guide For Switching To v2.0 Of The Flutter SDK
+
+### Overview
+
+v2.0 of the Stream Chat Flutter SDK brings along several changes - primarily making the SDK null-safe.
+Null safety allows your apps to run faster, with fewer errors, and with less code.
+
+Check [this link](https://flutter.dev/docs/null-safety) for more about Null Safety in Flutter.
+
+This guide is intended to enumerate and better explain the changes in the SDK.
+
+The changes will be listed by package and a concise changelog will follow with more info.
+
+### Changelog of `stream_chat_flutter`
+
+#### 🛑️ Breaking Changes from 1.5.4
+
+* Migrate this package to null safety
+
+* Renamed `ChannelImage` to `ChannelAvatar`
+
+* Updated `StreamChatThemeData.reactionIcons` to accept custom builder
+
+* Renamed `ColorTheme` properties to reflect the purpose of the colors
+
+ * `ColorTheme.black` -> `ColorTheme.textHighEmphasis`
+ * `ColorTheme.grey` -> `ColorTheme.textLowEmphasis`
+ * `ColorTheme.greyGainsboro` -> `ColorTheme.disabled`
+ * `ColorTheme.greyWhisper` -> `ColorTheme.borders`
+ * `ColorTheme.whiteSmoke` -> `ColorTheme.inputBg`
+ * `ColorTheme.whiteSnow` -> `ColorTheme.appBg`
+ * `ColorTheme.white` -> `ColorTheme.barsBg`
+ * `ColorTheme.blueAlice` -> `ColorTheme.linkBg`
+ * `ColorTheme.accentBlue` -> `ColorTheme.accentPrimary`
+ * `ColorTheme.accentRed` -> `ColorTheme.accentError`
+ * `ColorTheme.accentGreen` -> `ColorTheme.accentInfo`
+
+* `ChannelListCore` options property is removed in favor of individual properties
+
+ * `options.state` -> `bool state`
+ * `options.watch` -> `bool watch`
+ * `options.presence` -> `bool presence`
+
+* `UserListView` options property is removed in favor of individual properties
+
+ * `options.presence` -> `bool presence`
+
+* Renamed `ImageHeader` to `GalleryHeader`
+
+* Renamed `ImageFooter` to `GalleryFooter`
+
+* `MessageBuilder` and `ParentMessageBuilder` signature is now
+
+```
+typedef MessageBuilder = Widget Function(
+ BuildContext,
+ MessageDetails,
+ List,
+ MessageWidget defaultMessageWidget,
+ );
+```
+
+The last parameter is the default `MessageWidget`
+You can call `.copyWith` to customize just a subset of properties
+
+#### ✅ Added
+
+Added video compress options (frame and quality) to MessageInput
+`TypingIndicator` now has a property called `parentId` to show typing indicator specific to threads
+#493: add support for `MessageListView` header/footer
+`MessageWidget` accepts a `userAvatarBuilder`
+Added `pinMessage` ui support
+Added `MessageListView.threadSeparatorBuilder` property
+Added `MessageInput.onError` property to allow error handling
+Added `GalleryHeader`/`GalleryFooter` theme classes
+
+#### 🐞 Fixed
+
+#483: Keyboard covers input text box when editing message
+`Modals` are shown using the nearest `Navigator` to make using the SDK easier in a nested navigator use case
+#484: messages don't update without a reload
+`MessageListView` not rendering if the user is not a member of the channel
+Fix `MessageInput` overflow when there are no actions
+Minor fixes and improvements
+
+### Migrating to 2.0 for `stream_chat_flutter`
+
+:::note
+If you are migrating your full Flutter project to null-safety, first make sure you follow the
+instructions from the [official Null Safety migration guide](https://dart.dev/null-safety/migration-guide).
+:::
+
+To migrate to v2.0 for `stream_chat_flutter`, first change the version of the package to the latest
+null-safe version.
+
+```yaml
+dependencies:
+ stream_chat_flutter: ^2.0.0
+```
+
+Upon doing this, all breaking changes from the package will take immediate effect. Here are steps to
+remedy the issues:
+
+1) Replace the offending class names with the revised class names
+
+ * `ChannelImage` -> `ChannelAvatar`
+ * `ImageHeader` -> `GalleryHeader`
+ * `ImageFooter` -> `GalleryFooter`
+
+2) The new version comes with revised color names since the previous names do not suit light/dark mode
+nomenclature. Make sure any old colors used from theme are changed over to the new theme color names:
+
+ * `ColorTheme.black` -> `ColorTheme.textHighEmphasis`
+ * `ColorTheme.grey` -> `ColorTheme.textLowEmphasis`
+ * `ColorTheme.greyGainsboro` -> `ColorTheme.disabled`
+ * `ColorTheme.greyWhisper` -> `ColorTheme.borders`
+ * `ColorTheme.whiteSmoke` -> `ColorTheme.inputBg`
+ * `ColorTheme.whiteSnow` -> `ColorTheme.appBg`
+ * `ColorTheme.white` -> `ColorTheme.barsBg`
+ * `ColorTheme.blueAlice` -> `ColorTheme.linkBg`
+ * `ColorTheme.accentBlue` -> `ColorTheme.accentPrimary`
+ * `ColorTheme.accentRed` -> `ColorTheme.accentError`
+ * `ColorTheme.accentGreen` -> `ColorTheme.accentInfo`
+
+3) We decided to make messages easier to customize and now supply the default implementation of the
+messages in the builder - so you can now customize a single parameter without having to redo the
+entire implementation. Please reform your builders to take into account the new format:
+
+```
+typedef MessageBuilder = Widget Function(
+ BuildContext,
+ MessageDetails,
+ List,
+ MessageWidget defaultMessageWidget,
+ );
+```
+
+To tweak any of the default properties individually, you can use `defaultMessageWidget.copyWith()`.
+
+### Changelog of `stream_chat_flutter_core`
+
+#### 🛑️ Breaking Changes from 1.5.3
+
+* Migrate this package to null safety
+* `channelsBloc.queryChannels()`, `ChannelListCore` options param/property is removed in favor of individual params/properties
+ * `options.state` -> `bool state`
+ * `options.watch` -> `bool watch`
+ * `options.presence` -> `bool presence`
+* `usersBloc.queryUsers()`, `UserListCore` options param/property is removed in favor of individual params/properties
+ * `options.presence` -> `bool presence`
+
+#### ✅ Added
+
+* Monitor connection using `connectivity_plus` package
+
+#### 🐞 Fixed
+
+* Minor fixes
+* Performance improvements
+
+### Migrating to 2.0 for `stream_chat_flutter_core`
+
+:::note
+If you are migrating your full Flutter project to null-safety, first make sure you follow the
+instructions from the [official Null Safety migration guide](https://dart.dev/null-safety/migration-guide).
+:::
+
+To migrate to v2.0 for `stream_chat_flutter_core`, first change the version of the package to the latest
+null-safe version.
+
+```yaml
+dependencies:
+ stream_chat_flutter_core: ^2.0.0
+```
+
+Upon doing this, all breaking changes from the package will take immediate effect. Here are steps to
+remedy the issue:
+
+:::note
+The major changes in `stream_chat_flutter_core` consist of changing over from a map full of options
+to a more type safe and sound approach by changing over to explicit parameters.
+:::
+
+1) Change over Core widget implementations by using the explicit parameters instead of the options map.
+Use these explicit parameters in the widget constructor instead of the option keys:
+
+ * `options.state` -> `bool state`
+ * `options.watch` -> `bool watch`
+ * `options.presence` -> `bool presence`
+
+2) Change over query calls in the BLoCs in the same way (change from options map to explicit parameters
+in the constructor)
+
+### Changelog of `stream_chat`
+
+#### 🛑️ Breaking Changes from 1.5.3
+
+* Migrate this package to null safety
+* `ConnectUserWithProvider` now requires `tokenProvider` as a required param. (Removed from the constructor)
+* `client.disconnect()` is now divided into two different functions
+ * `client.closeConnection()` -> for closing user websocket connection.
+ * `client.disconnectUser()` -> for disconnecting user and resetting client state.
+* `client.devToken()` now returns a Token model instead of String.
+* `ApiError` is removed in favor of `StreamChatError`
+ * `StreamChatError` -> parent type for all the stream errors.
+ * `StreamWebSocketError` -> for user websocket related errors.
+ * `StreamChatNetworkError` -> for network related errors.
+* `client.queryChannels()`, `channel.query()` options param is removed in favor of individual params
+ * `option.state` -> `bool state`
+ * `option.watch` -> `bool watch`
+ * `option.presence` -> `bool presence`
+* `client.queryUsers()` options param is removed in favor of individual params
+ * `option.presence` -> `bool presence`
+* Added typed filters
+
+#### 🐞 Fixed
+
+* #369: Client does not return without internet connection
+* Several minor fixes
+* Performance improvements
+
+#### ✅ Added
+
+* New Location enum is introduced for easily changing the client location/baseUrl.
+* New `client.openConnection()` and `client.closeConnection()` is introduced to connect/disconnect user ws connection.
+* New `client.partialUpdateMessage` and `channel.partialUpdateMessage` methods
+* `connectWebSocket` parameter in connect user calls to use the client in "connection-less" mode.
+
+#### 🔄 Changed
+
+* `baseURL` is now deprecated in favor of using Location to change data location.
+
+### Migrating to 2.0 for `stream_chat`
+
+If you are migrating your full Flutter project to null-safety, first make sure you follow the
+instructions from the [official Null Safety migration guide](https://dart.dev/null-safety/migration-guide).
+:::
+
+To migrate to v2.0 for `stream_chat`, first change the version of the package to the latest
+null-safe version.
+
+```yaml
+dependencies:
+ stream_chat: ^2.0.0
+```
+
+Upon doing this, all breaking changes from the package will take immediate effect. Here are steps to
+remedy the issues:
+
+1) Change over the constructor of `connectUserWithProvider()` to the new format which has `tokenProvider` as a required param.
+
+2) We added more nuance to `disconnectUser()` by adding two new methods - one to close the connection
+and the other to disconnect the user. This allows more fine-grained control of disconnection.
+
+ * `client.closeConnection()` -> for closing user websocket connection.
+ * `client.disconnectUser()` -> for disconnecting user and resetting client state.
+
+3) We refactored how we handle errors - new error types are now introduced that replace ApiError.
+
+ * `StreamChatError` -> parent type for all the stream errors.
+ * `StreamWebSocketError` -> for user websocket related errors.
+ * `StreamChatNetworkError` -> for network related errors.
+
+4) We changed over from a map full of options to a more type-safe and sound approach by changing over to explicit parameters.
+
+Use these explicit parameters in the query parameters instead of the option keys:
+
+* `client.queryChannels()`, `channel.query()` options param is removed in favor of individual params
+ * `option.state` -> `bool state`
+ * `option.watch` -> `bool watch`
+ * `option.presence` -> `bool presence`
+* `client.queryUsers()` options param is removed in favor of individual params
+ * `option.presence` -> `bool presence`
+
+5) We added type-safe filters to make filtering in the app easier. Change over the filters to the
+new implementation.
+
+As an example, in the old app this filter:
+
+```dart
+ filter: {
+ 'members': {
+ '\$in': [StreamChat.of(context).user.id],
+ }
+ },
+```
+
+Would turn into:
+
+```dart
+ filter: Filter.in_('members', [StreamChat.of(context).user.id])
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/_category_.json b/docusaurus/docs/Flutter/stream_chat_flutter/_category_.json
new file mode 100644
index 00000000..242afb7b
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/_category_.json
@@ -0,0 +1,4 @@
+{
+ "label": "Stream Chat Flutter",
+ "position": 3
+}
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/channel_header.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/channel_header.mdx
new file mode 100644
index 00000000..bf65a863
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/channel_header.mdx
@@ -0,0 +1,84 @@
+---
+id: channel_header
+sidebar_position: 10
+title: ChannelHeader
+---
+
+A Widget To Display Common Channel Details
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/ChannelHeader-class.html)
+
+
+
+### Background
+
+When a user opens a channel, it is helpful to provide context of which channel they are in. This may
+be in the form of a channel name or the users in the channel. Along with that, there also needs to be
+a way for the user to look at more details of the channel (media, pinned messages, actions, etc.) and
+preferably also a way to navigate back to where they came from.
+
+To encapsulate all of this functionality into one widget, the Flutter SDK contains a `ChannelHeader`
+widget which provides these out of the box.
+
+### Basic Example
+
+Let's just add a `ChannelHeader` to a page with a `MessageListView` and a `MessageInput` to display
+and send messages.
+
+```dart
+class ChannelPage extends StatelessWidget {
+ const ChannelPage({
+ Key? key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: ChannelHeader(),
+ body: Column(
+ children: [
+ Expanded(
+ child: MessageListView(
+ threadBuilder: (_, parentMessage) {
+ return ThreadPage(
+ parent: parentMessage,
+ );
+ },
+ ),
+ ),
+ MessageInput(),
+ ],
+ ),
+ );
+ }
+}
+```
+
+### Customizing Parts Of The Header
+
+The header works like a `ListTile` widget.
+
+Use the `title`, `subtitle`, `leading`, or `actions` parameters to substitute the widgets for your own.
+
+```dart
+//...
+ChannelHeader(
+ title: Text('My Custom Name'),
+),
+```
+
+
+
+### Showing Connection State
+
+The `ChannelHeader` can also display connection state below the tile which shows the user if they
+are connected or offline, etc. on connection events.
+
+To enable this, use the `showConnectionStateTile` property.
+
+```dart
+//...
+ChannelHeader(
+ showConnectionStateTile: true,
+),
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_header.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_header.mdx
new file mode 100644
index 00000000..d6930cb4
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_header.mdx
@@ -0,0 +1,88 @@
+---
+id: channel_list_header
+sidebar_position: 9
+title: ChannelListHeader
+---
+
+A Header Widget For A List Of Channels
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/ChannelListHeader-class.html)
+
+
+
+### Background
+
+A common pattern for most messaging apps is to show a list of Channels (chats) on the first screen
+and navigate to an individual one on being clicked. On this first page where the list of channels are
+displayed, it is usual to have functionality such as adding a new chat, display the user logged in, etc.
+
+To encapsulate all of this functionality into one widget, the Flutter SDK contains a `ChannelListHeader`
+widget which provides these out of the box.
+
+### Basic Example
+
+This is a basic example of a page which has a `ChannelListView` and a `ChannelListHeader` to recreate a
+common Channels Page.
+
+```dart
+class DemoPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: ChannelListHeader(),
+ body: ChannelsBloc(
+ child: ChannelListView(
+ filter: Filter.in_('members', [StreamChat.of(context).user.id]),
+ sort: [SortOption('last_message_at')],
+ pagination: PaginationParams(
+ limit: 20,
+ ),
+ channelWidget: ChannelPage(),
+ ),
+ ),
+ );
+ }
+}
+```
+
+### Customizing Parts Of The Header
+
+The header works like a `ListTile` widget.
+
+Use the `titleBuilder`, `subtitle`, `leading`, or `actions` parameters to substitute the widgets for your own.
+
+```dart
+//...
+ChannelListHeader(
+ subtitle: Text('My Custom Subtitle'),
+),
+```
+
+
+
+The `titleBuilder` param helps you build different titles depending on the connection state:
+
+```dart
+//...
+ChannelListHeader(
+ titleBuilder: (context, status, client) {
+ switch(status) {
+ /// Return your title widget
+ }
+ },
+),
+```
+
+### Showing Connection State
+
+The `ChannelListHeader` can also display connection state below the tile which shows the user if they
+are connected or offline, etc. on connection events.
+
+To enable this, use the `showConnectionStateTile` property.
+
+```dart
+//...
+ChannelListHeader(
+ showConnectionStateTile: true,
+),
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_view.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_view.mdx
new file mode 100644
index 00000000..eb7baf20
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/channel_list_view.mdx
@@ -0,0 +1,111 @@
+---
+id: channel_list_view
+sidebar_position: 4
+title: ChannelListView
+---
+
+A Widget For Displaying A List Of Channels
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/ChannelListView-class.html)
+
+
+
+### Background
+
+Channels are fundamental elements of Stream Chat and constitute shared spaces which allow users to
+message each other.
+
+1:1 conversations and groups are both examples of channels, albeit with some (distinct/non-distinct)
+differences. Displaying the list of channels that a user is a part of is a pattern present in most messaging apps.
+
+The `ChannelListView` widget allows displaying a list of channels to a user. By default, this is NOT
+ONLY the channels that the user is a part of. This section goes into setting up and using a `ChannelListView`
+widget.
+
+### Basic Example
+
+Here is a basic example of the `ChannelListView` widget. It consists of the main widget itself, a `Filter`
+to filter only the channels that the user is a part of, sorting by last message time, pagination params,
+and the widget to use when a particular channel is clicked.
+
+```dart
+class ChannelListPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: ChannelsBloc(
+ child: ChannelListView(
+ filter: Filter.in_('members', [StreamChat.of(context).user.id]),
+ sort: [SortOption('last_message_at')],
+ pagination: PaginationParams(
+ limit: 20,
+ ),
+ channelWidget: ChannelPage(),
+ ),
+ ),
+ );
+ }
+}
+```
+
+This example by default displays the channels that a user is a part of. Now let's look at customizing
+the widget.
+
+### Customizing the Channel Preview
+
+A common aspect of the widget needed to be tweaked according to each app is the Channel Preview (the
+Channel tile in the list). To do this, we use the `channelPreviewBuilder` param like this:
+
+```dart
+ChannelListView(
+ ...
+ channelPreviewBuilder: (context, channel) {
+ return ListTile(
+ tileColor: Colors.amberAccent,
+ title: Center(
+ child: ChannelName(),
+ ),
+ );
+ },
+),
+```
+
+Which gives you a new Channel preview in the list:
+
+
+
+### Adding Swipe Actions
+
+To add actions (such as delete, more info, etc) when Channel preview is swiped left, set the `swipeToAction`
+parameter to `true`.
+
+```dart
+ChannelListView(
+ ...
+ swipeToAction: true,
+),
+```
+
+This adds two basic actions - info and delete:
+
+
+
+To add custom actions of your own, use the `swipeActions` param:
+
+```dart
+ChannelListView(
+ ...
+ swipeToAction: true,
+ swipeActions: [
+ SwipeAction(
+ color: Colors.blue,
+ iconWidget: Icon(Icons.add),
+ onTap: (channel) {
+ // Things to do on icon tap
+ },
+ ),
+ // Other actions here
+ ]
+),
+```
+
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/introduction.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/introduction.mdx
new file mode 100644
index 00000000..28640483
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/introduction.mdx
@@ -0,0 +1,18 @@
+---
+id: introduction
+sidebar_position: 1
+title: Introduction
+---
+
+Understanding The UI Package Of The Flutter SDK
+
+### What function does `stream_chat_flutter` serve?
+
+The UI SDK (`stream_chat_flutter`) contains official Flutter components for Stream Chat, a service for building chat applications.
+
+While the Stream Chat service provides the backend for messaging and the LLC provides an easy way to
+use it in your Flutter apps, we wanted to make sure that adding Chat functionality to your app was as quick as possible.
+
+The UI package is built on top of the low-level client and the core package and allows you to build a
+full fledged app with either the inbuilt components, modify existing components, or easily add widgets
+of your own to match your app's style better.
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/message_input.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/message_input.mdx
new file mode 100644
index 00000000..f33f85e9
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/message_input.mdx
@@ -0,0 +1,170 @@
+---
+id: message_input
+sidebar_position: 6
+title: MessageInput
+---
+
+A Widget Dealing With Everything Related To Sending A Message
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/MessageInput-class.html)
+
+
+
+### Background
+
+In Stream Chat, we can send messages in a channel. However, sending a message isn't as simple as adding
+a `TextField` and logic for sending a message. It involves additional processes like addition of media,
+quoting a message, adding a custom command like a GIF board, and much more. Moreover, most apps also
+need to customize the input to match their theme, overall color and structure pattern, etc.
+
+To do this, we created a `MessageInput` widget which abstracts all expected functionality a modern input
+needs - and allows you to use it out of the box.
+
+### Basic Example
+
+A `StreamChannel` is required above the widget tree in which the `MessageInput` is rendered since the channel is
+where the messages sent actually go. Let's look at a common example of how we could use the `MessageInput`:
+
+```dart
+class ChannelPage extends StatelessWidget {
+ const ChannelPage({
+ Key key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: ChannelHeader(),
+ body: Column(
+ children: [
+ Expanded(
+ child: MessageListView(
+ threadBuilder: (_, parentMessage) {
+ return ThreadPage(
+ parent: parentMessage,
+ );
+ },
+ ),
+ ),
+ MessageInput(),
+ ],
+ ),
+ );
+ }
+}
+```
+
+It is common to put this widget in the same page of a `MessageListView` as the bottom widget.
+
+### Quoting A Message
+
+The quoting functionality allows us to 'reply' to a specific message without creating a thread out of it.
+It adds the other message as context when sending a message and also displays it above the sent message.
+
+To quote a message, we provide a `quotedMessage` to the `MessageInput`.
+
+```dart
+Message? message;
+
+// ...
+MessageInput(
+ quotedMessage: message,
+),
+```
+
+This will add the message given above the message about to be sent.
+
+While you can implement your own functionality to select which message to reply to, the `MessageListView`
+widget helps in this case since it has an inbuilt `onMessageSwiped` callback which we can use.
+
+```dart
+
+class ChannelPage extends StatefulWidget {
+ @override
+ _ChannelPageState createState() => _ChannelPageState();
+}
+
+class _ChannelPageState extends State {
+ Message? quotedMessage;
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: Column(
+ children: [
+ Expanded(
+ child: MessageListView(
+ // ...
+ onMessageSwiped: (message) {
+ setState(() {
+ quotedMessage = message;
+ });
+ },
+ ),
+ ),
+ MessageInput(
+ quotedMessage: _quotedMessage,
+ onQuotedMessageCleared: () {
+ setState(() => _quotedMessage = null);
+ },
+ ),
+ ],
+ ),
+ );
+ }
+}
+```
+
+
+
+### Adding Custom Actions
+
+By default, the `MessageInput` has two actions: one for attachments and one for commands like Giphy.
+To add your own action, we use the `actions` parameter like this:
+
+```dart
+MessageInput(
+ actions: [
+ InkWell(
+ child: Icon(
+ Icons.location_on,
+ size: 20.0,
+ color: StreamChatTheme.of(context).colorTheme.grey,
+ ),
+ onTap: () {
+ // Do something here
+ },
+ ),
+ ],
+),
+```
+
+This will add on your action to the existing ones.
+
+### Disable Attachments
+
+To disable attachments being added to the message, set the `disableAttachments` parameter to true.
+
+```dart
+MessageInput(
+ disableAttachments: true,
+),
+```
+
+### Changing Position Of MessageInput Components
+
+You can also change the position of the TextField, actions and 'send' button relative to each other.
+
+To do this, use the `actionsLocation` or `sendButtonLocation` parameters which help you decide the location
+of the buttons in the input.
+
+For example, if we want the actions on the right and the send button inside the TextField, we can do:
+
+```dart
+MessageInput(
+ sendButtonLocation: SendButtonLocation.inside,
+ actionsLocation: ActionsLocation.right,
+),
+```
+
+
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/message_list_view.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/message_list_view.mdx
new file mode 100644
index 00000000..0ac78f7d
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/message_list_view.mdx
@@ -0,0 +1,115 @@
+---
+id: message_list_view
+sidebar_position: 5
+title: MessageListView
+---
+
+A Widget For Displaying A List Of Messages
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/MessageListView-class.html)
+
+
+
+### Background
+
+Every channel can contain a list of messages sent by users inside it. The `MessageListView` widget
+displays the list of messages inside a particular channel along with possible attachments and
+other message attributes (if the message is pinned for example). This sets it apart from the `MessageSearchListView`
+which may not contain messages only from a single channel and is used to search for messages across
+many.
+
+### Basic Example
+
+The `MessageListView` shows the list of messages of the current channel. It has inbuilt support for
+common messaging functionality: displaying and editing messages, adding / modifying reactions, support
+for quoting messages, pinning messages, and more.
+
+An example of how you can use the MessageListView is:
+
+```dart
+class ChannelPage extends StatelessWidget {
+ const ChannelPage({
+ Key key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: ChannelHeader(),
+ body: Column(
+ children: [
+ Expanded(
+ child: MessageListView(
+ threadBuilder: (_, parentMessage) {
+ return ThreadPage(
+ parent: parentMessage,
+ );
+ },
+ ),
+ ),
+ MessageInput(),
+ ],
+ ),
+ );
+ }
+}
+```
+
+### Enable Threads
+
+Threads are made of a parent message and replies linked to it. To enable threading, the SDK requires you
+to supply a `threadBuilder` which will supply the page when the thread is clicked.
+
+```dart
+MessageListView(
+ threadBuilder: (_, parentMessage) {
+ return ThreadPage(
+ parent: parentMessage,
+ );
+ },
+),
+```
+
+
+
+The `MessageListView` itself can render the thread by supplying the `parentMessage` parameter.
+
+```dart
+MessageListView(
+ parentMessage: parent,
+),
+```
+
+### Building Custom Messages
+
+You can also supply your own implementation for displaying messages using the `messageBuilder` parameter.
+
+:::note
+To customize the existing implementation, look at the `MessageWidget` documentation instead.
+:::
+
+```dart
+MessageListView(
+ messageBuilder: (context, details, messageList, defaultImpl) {
+ // Your implementation of the message here
+ // E.g: return Text(details.message.text ?? '');
+ },
+),
+```
+
+### Enabling Message Pinning
+
+Message pins save and highlight the message in the `MessageListView`. To enable users to pin the message,
+make sure the pin permissions are granted for different types of users on the dashboard. After confirming
+the appropriate users have permissions, add the user types in the `pinPermissions` parameter.
+
+```dart
+MessageListView(
+ //...
+ pinPermissions: ['admin', 'userType1', 'userType2'],
+),
+```
+
+This will allow these user types to pin messages through the message actions modal.
+
+
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/message_search_list_view.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/message_search_list_view.mdx
new file mode 100644
index 00000000..864b5e49
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/message_search_list_view.mdx
@@ -0,0 +1,62 @@
+---
+id: message_search_list_view
+sidebar_position: 8
+title: MessageSearchListView
+---
+
+A Widget To Search For Messages Across Channels
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/MessageSearchListView-class.html)
+
+
+
+### Background
+
+Users in Stream Chat can have several channels and it can get hard to remember which channel has the
+message they are searching for. As such, there needs to be a way to search for a message across multiple
+channels. This is where `MessageSearchListView` comes in.
+
+### Basic Example
+
+While the MessageListView is tied to a certain `StreamChannel`, a `MessageSearchListView` is not.
+
+```dart
+class MessageSearchPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: MessageSearchBloc(
+ child: MessageSearchListView(
+ filters: Filter.in_('members', [StreamChat.of(context).user!.id],),
+ messageQuery: 'your query here',
+ paginationParams: PaginationParams(limit: 20),
+ ),
+ ),
+ );
+ }
+}
+```
+
+### Customize The Result Tiles
+
+You can use your own widget for the result items using the `itemBuilder` parameter.
+
+```dart
+MessageSearchListView(
+ // ...
+ itemBuilder: (context, response) {
+ return Text(response.message.text);
+ },
+),
+```
+
+### Show Result Count
+
+You show the number of results via the `showResultCount` parameter.
+
+```dart
+MessageSearchListView(
+ // ...
+ showResultCount: true,
+),
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/message_widget.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/message_widget.mdx
new file mode 100644
index 00000000..5060bcac
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/message_widget.mdx
@@ -0,0 +1,98 @@
+---
+id: message_widget
+sidebar_position: 11
+title: MessageWidget
+---
+
+A Widget For Displaying Messages And Attachments
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/MessageWidget-class.html)
+
+### Background
+
+There are several things that need to be displayed with text in a message in a modern messaging app:
+attachments, highlights if the message is pinned, user avatars of the sender, etc.
+
+To encapsulate all of this functionality into one widget, the Flutter SDK contains a `MessageWidget`
+widget which provides these out of the box.
+
+### Basic Example (Modifying `MessageWidget` in `MessageListView`)
+
+Primarily, the `MessageWidget` is used in the `MessageListView`. To customize only a few properties
+of the `MessageWidget` without supplying all other properties, the `messageBuilder` builder supplies
+a default implementation of the widget for us to modify.
+
+```dart
+class ChannelPage extends StatelessWidget {
+ const ChannelPage({
+ Key key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: MessageListView(
+ messageBuilder: (context, details, messageList, defaultMessageWidget) {
+ return defaultMessageWidget.copyWith(
+ showThreadReplyIndicator: false,
+ );
+ },
+ ),
+
+ );
+ }
+}
+```
+
+### Building A Custom Attachment
+
+When a custom attachment type (location, audio, etc.) is sent, the MessageWidget also needs to know
+how to build it. For this purpose, we can use the `customAttachmentBuilders` parameter.
+
+As an example, if a message has a attachment type 'location', we do:
+
+```dart
+MessageWidget(
+ //...
+ customAttachmentBuilders: {
+ 'location': (context, message, attachments) {
+ var attachmentWidget = Image.network(
+ _buildMapAttachment(
+ attachments[0].extraData['latitude'],
+ attachments[0].extraData['longitude'],
+ ),
+ );
+
+ return wrapAttachmentWidget(context, attachmentWidget, null, true, BorderRadius.circular(8.0));
+ }
+ },
+)
+```
+
+You can also override the builder for existing attachment types like `image` and `video`.
+
+### Show User Avatar For Messages
+
+You can decide to show, hide, or remove user avatars of the sender of the message. To do this, set
+the `showUserAvatar` property like this:
+
+```dart
+MessageWidget(
+ //...
+ showUserAvatar = DisplayWidget.show,
+)
+```
+
+### Reverse the message
+
+In most cases, `MessageWidget` needs to be a different orientation depending upon if the sender is the
+user or someone else.
+
+For this, we use the `reverse` parameter to change the orientation of the message:
+
+```dart
+MessageWidget(
+ //...
+ reverse = true,
+)
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/setup.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/setup.mdx
new file mode 100644
index 00000000..22e5c6c5
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/setup.mdx
@@ -0,0 +1,48 @@
+---
+id: setup
+sidebar_position: 2
+title: Setup
+---
+
+Understanding Setup For `stream_chat_flutter`
+
+### Add pub.dev dependency
+
+First, you need to add the `stream_chat_flutter` dependency to your `pubspec.yaml`.
+
+You can either run this command:
+
+```shell
+flutter pub add stream_chat_flutter
+```
+
+OR
+
+Add this line in the dependencies section of your pubspec.yaml after substituting latest version:
+
+```yaml
+dependencies:
+ stream_chat_flutter: ^latest_version
+```
+
+You can find the package details on [pub.dev](https://pub.dev/packages/stream_chat_flutter).
+
+### Details On Platform Support
+
+`stream_chat_flutter` was originally created for Android and iOS mobile platforms. As Flutter matured,
+support for additional platforms was added and the package now has experimental support for web and desktop as
+[detailed here](https://getstream.io/blog/announcing-experimental-multi-platform-support-for-the-stream-flutter-sdk/).
+
+However, platforms other than mobile may have additional constraints due to not supporting all plugins,
+which will be addressed by the respective plugin creators over time.
+
+### Setup: iOS
+
+The library uses [flutter file picker plugin](https://github.com/miguelpruivo/flutter_file_picker) to pick files from the os.
+Follow [this wiki](https://github.com/miguelpruivo/flutter_file_picker/wiki/Setup#ios) to fulfill iOS requirements.
+
+We also use [video_player](https://pub.dev/packages/video_player) to reproduce videos.
+Follow [this guide](https://pub.dev/packages/video_player#installation) to fulfill the requirements.
+
+To pick images from the camera, we use the [image_picker](https://pub.dev/packages/image_picker) plugin.
+Follow [these instructions](https://pub.dev/packages/image_picker#ios) to check the requirements.
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/stream_chat_and_theming.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/stream_chat_and_theming.mdx
new file mode 100644
index 00000000..d527b738
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/stream_chat_and_theming.mdx
@@ -0,0 +1,71 @@
+---
+id: stream_chat_and_theming
+sidebar_position: 3
+title: StreamChat And Theming
+---
+
+Understanding How To Customize Widgets Using `StreamChatTheme`
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChatTheme-class.html) and [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/StreamChatThemeData-class.html)
+
+### Background
+
+Stream's UI SDK makes it easy for developers to add custom styles and attributes to our widgets. Like most Flutter frameworks, Stream exposes a dedicated widget for theming.
+
+Using `StreamChatTheme`, users can customize most aspects of our UI widgets by setting attributes using `StreamChatThemeData`.
+
+Similar to the `Theme` and `ThemeData` in Flutter, Stream Chat uses a top level [inherited widget](https://api.flutter.dev/flutter/widgets/InheritedWidget-class.html) to provide theming information throughout your application. This can be optionally set at the top of your application tree or at a localized point in your widget sub-tree.
+
+If you'd like to customize the look and feel of Stream chat across your entire application, we recommend setting your theme at the top level. Conversely, users can customize specific screens or widgets by wrapping components in a `StreamChatTheme`.
+
+### A closer look at StreamChatThemeData
+
+Looking at the constructor for `StreamChatThemeData`, we can see the full list of properties and widgets available for customization.
+
+Some high-level properties such as `textTheme` or `colorTheme` can be set application-wide directly from this class. In contrast, larger components such as `ChannelHeader`, `MessageInputs`, etc. have been broken up into smaller theme objects.
+
+```dart
+factory StreamChatThemeData({
+ Brightness? brightness,
+ TextTheme? textTheme,
+ ColorTheme? colorTheme,
+ ChannelListHeaderTheme? channelListHeaderTheme,
+ ChannelPreviewTheme? channelPreviewTheme,
+ ChannelTheme? channelTheme,
+ MessageTheme? otherMessageTheme,
+ MessageTheme? ownMessageTheme,
+ MessageInputTheme? messageInputTheme,
+ Widget Function(BuildContext, Channel)? defaultChannelImage,
+ Widget Function(BuildContext, User)? defaultUserImage,
+ IconThemeData? primaryIconTheme,
+ List? reactionIcons,
+ });
+```
+
+### Stream Chat Theme in use
+
+Let's take a look at customizing widgets using `StreamChatTheme`. In the example below, we can change the default color theme to yellow and override the channel header's typography and colors.
+
+```dart
+builder: (context, child) => StreamChat(
+ client: client,
+ child: child,
+ streamChatThemeData: StreamChatThemeData(
+ colorTheme: ColorTheme.light(
+ primaryAccent: const Color(0xffffe072),
+ ),
+ channelTheme: ChannelTheme(
+ channelHeaderTheme: ChannelHeaderTheme(
+ color: const Color(0xffd34646),
+ title: TextStyle(
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ),
+ ),
+```
+
+We are creating this class at the very top of our widget tree using the `streamChatThemeData` parameter found in the `StreamChat` widget.
+
+
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter/user_list_view.mdx b/docusaurus/docs/Flutter/stream_chat_flutter/user_list_view.mdx
new file mode 100644
index 00000000..61dfbeb4
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter/user_list_view.mdx
@@ -0,0 +1,88 @@
+---
+id: user_list_view
+sidebar_position: 7
+title: UserListView
+---
+
+A Widget For Displaying And Selecting Users
+
+Find the pub.dev documentation [here](https://pub.dev/documentation/stream_chat_flutter/latest/stream_chat_flutter/UserListView-class.html)
+
+
+
+### Background
+
+A list of users is required for many different purposes: showing a list of users in a Channel,
+selecting users to add in a channel, etc. The `UserListView` displays and allows selection of a list
+of users along with multiple display configurations like a list and grid.
+
+### Basic Example
+
+Let's take a look at an example where we use the widget to autocomplete user names:
+
+```dart
+class UsersListPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: UsersBloc(
+ child: UsersListView(
+ filter: Filter.notEqual('id', StreamChat.of(context).user!.id),
+ sort: [
+ SortOption(
+ 'name',
+ direction: 1,
+ ),
+ ],
+ pagination: PaginationParams(
+ limit: 25,
+ ),
+ ),
+ ),
+ );
+ }
+}
+```
+
+### Customize The User Items
+
+You can use your own widget for the user items using the `userItemBuilder` parameter.
+
+```dart
+UsersListView(
+ // ...
+ userItemBuilder: (context, user, isSelected) {
+ return Text(user.name);
+ },
+),
+```
+
+### Group Alphabetically
+
+You can group alphabetically using the `groupAlphabetically` parameter:
+
+```dart
+UsersListView(
+ //...
+ groupAlphabetically: true,
+),
+```
+
+### Selecting Users
+
+The `UserListView` widget allows selecting users in a list by supplying a selected users list and callbacks
+for when user items are tapped.
+
+```dart
+Set? selectedUsers = {};
+
+UsersListView(
+ //...
+ selectedUsers: selectedUsers,
+ onUserTap: (user, _) {
+ setState(() {
+ selectedUsers.add(user);
+ });
+ },
+),
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/_category_.json b/docusaurus/docs/Flutter/stream_chat_flutter_core/_category_.json
new file mode 100644
index 00000000..8d738e89
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/_category_.json
@@ -0,0 +1,4 @@
+{
+ "label": "Stream Chat Flutter Core",
+ "position": 4
+}
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/channel_list_core.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/channel_list_core.mdx
new file mode 100644
index 00000000..4196a14c
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/channel_list_core.mdx
@@ -0,0 +1,68 @@
+---
+id: channel_list_core
+sidebar_position: 4
+title: ChannelListCore
+---
+
+A Widget For Building A List Of Channels
+
+### Background
+
+The UI SDK of Stream Chat supplies a `ChannelListView` class that builds a list of channels fetching
+according to the filters and sort order given. However, in some cases, implementing novel UI is necessary
+that cannot be done using the customization approaches given in the widget.
+
+To do this, we extracted the logic required for fetching channels into a 'Core' widget - a widget that
+fetches channels in the expected way via the usual params but does not supply any UI and instead
+exposes builders to build the UI in situations such as loading, empty data, errors, and on data received.
+
+### Basic Example
+
+`ChannelListCore` is a simplified class that allows fetching a list of
+channels while exposing UI builders.
+
+This allows you to construct your own UI while not having to
+worry about the specific logic of fetching channels in your app.
+
+A `ChannelListController` is used to reload and paginate data.
+
+```dart
+class ChannelListPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: ChannelListCore(
+ filter: Filter.in_(
+ 'members',
+ [StreamChat.of(context).user!.id],
+ ),
+ sort: [SortOption('last_message_at')],
+ pagination: PaginationParams(
+ limit: 20,
+ ),
+ errorBuilder: (context, err) {
+ return Center(
+ child: Text('An error has occured'),
+ );
+ },
+ emptyBuilder: (context) {
+ return Center(
+ child: Text('Nothing here...'),
+ );
+ },
+ loadingBuilder: (context) {
+ return Center(
+ child: CircularProgressIndicator(),
+ );
+ },
+ listBuilder: (context, list) {
+ return ChannelPage(list);
+ }
+ ),
+ );
+ }
+}
+```
+
+Make sure to have a `StreamChatCore` ancestor in order to provide the
+information about the channels.
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/channels_bloc.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/channels_bloc.mdx
new file mode 100644
index 00000000..3cb1728a
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/channels_bloc.mdx
@@ -0,0 +1,90 @@
+---
+id: channels_bloc
+sidebar_position: 7
+title: ChannelsBloc
+---
+
+A Widget Dedicated To The Management Of A Channel List With Pagination.
+
+### Background
+
+Most widgets in the Core SDK are focused on fetching a particular type of object from Stream Chat - channels,
+messages, users, etc. The BLoC widgets bundle up the base functions used to fetch data as well as the current
+data fetched by the respective functions. Furthermore, the Core widgets use this BLoC to fetch new or
+existing data and build UI based on it.
+
+All Core and UI widgets which focus on fetching a list of objects need to have their respective functions
+above them in the widget tree. The ChannelListCore and ChannelListView require the ChannelsBloc
+above them in the widget hierarchy without which they will fail.
+
+### Understanding The Widget
+
+`ChannelsBloc` is used together with `ChannelListCore` to manage a list of
+Channels with pagination, re-ordering, querying and other operations
+associated with Channels.
+
+`ChannelsBloc` can be accessed at anytime by using the static `.of` method
+using Flutter's `BuildContext`.
+
+```dart
+var _channelsBloc = ChannelsBloc.of(context);
+```
+
+The `ChannelsBloc` widget encapsulates common functionality related to channel lists such as fetching
+the existing channels and querying new channels and also supplies them down the widget tree.
+
+The widget is required for the respective core widget (`ChannelListCore`) to fetch channels and hence
+must be above the core widget in the tree.
+
+Here is a basic implementation of `ChannelsBloc`:
+
+```dart
+ChannelsBloc(
+ child: // Further Widget Tree
+),
+```
+
+The `ChannelsBloc` widget allows three customisations:
+
+#### Lock Channels Order
+
+ChannelsBloc may change the order of channels when new messages arrive. To lock this order, we can
+set the `lockChannelsOrder` property to true.
+
+```dart
+ChannelsBloc(
+ lockChannelsOrder: true,
+ child: // Further Widget Tree
+),
+```
+
+#### Set custom channel order
+
+We can decide the order of the channels in the list by supplying a comparator to the `channelsComparator`
+parameter:
+
+```dart
+ChannelsBloc(
+ channelsComparator: (a, b) {
+ return a.createdAt!.millisecondsSinceEpoch >
+ b.createdAt!.millisecondsSinceEpoch
+ ? 1
+ : -1;
+ },
+ child: // Further Widget Tree
+),
+```
+
+#### Decide if channel should be added on new message event
+
+When a new message arrives, a `message.new` event is received. We can decide if we want to add the channel
+to the list using the `shouldAddChannel` parameter which is a callback supplying the event data:
+
+```dart
+ChannelsBloc(
+ shouldAddChannel: (event) {
+ return event.message!.extraData['priority'] == '1';
+ },
+ child: // Further Widget Tree
+),
+```
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/introduction.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/introduction.mdx
new file mode 100644
index 00000000..3c6a70f2
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/introduction.mdx
@@ -0,0 +1,80 @@
+---
+id: introduction
+sidebar_position: 1
+title: Introduction
+---
+
+Understanding The Core Package Of The Flutter SDK
+
+This package provides business logic to fetch common things required for integrating Stream Chat into your application.
+The core package allows more customisation and hence provides business logic but no UI components.
+Please use the `stream_chat_flutter` package for the full fledged suite of UI components or `stream_chat` for the low-level client.
+
+### Background
+
+In the early days of the Flutter SDK, the SDK was only split into the LLC (`stream_chat`) and
+the UI package (`stream_chat_flutter`). With this you could use a fully built interface with the UI package
+or a fully custom interface with the LLC. However, we soon recognised the need for a third intermediary
+package which made tasks like building and modifying a list of channels or messages easy but without
+the complexity of using low level components. The Core package (`stream_chat_flutter_core`) is a manifestation
+of the same idea and allows you to build an interface with Stream Chat without having to deal with
+low level code and architecture as well as implementing your own theme and UI effortlessly.
+Also, it has very few dependencies.
+
+We will now explore the components of this intermediary package and understand how it helps you build
+the experience you want your users to have.
+
+The package primarily contains three types of classes:
+
+* Business Logic Components
+* Core Components
+* Core Controllers
+
+### Business Logic Components
+
+These components allow you to have the maximum and lower-level control of the queries being executed.
+
+In BLoCs, the basic functionalities - such as queries for messages, channels or queries - are bundled up
+and passed along down the tree. Using a BLoC allows you to either create your own way to fetch and
+build UIs or use an inbuilt Core widget to do the work such as queries, pagination, etc for you.
+
+The BLoCs we provide are:
+
+* ChannelsBloc
+* MessageSearchBloc
+* UsersBloc
+
+### Core Components
+
+Core components usually are an easy way to fetch data associated with Stream Chat.
+Core components use functions exposed by the respective BLoCs (for example the ChannelListCore uses the ChannelsBloc)
+and use the respective controllers for various operations. Unlike heavier components from the UI
+package, core components are decoupled from UI and they expose builders instead to help you build
+a fully custom interface.
+
+Data fetching can be controlled with the controllers of the respective core components.
+
+* ChannelListCore (Fetch a list of channels)
+* MessageListCore (Fetch a list of messages from a channel)
+* MessageSearchListCore (Fetch a list of search messages)
+* UserListCore (Fetch a list of users)
+* StreamChatCore (This is different from the other core components - it is a version of StreamChat decoupled from theme and initialisations.)
+
+### Core Controllers
+
+Core Controllers are supplied to respective CoreList widgets which allows reloading and pagination of data whenever needed.
+
+Unlike the UI package, the Core package allows a fully custom user interface built with the data. This
+in turn provides a few challenges: we do not know implicitly when to paginate your list or reload your data.
+
+While this is handled out of the box in the UI package since the List implementation is inbuilt, a controller
+needs to be used in the core package notifying the core components to reload or paginate the data existing
+currently. For this, each core component has a respective controller which you can use to call the
+specific function (reload / paginate) whenever such an event is triggered through / needed in your UI.
+
+* ChannelListController
+* MessageListController
+* MessageSearchListController
+* ChannelListController
+
+This section goes into the individual core package widgets and their functional use.
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/message_list_core.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_list_core.mdx
new file mode 100644
index 00000000..5fd5877a
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_list_core.mdx
@@ -0,0 +1,70 @@
+---
+id: message_list_core
+sidebar_position: 5
+title: MessageListCore
+---
+
+A Widget For Building A List Of Messages
+
+### Background
+
+The UI SDK of Stream Chat supplies a `MessageListView` class that builds a list of channels fetching
+according to the filters and sort order given. However, in some cases, implementing novel UI is necessary
+that cannot be done using the customization approaches given in the widget.
+
+To do this, we extracted the logic required for fetching channels into a 'Core' widget - a widget that
+fetches channels in the expected way via the usual params but does not supply any UI and instead
+exposes builders to build the UI in situations such as loading, empty data, errors, and on data received.
+
+### Basic Example
+
+`MessageListCore` is a simplified class that allows fetching a list of
+messages while exposing UI builders.
+
+This allows you to construct your own UI while not having to
+worry about the specific logic of fetching messages in a channel.
+
+A `MessageListController` is used to paginate data.
+
+```dart
+class ChannelPage extends StatelessWidget {
+ const ChannelPage({
+ Key key,
+ }) : super(key: key);
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: Column(
+ children: [
+ Expanded(
+ child: MessageListCore(
+ emptyBuilder: (context) {
+ return Center(
+ child: Text('Nothing here...'),
+ );
+ },
+ loadingBuilder: (context) {
+ return Center(
+ child: CircularProgressIndicator(),
+ );
+ },
+ messageListBuilder: (context, list) {
+ return MessagesPage(list);
+ },
+ errorWidgetBuilder: (context, err) {
+ return Center(
+ child: Text('Error'),
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+```
+
+Make sure to have a `StreamChannel` ancestor in order to provide the
+information about the channels.
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_bloc.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_bloc.mdx
new file mode 100644
index 00000000..15f5a6d6
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_bloc.mdx
@@ -0,0 +1,40 @@
+---
+id: message_search_list_block
+sidebar_position: 8
+title: MessageSearchListBloc
+---
+
+A Widget Used To Manage A List Of Messages With Pagination.
+
+### Background
+
+Most widgets in the Core SDK are focused on fetching a particular type of object from Stream Chat - channels,
+messages, users etc. The BLoC widgets bundle up the base functions used to fetch data as well as the current
+data fetched by the respective functions. Furthermore, the Core widgets use this BLoC to fetch new or
+existing data and build UI based on it.
+
+All Core and UI widgets which focus on fetching a list of objects need to have their respective functions
+above them in the widget tree. The MessageSearchListCore and MessageSearchListView require the
+MessageSearchListCore above them in the widget hierarchy without which they will fail.
+
+### Understanding The Widget
+
+This class can be used to load messages, perform queries, etc.
+
+`MessageSearchBloc` can be accessed at anytime by using the static `.of` method
+using Flutter's BuildContext.
+
+```dart
+var _searchBloc = MessageSearchBloc.of(context);
+```
+
+The `MessageSearchBloc` widget encapsulates common functionality related to searching for messages
+across channels and also supplies them down the widget tree.
+
+Here is a basic implementation of `ChannelsBloc`:
+
+```dart
+MessageSearchBloc(
+ child: // Further Widget Tree
+),
+```
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_list_core.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_list_core.mdx
new file mode 100644
index 00000000..70cc026f
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/message_search_list_core.mdx
@@ -0,0 +1,41 @@
+---
+id: message_search_list_core
+sidebar_position: 6
+title: MessageSearchListCore
+---
+
+A Widget For Displaying Message Searches
+
+### Background
+
+The UI SDK of Stream Chat supplies a `MessageSearchListView` class that builds a list of channels fetching
+according to the filters and sort order given. However, in some cases, implementing novel UI is necessary
+that cannot be done using the customization approaches given in the widget.
+
+To do this, we extracted the logic required for fetching channels into a 'Core' widget - a widget that
+fetches channels in the expected way via the usual params but does not supply any UI and instead
+exposes builders to build the UI in situations such as loading, empty data, errors, and on data received.
+
+### Basic Example
+
+`MessageSearchListCore` is a simplified class that allows searching for
+ messages across channels while exposing UI builders.
+ A `MessageSearchListController` is used to load and paginate data.
+
+```dart
+class MessageSearchPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: MessageSearchListCore(
+ messageQuery: _messageFilter,
+ filters: _channelsFilter,
+ paginationParams: PaginationParams(limit: 20),
+ ),
+ );
+ }
+}
+```
+
+Make sure to have a `MessageSearchBloc` ancestor in order to provide the
+information about the messages.
\ No newline at end of file
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/setup.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/setup.mdx
new file mode 100644
index 00000000..15b15a56
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/setup.mdx
@@ -0,0 +1,28 @@
+---
+id: setup
+sidebar_position: 2
+title: Setup
+---
+
+Understanding Setup For `stream_chat_flutter_core`
+
+### Add pub.dev dependency
+
+First, you need to add the `stream_chat_flutter_core` dependency to your pubspec.yaml
+
+You can either run this command:
+
+```shell
+flutter pub add stream_chat_flutter_core
+```
+
+OR
+
+Add this line in the dependencies section of your pubspec.yaml after substituting latest version:
+
+```yaml
+dependencies:
+ stream_chat_flutter_core: ^latest_version
+```
+
+You can find the package details on [pub.dev](https://pub.dev/packages/stream_chat_flutter_core).
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/stream_chat_core.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/stream_chat_core.mdx
new file mode 100644
index 00000000..2a43ae52
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/stream_chat_core.mdx
@@ -0,0 +1,26 @@
+---
+id: stream_chat_core
+sidebar_position: 3
+title: StreamChatCore
+---
+
+`StreamChatCore` is a version of `StreamChat` found in `stream_chat_flutter` that is decoupled from
+theme and initialisations.
+
+`StreamChatCore` is used to provide information about the chat client to the widget tree.
+This Widget is used to react to life cycle changes and system updates.
+When the app goes into the background, the websocket connection is automatically closed and when it goes back to foreground the connection is opened again.
+
+Like the `StreamChat` widget in the higher level UI package, the `StreamChatCore` widget should
+be on the top level before using any Stream functionality:
+
+```dart
+return MaterialApp(
+ title: 'Stream Chat Core Example',
+ home: HomeScreen(),
+ builder: (context, child) => StreamChatCore(
+ client: client,
+ child: child!,
+ ),
+ );
+```
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/user_list_core.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/user_list_core.mdx
new file mode 100644
index 00000000..622d0025
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/user_list_core.mdx
@@ -0,0 +1,64 @@
+---
+id: user_list_core
+sidebar_position: 10
+title: UserListCore
+---
+
+A Widget For Building A List Of Users
+
+### Background
+
+The UI SDK of Stream Chat supplies a `UserListView` class that builds a list of channels fetching
+according to the filters and sort order given. However, in some cases, implementing novel UI is necessary
+that cannot be done using the customization approaches given in the widget.
+
+To do this, we extracted the logic required for fetching channels into a 'Core' widget - a widget that
+fetches channels in the expected way via the usual params but does not supply any UI and instead
+exposes builders to build the UI in situations such as loading, empty data, errors, and on data received.
+
+### Basic Example
+
+`UserListCore` is a simplified class that allows fetching users while
+exposing UI builders.
+A `UserListController` is used to load and paginate data.
+
+```dart
+class UsersListPage extends StatelessWidget {
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: UsersListCore(
+ sort: [SortOption('last_active')],
+ pagination: PaginationParams(
+ limit: 20,
+ ),
+ errorBuilder: (err) {
+ return Center(
+ child: Text('An error has occured'),
+ );
+ },
+ emptyBuilder: (context) {
+ return Center(
+ child: Text('Nothing here...'),
+ );
+ },
+ emptyBuilder: (context) {
+ return Center(
+ child: CircularProgressIndicator(),
+ );
+ },
+ listBuilder: (context, list) {
+ return UsersPage(list);
+ }
+ ),
+ );
+ }
+}
+```
+
+`UsersBloc` must be the ancestor of this widget. This is necessary since
+`UserListCore` depends on functionality contained within `UsersBloc`.
+
+The parameters `listBuilder`, `loadingBuilder`, `emptyBuilder` and
+`errorBuilder` must all be supplied and not null.
+
diff --git a/docusaurus/docs/Flutter/stream_chat_flutter_core/users_bloc.mdx b/docusaurus/docs/Flutter/stream_chat_flutter_core/users_bloc.mdx
new file mode 100644
index 00000000..61463599
--- /dev/null
+++ b/docusaurus/docs/Flutter/stream_chat_flutter_core/users_bloc.mdx
@@ -0,0 +1,37 @@
+---
+id: users_bloc
+sidebar_position: 9
+title: UsersBloc
+---
+
+A Widget Dedicated To The Management Of A Users List With Pagination.
+
+### Background
+
+Most widgets in the Core SDK are focused on fetching a particular type of object from Stream Chat - channels,
+messages, users, etc. The BLoC widgets bundle up the base functions used to fetch data as well as the current
+data fetched by the respective functions. Furthermore, the Core widgets use this BLoC to fetch new or
+existing data and build UI based on it.
+
+All Core and UI widgets which focus on fetching a list of objects need to have their respective functions
+above them in the widget tree. The UserListCore and UserListView require the UserListCore
+above them in the widget hierarchy without which they will fail.
+
+### Understanding The Widget
+
+`UsersBloc` can be accessed at anytime by using the static `.of` method
+using Flutter's `BuildContext`.
+
+```dart
+var _userBloc_ = UsersBloc.of(context);
+```
+
+The `UsersBloc` widget encapsulates common functionality related to user lists and also supplies them down the widget tree.
+
+Here is a basic implementation of `UsersBloc`:
+
+```dart
+UsersBloc(
+ child: // Further Widget Tree
+),
+```
\ No newline at end of file
diff --git a/melos.yaml b/melos.yaml
index 6a6c74dc..6232c3fa 100644
--- a/melos.yaml
+++ b/melos.yaml
@@ -1,4 +1,4 @@
-name: stream_chat_dart
+name: stream_chat_flutter
versioning:
mode: independent
@@ -7,57 +7,68 @@ packages:
- packages/**
scripts:
+ lint:all:
+ run: melos run analyze && melos run format
+ description: Run all static analysis checks
- # - Requires `pub global activate tuneup`.
- analyze: >
- melos exec -c 1 --fail-fast -- \
- pub global run tuneup check
+ analyze:
+ run: |
+ melos exec -c 4 --ignore="*example*" -- \
+ dart analyze --fatal-infos .
+ description: |
+ Run `dart analyze` in all packages.
+ - Note: you can also rely on your IDEs Dart Analysis / Issues window.
- format: pub global run flutter_plugin_tools format
+ format:
+ run: flutter format --set-exit-if-changed .
+ description: |
+ Run `flutter format --set-exit-if-changed .` in all packages.
+ lint:pub:
+ run: |
+ melos exec -c 4 --no-private --ignore="*example*" -- \
+ pub publish --dry-run
+ description: |
+ Run `pub publish --dry-run` in all packages.
+ - Note: you can also rely on your IDEs Dart Analysis / Issues window.
- build:examples:ios: >
- melos exec -c 1 --scope="*example*" --fail-fast -- \
- flutter build ios --no-codesign
+ generate:all:
+ run: melos run generate:dart && melos run generate:flutter
+ description: Build all generated files for Dart & Flutter packages in this project.
+ generate:dart:
+ run: melos exec -c 1 --depends-on="build_runner" --no-flutter -- "dart run build_runner build --delete-conflicting-outputs"
+ description: Build all generated files for Dart packages in this project.
- build:examples:android: >
- melos exec -c 1 --scope="*example*" --fail-fast -- \
- flutter build apk
+ generate:flutter:
+ run: melos exec -c 1 --depends-on="build_runner" --flutter -- "flutter pub run build_runner build --delete-conflicting-outputs"
+ description: Build all generated files for Flutter packages in this project.
- # Build any plugin example apps that have MacOS support.
- # - Requires `flutter config --enable-macos-desktop` enabled.
- # - Requires `flutter channel master && flutter upgrade`.
- build:examples:macos: >
- melos exec -c 1 --scope="*example*" --dir-exists=macos --fail-fast -- \
- flutter build macos
+ test:all:
+ run: melos run test:dart --no-select && melos run test:flutter --no-select
+ description: Run all Dart & Flutter tests in this project.
+ test:dart:
+ run: melos exec -c 1 --fail-fast -- "flutter test --coverage"
+ description: Run Dart tests for a specific package in this project.
+ select-package:
+ flutter: false
+ dir-exists: test
- test:dart: >
- melos exec -c 1 --fail-fast --no-flutter --dir-exists=test --ignore="*example*" --ignore="*web*" -- \
- flutter pub run test
+ test:flutter:
+ run: melos exec -c 3 --fail-fast -- "flutter test --coverage"
+ description: Run Flutter tests for a specific package in this project.
+ select-package:
+ flutter: true
+ dir-exists: test
- test:flutter: >
- melos exec -c 1 --fail-fast --flutter --dir-exists=test --ignore="*example*" --ignore="*web*" -- \
- flutter test
-
- test:web: >
- melos exec -c 1 --fail-fast --dir-exists=test --scope="*web*" -- \
- flutter test --platform=chrome
-
-
- lint:pub: >
- melos exec -c 5 --fail-fast --no-private --ignore="*example*" -- \
- pub publish --dry-run
-
-
- postclean: >
- melos exec -- \
- rm -rf ./build ./android/.gradle ./ios/.symlinks ./ios/Pods ./android/.idea ./.idea ./.dart-tool/build
-
-dev_dependencies:
- pedantic: 1.9.2
+ coverage:ignore-file:
+ run: |
+ melos exec -c 4 --fail-fast -- "\$MELOS_ROOT_PATH/.github/workflows/scripts/remove-from-coverage.sh"
+ description: Removes all the ignored files from the coverage report.
+ select-package:
+ dir-exists: coverage
environment:
- sdk: ">=2.7.0 <3.0.0"
- flutter: ">=1.22.4 <2.0.0"
\ No newline at end of file
+ sdk: '>=2.12.0 <3.0.0'
+ flutter: '>=1.22.4 <2.0.0'
\ No newline at end of file
diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md
index d6d08a3c..e05599e1 100644
--- a/packages/stream_chat/CHANGELOG.md
+++ b/packages/stream_chat/CHANGELOG.md
@@ -1,3 +1,100 @@
+## 2.0.0
+
+🛑️ Breaking Changes from `1.5.3`
+
+- migrate this package to null safety
+- `ConnectUserWithProvider` now requires `tokenProvider` as a required param. (Removed from the constructor)
+- `client.disconnect()` is now divided into two different functions
+ - `client.closeConnection()` -> for closing user websocket connection.
+ - `client.disconnectUser()` -> for disconnecting user and resetting client state.
+- `client.devToken()` now returns a `Token` model instead of `String`.
+- `ApiError` is removed in favor of `StreamChatError`
+ - `StreamChatError` -> parent type for all the stream errors.
+ - `StreamWebSocketError` -> for user websocket related errors.
+ - `StreamChatNetworkError` -> for network related errors.
+- `client.queryChannels()`, `channel.query()` options param is removed in favor of individual params
+ - `option.state` -> bool state
+ - `option.watch` -> bool watch
+ - `option.presence` -> bool presence
+- `client.queryUsers()` options param is removed in favor of individual params
+ - `option.presence` -> bool presence
+- Migrate this package to null safety
+- Added typed filters
+
+🐞 Fixed
+
+- [#369](https://github.com/GetStream/stream-chat-flutter/issues/369): Client does not return without internet connection
+- several minor fixes
+- performance improvements
+
+
+✅ Added
+
+- New `Location` enum is introduced for easily changing the client location/baseUrl.
+- New `client.openConnection()` and `client.closeConnection()` is introduced to connect/disconnect user ws connection.
+- New `client.partialUpdateMessage` and `channel.partialUpdateMessage` methods
+- `connectWebSocket` parameter in connect user calls to use the client in "connection-less" mode.
+
+🔄 Changed
+
+- `baseURL` is now deprecated in favor of using `Location` to change data location.
+
+## 2.0.0-nullsafety.8
+
+🐞 Fixed
+- Export `PushProvider` enum
+
+## 2.0.0-nullsafety.7
+
+🛑️ Breaking Changes from `2.0.0-nullsafety.6`
+
+- `ConnectUserWithProvider` now requires `tokenProvider` as a required param. (Removed from the constructor)
+- `client.disconnect()` is now divided into two different functions
+ - `client.closeConnection()` -> for closing user websocket connection.
+ - `client.disconnectUser()` -> for disconnecting user and resetting client state.
+- `client.devToken()` now returns a `Token` model instead of `String`.
+- `ApiError` is removed in favor of `StreamChatError`
+ - `StreamChatError` -> parent type for all the stream errors.
+ - `StreamWebSocketError` -> for user websocket related errors.
+ - `StreamChatNetworkError` -> for network related errors.
+- `client.queryChannels()`, `channel.query()` options param is removed in favor of individual params
+ - `option.state` -> bool state
+ - `option.watch` -> bool watch
+ - `option.presence` -> bool presence
+- `client.queryUsers()` options param is removed in favor of individual params
+ - `option.presence` -> bool presence
+
+✅ Added
+
+- New `Location` enum is introduced for easily changing the client location/baseUrl.
+- New `client.openConnection()` and `client.closeConnection()` is introduced to connect/disconnect user ws connection.
+
+🔄 Changed
+
+- `baseURL` is now deprecated in favor of using `Location` to change data location.
+
+## 2.0.0-nullsafety.6
+
+- Fix thread reply not working with attachments
+- Minor fixes
+## 2.0.0-nullsafety.5
+
+- Minor fixes
+- Performance improvements
+- Fixed `skip_push` in `client.sendMessage`
+- Added partial message update method
+
+## 2.0.0-nullsafety.2
+
+- Added new `Filter.raw` constructor
+- Changed extraData
+- Minor fixes
+
+## 2.0.0-nullsafety.1
+
+- Migrate this package to null safety
+- Added typed filters
+
## 1.5.3
- fix: `StreamChatClient.connect` returns quicker when you're using the persistence package
@@ -34,7 +131,8 @@
- Save pinned messages in offline storage
- Minor fixes
- `StreamClient.QueryChannels` now returns a Stream and fetches the channels from storage before calling the api
-- Added `StreamClient.QueryChannelsOnline` and `StreamClient.QueryChannelsOffline` to fetch channels only from online or offline
+- Added `StreamClient.QueryChannelsOnline` and `StreamClient.QueryChannelsOffline` to fetch channels only from online or
+ offline
## 1.2.0-beta
@@ -45,7 +143,8 @@
## 1.1.0-beta
- Fixed minor bugs
-- Add support for custom attachment upload [docs here](https://getstream.io/chat/docs/flutter-dart/file_uploads/?language=dart)
+- Add support for custom attachment
+ upload [docs here](https://getstream.io/chat/docs/flutter-dart/file_uploads/?language=dart)
- Add support for asynchronous attachment upload
## 1.0.3-beta
@@ -55,7 +154,8 @@
## 1.0.2-beta
-- Deprecated `setUser`, `setGuestUser`, `setUserWithProvider` in favor of `connectUser`, `connectGuestUser`, `connectUserWithProvider`
+- Deprecated `setUser`, `setGuestUser`, `setUserWithProvider` in favor of `connectUser`, `connectGuestUser`
+ , `connectUserWithProvider`
- Optimised reaction updates - i.e., Update first call Api later.
## 1.0.1-beta
@@ -65,9 +165,11 @@
## 1.0.0-beta
- 🛑 **BREAKING** Renamed `Client` to less generic `StreamChatClient`
-- 🛑 **BREAKING** Segregated the persistence layer into separate package [stream_chat_persistence](https://pub.dev/packages/stream_chat_persistence)
+- 🛑 **BREAKING** Segregated the persistence layer into separate
+ package [stream_chat_persistence](https://pub.dev/packages/stream_chat_persistence)
- 🛑 **BREAKING** Moved `Client.backgroundKeepAlive` to [core package](https://pub.dev/packages/stream_chat_core)
-- 🛑 **BREAKING** Moved `Client.showLocalNotification` to [core package](https://pub.dev/packages/stream_chat_core) and renamed it to `StreamChatCore.onBackgroundEventReceived`
+- 🛑 **BREAKING** Moved `Client.showLocalNotification` to [core package](https://pub.dev/packages/stream_chat_core) and
+ renamed it to `StreamChatCore.onBackgroundEventReceived`
- Removed `flutter` dependency. This is now a pure Dart package 🥳
- Minor improvements and bugfixes
@@ -122,7 +224,8 @@
## 0.2.20
-- Return offline data only if the backend is unreachable. This avoids the glitch of the ChannelListView because we cannot sort by custom properties.
+- Return offline data only if the backend is unreachable. This avoids the glitch of the ChannelListView because we
+ cannot sort by custom properties.
## 0.2.19
@@ -136,7 +239,7 @@
## 0.2.17+1
-- Do not retry messages when server returns error
+- Do not retry messages when server returns error
## 0.2.17
diff --git a/packages/stream_chat/analysis_options.yaml b/packages/stream_chat/analysis_options.yaml
deleted file mode 100644
index ddc691d0..00000000
--- a/packages/stream_chat/analysis_options.yaml
+++ /dev/null
@@ -1,144 +0,0 @@
-analyzer:
- exclude:
- - lib/**/*.g.dart
- - lib/**/*.freezed.dart
- - example/*
- - test/*
-linter:
- rules:
- - always_use_package_imports
- - avoid_empty_else
- - avoid_relative_lib_imports
- - avoid_slow_async_io
- - avoid_types_as_parameter_names
- - cancel_subscriptions
- - close_sinks
- - control_flow_in_finally
- - empty_statements
- - hash_and_equals
- - invariant_booleans
- - iterable_contains_unrelated_type
- - list_remove_unrelated_type
- - literal_only_boolean_expressions
- - no_adjacent_strings_in_list
- - no_duplicate_case_values
- - no_logic_in_create_state
- - prefer_void_to_null
- - test_types_in_equals
- - throw_in_finally
- - unnecessary_statements
- - unrelated_type_equality_checks
- - omit_local_variable_types
- - use_key_in_widget_constructors
- - valid_regexps
- - always_declare_return_types
- - always_require_non_null_named_parameters
- - annotate_overrides
- - avoid_bool_literals_in_conditional_expressions
- - avoid_catching_errors
- - avoid_init_to_null
- - avoid_null_checks_in_equality_operators
- - avoid_positional_boolean_parameters
- - avoid_private_typedef_functions
- - avoid_redundant_argument_values
- - avoid_return_types_on_setters
- - avoid_returning_null_for_void
- - avoid_shadowing_type_parameters
- - avoid_single_cascade_in_expression_statements
- - avoid_unnecessary_containers
- - avoid_unused_constructor_parameters
- - await_only_futures
- - camel_case_extensions
- - camel_case_types
- - cascade_invocations
-
- - constant_identifier_names
- - curly_braces_in_flow_control_structures
- - directives_ordering
- - empty_catches
- - empty_constructor_bodies
- - exhaustive_cases
- - file_names
- - implementation_imports
- - join_return_with_assignment
- - leading_newlines_in_multiline_strings
- - library_names
- - library_prefixes
- - lines_longer_than_80_chars
- - missing_whitespace_between_adjacent_strings
- - non_constant_identifier_names
- - null_closures
- - one_member_abstracts
- - only_throw_errors
- - package_api_docs
- - package_prefixed_library_names
- - parameter_assignments
- - prefer_adjacent_string_concatenation
- - prefer_asserts_in_initializer_lists
- - prefer_asserts_with_message
- - prefer_collection_literals
- - prefer_conditional_assignment
- - prefer_const_constructors
- - prefer_const_constructors_in_immutables
- - prefer_const_declarations
- - prefer_const_literals_to_create_immutables
- - prefer_constructors_over_static_methods
- - prefer_contains
- - prefer_equal_for_default_values
- - prefer_expression_function_bodies
- - prefer_final_fields
- - prefer_final_in_for_each
- - prefer_final_locals
- - prefer_function_declarations_over_variables
- - prefer_generic_function_type_aliases
- - prefer_if_elements_to_conditional_expressions
- - prefer_if_null_operators
- - prefer_initializing_formals
- - prefer_inlined_adds
- - prefer_int_literals
- - prefer_interpolation_to_compose_strings
- - prefer_is_empty
- - prefer_is_not_empty
- - prefer_is_not_operator
- - prefer_null_aware_operators
- - prefer_single_quotes
- - prefer_spread_collections
- - prefer_typing_uninitialized_variables
- - provide_deprecation_message
- - public_member_api_docs
- - recursive_getters
- - sized_box_for_whitespace
- - slash_for_doc_comments
- - sort_child_properties_last
- - sort_constructors_first
- - sort_unnamed_constructors_first
-
- - type_annotate_public_apis
- - type_init_formals
- - unnecessary_await_in_return
- - unnecessary_brace_in_string_interps
- - unnecessary_const
- - unnecessary_getters_setters
- - unnecessary_lambdas
- - unnecessary_new
- - unnecessary_null_aware_assignments
- - unnecessary_null_in_if_null_operators
- - unnecessary_nullable_for_final_variable_declarations
- - unnecessary_parenthesis
- - unnecessary_raw_strings
- - unnecessary_string_escapes
- - unnecessary_string_interpolations
- - unnecessary_this
- - use_is_even_rather_than_modulo
- - use_late_for_private_fields_and_variables
- - use_rethrow_when_possible
- - use_setters_to_change_properties
- - use_to_and_as_if_applicable
- - package_names
- - sort_pub_dependencies
-
- # To be added when null-safe:
- # - cast_nullable_to_non_nullable
- #- unnecessary_null_checks
- # - tighten_type_of_initializing_formals
- # - null_check_on_nullable_type_parameter
\ No newline at end of file
diff --git a/packages/stream_chat/build.yaml b/packages/stream_chat/build.yaml
index ddbd70dd..d439bddb 100644
--- a/packages/stream_chat/build.yaml
+++ b/packages/stream_chat/build.yaml
@@ -4,5 +4,4 @@ targets:
json_serializable:
options:
explicit_to_json: true
- field_rename: snake
- any_map: true
+ field_rename: snake
\ No newline at end of file
diff --git a/packages/stream_chat/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/stream_chat/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
index 1d526a16..919434a6 100644
--- a/packages/stream_chat/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+++ b/packages/stream_chat/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -2,6 +2,6 @@
+ location = "self:">
diff --git a/packages/stream_chat/example/lib/main.dart b/packages/stream_chat/example/lib/main.dart
index 2d0a529f..167f5f6b 100644
--- a/packages/stream_chat/example/lib/main.dart
+++ b/packages/stream_chat/example/lib/main.dart
@@ -2,12 +2,9 @@ import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
Future main() async {
- /// Create a new instance of [StreamChatClient] passing the apikey obtained from your
- /// project dashboard.
- final client = StreamChatClient(
- 'b67pax5b2wdq',
- logLevel: Level.INFO,
- );
+ /// Create a new instance of [StreamChatClient]
+ /// by passing the apikey obtained from your project dashboard.
+ final client = StreamChatClient('b67pax5b2wdq', logLevel: Level.INFO);
/// Set the current user. In a production scenario, this should be done using
/// a backend to generate a user token using our server SDK.
@@ -16,12 +13,12 @@ Future main() async {
await client.connectUser(
User(
id: 'cool-shadow-7',
- extraData: {
+ extraData: const {
'image':
'https://getstream.io/random_png/?id=cool-shadow-7&name=Cool+shadow',
},
),
- 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo',
+ '''eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo''',
);
/// Creates a channel using the type `messaging` and `godevs`.
@@ -44,55 +41,57 @@ Future main() async {
/// Example using Stream's Low Level Dart client.
class StreamExample extends StatelessWidget {
- /// To initialize this example, an instance of [client] and [channel] is required.
+ /// To initialize this example, an instance of
+ /// [client] and [channel] is required.
const StreamExample({
- Key key,
- @required this.client,
- @required this.channel,
+ Key? key,
+ required this.client,
+ required this.channel,
}) : super(key: key);
- /// Instance of [StreamChatClient] we created earlier. This contains information about
- /// our application and connection state.
+ /// Instance of [StreamChatClient] we created earlier.
+ /// This contains information about our application and connection state.
final StreamChatClient client;
/// The channel we'd like to observe and participate.
final Channel channel;
@override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Stream Chat Dart Example',
- home: HomeScreen(channel: channel),
- );
- }
+ Widget build(BuildContext context) => MaterialApp(
+ title: 'Stream Chat Dart Example',
+ home: HomeScreen(channel: channel),
+ );
}
/// Main screen of our application. The layout is comprised of an [AppBar]
/// containing the channel name and a [MessageView] displaying recent messages.
class HomeScreen extends StatelessWidget {
/// [HomeScreen] is constructed using the [Channel] we defined earlier.
- const HomeScreen({Key key, @required this.channel}) : super(key: key);
+ const HomeScreen({
+ Key? key,
+ required this.channel,
+ }) : super(key: key);
/// Channel object containing the [Channel.id] we'd like to observe.
final Channel channel;
@override
Widget build(BuildContext context) {
- final messages = channel.state.channelStateStream;
+ final messages = channel.state!.messagesStream;
return Scaffold(
appBar: AppBar(
title: Text('Channel: ${channel.id}'),
),
body: SafeArea(
- child: StreamBuilder(
+ child: StreamBuilder?>(
stream: messages,
builder: (
BuildContext context,
- AsyncSnapshot snapshot,
+ AsyncSnapshot?> snapshot,
) {
if (snapshot.hasData && snapshot.data != null) {
return MessageView(
- messages: snapshot.data.messages.reversed.toList(),
+ messages: snapshot.data!.reversed.toList(),
channel: channel,
);
} else if (snapshot.hasError) {
@@ -104,8 +103,8 @@ class HomeScreen extends StatelessWidget {
}
return const Center(
child: SizedBox(
- width: 100.0,
- height: 100.0,
+ width: 100,
+ height: 100,
child: CircularProgressIndicator(),
),
);
@@ -121,9 +120,9 @@ class HomeScreen extends StatelessWidget {
class MessageView extends StatefulWidget {
/// Message takes the latest list of messages and the current channel.
const MessageView({
- Key key,
- @required this.messages,
- @required this.channel,
+ Key? key,
+ required this.messages,
+ required this.channel,
}) : super(key: key);
/// List of messages sent in the given channel.
@@ -137,8 +136,8 @@ class MessageView extends StatefulWidget {
}
class _MessageViewState extends State {
- TextEditingController _controller;
- ScrollController _scrollController;
+ late final TextEditingController _controller;
+ late final ScrollController _scrollController;
List get _messages => widget.messages;
@@ -166,86 +165,85 @@ class _MessageViewState extends State {
}
@override
- Widget build(BuildContext context) {
- return Column(
- children: [
- Expanded(
- child: ListView.builder(
- controller: _scrollController,
- itemCount: _messages.length,
- reverse: true,
- itemBuilder: (BuildContext context, int index) {
- final item = _messages[index];
- if (item.user.id == widget.channel.client.uid) {
- return Align(
- alignment: Alignment.centerRight,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(item.text),
- ),
- );
- } else {
- return Align(
- alignment: Alignment.centerLeft,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(item.text),
- ),
- );
- }
- },
+ Widget build(BuildContext context) => Column(
+ children: [
+ Expanded(
+ child: ListView.builder(
+ controller: _scrollController,
+ itemCount: _messages.length,
+ reverse: true,
+ itemBuilder: (BuildContext context, int index) {
+ final item = _messages[index];
+ if (item.user?.id == widget.channel.client.uid) {
+ return Align(
+ alignment: Alignment.centerRight,
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Text(item.text ?? ''),
+ ),
+ );
+ } else {
+ return Align(
+ alignment: Alignment.centerLeft,
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: Text(item.text ?? ''),
+ ),
+ );
+ }
+ },
+ ),
),
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- children: [
- Expanded(
- child: TextField(
- controller: _controller,
- decoration: const InputDecoration(
- hintText: 'Enter your message',
- ),
- ),
- ),
- Material(
- type: MaterialType.circle,
- color: Colors.blue,
- clipBehavior: Clip.hardEdge,
- child: InkWell(
- onTap: () async {
- // We can send a new message by calling `sendMessage` on
- // the current channel. After sending a message, the
- // TextField is cleared and the list view is scrolled
- // to show the new item.
- if (_controller.value.text.isNotEmpty) {
- await widget.channel.sendMessage(
- Message(text: _controller.value.text),
- );
- _controller.clear();
- _updateList();
- }
- },
- child: const Padding(
- padding: EdgeInsets.all(8.0),
- child: Center(
- child: Icon(
- Icons.send,
- color: Colors.white,
- ),
+ Padding(
+ padding: const EdgeInsets.all(8),
+ child: Row(
+ children: [
+ Expanded(
+ child: TextField(
+ controller: _controller,
+ decoration: const InputDecoration(
+ hintText: 'Enter your message',
),
),
),
- )
- ],
- ),
- )
- ],
- );
- }
+ Material(
+ type: MaterialType.circle,
+ color: Colors.blue,
+ clipBehavior: Clip.hardEdge,
+ child: InkWell(
+ onTap: () async {
+ // We can send a new message by calling `sendMessage` on
+ // the current channel. After sending a message, the
+ // TextField is cleared and the list view is scrolled
+ // to show the new item.
+ if (_controller.value.text.isNotEmpty) {
+ await widget.channel.sendMessage(
+ Message(text: _controller.value.text),
+ );
+ _controller.clear();
+ _updateList();
+ }
+ },
+ child: const Padding(
+ padding: EdgeInsets.all(8),
+ child: Center(
+ child: Icon(
+ Icons.send,
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ),
+ )
+ ],
+ ),
+ )
+ ],
+ );
}
-/// Helper extension for quickly retrieving the current user id from a [StreamChatClient].
+/// Helper extension for quickly retrieving
+/// the current user id from a [StreamChatClient].
extension on StreamChatClient {
- String get uid => state.user.id;
+ String get uid => state.user!.id;
}
diff --git a/packages/stream_chat/example/pubspec.yaml b/packages/stream_chat/example/pubspec.yaml
index 2a8b7eb2..1b092b3e 100644
--- a/packages/stream_chat/example/pubspec.yaml
+++ b/packages/stream_chat/example/pubspec.yaml
@@ -1,21 +1,22 @@
name: example
description: A new Flutter project.
-publish_to: 'none'
+publish_to: "none"
version: 1.0.0+1
environment:
- sdk: ">=2.7.0 <3.0.0"
+ sdk: '>=2.12.0 <3.0.0'
dependencies:
+ cupertino_icons: ^1.0.0
flutter:
sdk: flutter
- cupertino_icons: ^1.0.0
- stream_chat:
+ stream_chat:
path: ../
dev_dependencies:
flutter_test:
sdk: flutter
+
flutter:
- uses-material-design: true
\ No newline at end of file
+ uses-material-design: true
diff --git a/packages/stream_chat/lib/src/api/responses.g.dart b/packages/stream_chat/lib/src/api/responses.g.dart
deleted file mode 100644
index 1f290d6e..00000000
--- a/packages/stream_chat/lib/src/api/responses.g.dart
+++ /dev/null
@@ -1,399 +0,0 @@
-// GENERATED CODE - DO NOT MODIFY BY HAND
-
-part of 'responses.dart';
-
-// **************************************************************************
-// JsonSerializableGenerator
-// **************************************************************************
-
-SyncResponse _$SyncResponseFromJson(Map json) {
- return SyncResponse()
- ..duration = json['duration'] as String
- ..events = (json['events'] as List)
- ?.map((e) => e == null
- ? null
- : Event.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-QueryChannelsResponse _$QueryChannelsResponseFromJson(Map json) {
- return QueryChannelsResponse()
- ..duration = json['duration'] as String
- ..channels = (json['channels'] as List)
- ?.map((e) => e == null ? null : ChannelState.fromJson(e as Map))
- ?.toList();
-}
-
-TranslateMessageResponse _$TranslateMessageResponseFromJson(Map json) {
- return TranslateMessageResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : TranslatedMessage.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-QueryMembersResponse _$QueryMembersResponseFromJson(Map json) {
- return QueryMembersResponse()
- ..duration = json['duration'] as String
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-QueryUsersResponse _$QueryUsersResponseFromJson(Map json) {
- return QueryUsersResponse()
- ..duration = json['duration'] as String
- ..users = (json['users'] as List)
- ?.map((e) => e == null
- ? null
- : User.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-QueryReactionsResponse _$QueryReactionsResponseFromJson(Map json) {
- return QueryReactionsResponse()
- ..duration = json['duration'] as String
- ..reactions = (json['reactions'] as List)
- ?.map((e) => e == null
- ? null
- : Reaction.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-QueryRepliesResponse _$QueryRepliesResponseFromJson(Map json) {
- return QueryRepliesResponse()
- ..duration = json['duration'] as String
- ..messages = (json['messages'] as List)
- ?.map((e) => e == null
- ? null
- : Message.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-ListDevicesResponse _$ListDevicesResponseFromJson(Map json) {
- return ListDevicesResponse()
- ..duration = json['duration'] as String
- ..devices = (json['devices'] as List)
- ?.map((e) => e == null
- ? null
- : Device.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-SendFileResponse _$SendFileResponseFromJson(Map json) {
- return SendFileResponse()
- ..duration = json['duration'] as String
- ..file = json['file'] as String;
-}
-
-SendImageResponse _$SendImageResponseFromJson(Map json) {
- return SendImageResponse()
- ..duration = json['duration'] as String
- ..file = json['file'] as String;
-}
-
-SendReactionResponse _$SendReactionResponseFromJson(Map json) {
- return SendReactionResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..reaction = json['reaction'] == null
- ? null
- : Reaction.fromJson((json['reaction'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-ConnectGuestUserResponse _$ConnectGuestUserResponseFromJson(Map json) {
- return ConnectGuestUserResponse()
- ..duration = json['duration'] as String
- ..accessToken = json['access_token'] as String
- ..user = json['user'] == null
- ? null
- : User.fromJson((json['user'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-UpdateUsersResponse _$UpdateUsersResponseFromJson(Map json) {
- return UpdateUsersResponse()
- ..duration = json['duration'] as String
- ..users = (json['users'] as Map)?.map(
- (k, e) => MapEntry(
- k as String,
- e == null
- ? null
- : User.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))),
- );
-}
-
-UpdateMessageResponse _$UpdateMessageResponseFromJson(Map json) {
- return UpdateMessageResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-SendMessageResponse _$SendMessageResponseFromJson(Map json) {
- return SendMessageResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-GetMessageResponse _$GetMessageResponseFromJson(Map json) {
- return GetMessageResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-SearchMessagesResponse _$SearchMessagesResponseFromJson(Map json) {
- return SearchMessagesResponse()
- ..duration = json['duration'] as String
- ..results = (json['results'] as List)
- ?.map((e) => e == null ? null : GetMessageResponse.fromJson(e as Map))
- ?.toList();
-}
-
-GetMessagesByIdResponse _$GetMessagesByIdResponseFromJson(Map json) {
- return GetMessagesByIdResponse()
- ..duration = json['duration'] as String
- ..messages = (json['messages'] as List)
- ?.map((e) => e == null
- ? null
- : Message.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-UpdateChannelResponse _$UpdateChannelResponseFromJson(Map json) {
- return UpdateChannelResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-PartialUpdateChannelResponse _$PartialUpdateChannelResponseFromJson(Map json) {
- return PartialUpdateChannelResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
-
-InviteMembersResponse _$InviteMembersResponseFromJson(Map json) {
- return InviteMembersResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-RemoveMembersResponse _$RemoveMembersResponseFromJson(Map json) {
- return RemoveMembersResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-SendActionResponse _$SendActionResponseFromJson(Map json) {
- return SendActionResponse()
- ..duration = json['duration'] as String
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-AddMembersResponse _$AddMembersResponseFromJson(Map json) {
- return AddMembersResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-AcceptInviteResponse _$AcceptInviteResponseFromJson(Map json) {
- return AcceptInviteResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-RejectInviteResponse _$RejectInviteResponseFromJson(Map json) {
- return RejectInviteResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..message = json['message'] == null
- ? null
- : Message.fromJson((json['message'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ));
-}
-
-EmptyResponse _$EmptyResponseFromJson(Map json) {
- return EmptyResponse()..duration = json['duration'] as String;
-}
-
-ChannelStateResponse _$ChannelStateResponseFromJson(Map json) {
- return ChannelStateResponse()
- ..duration = json['duration'] as String
- ..channel = json['channel'] == null
- ? null
- : ChannelModel.fromJson((json['channel'] as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- ))
- ..messages = (json['messages'] as List)
- ?.map((e) => e == null
- ? null
- : Message.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..members = (json['members'] as List)
- ?.map((e) => e == null
- ? null
- : Member.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList()
- ..watcherCount = json['watcher_count'] as int
- ..read = (json['read'] as List)
- ?.map((e) => e == null
- ? null
- : Read.fromJson((e as Map)?.map(
- (k, e) => MapEntry(k as String, e),
- )))
- ?.toList();
-}
diff --git a/packages/stream_chat/lib/src/api/retry_policy.dart b/packages/stream_chat/lib/src/api/retry_policy.dart
deleted file mode 100644
index a4d1e7bd..00000000
--- a/packages/stream_chat/lib/src/api/retry_policy.dart
+++ /dev/null
@@ -1,39 +0,0 @@
-import 'package:meta/meta.dart';
-import 'package:stream_chat/src/client.dart';
-import 'package:stream_chat/src/exceptions.dart';
-
-/// The retry options
-class RetryPolicy {
- /// Instantiate a new RetryPolicy
- RetryPolicy({
- @required this.shouldRetry,
- @required this.retryTimeout,
- this.attempt,
- });
-
- /// The number of attempts tried so far
- int attempt = 0;
-
- /// This function evaluates if we should retry the failure
- final bool Function(StreamChatClient client, int attempt, ApiError apiError)
- shouldRetry;
-
- /// In the case that we want to retry a failed request the retryTimeout
- /// method is called to determine the timeout
- final Duration Function(
- StreamChatClient client, int attempt, ApiError apiError) retryTimeout;
-
- /// Creates a copy of [RetryPolicy] with specified attributes overridden.
- RetryPolicy copyWith({
- bool Function(StreamChatClient client, int attempt, ApiError apiError)
- shouldRetry,
- Duration Function(StreamChatClient client, int attempt, ApiError apiError)
- retryTimeout,
- int attempt,
- }) =>
- RetryPolicy(
- retryTimeout: retryTimeout ?? this.retryTimeout,
- shouldRetry: shouldRetry ?? this.shouldRetry,
- attempt: attempt ?? this.attempt,
- );
-}
diff --git a/packages/stream_chat/lib/src/api/retry_queue.dart b/packages/stream_chat/lib/src/api/retry_queue.dart
deleted file mode 100644
index ac0e14d7..00000000
--- a/packages/stream_chat/lib/src/api/retry_queue.dart
+++ /dev/null
@@ -1,194 +0,0 @@
-import 'dart:async';
-
-import 'package:collection/collection.dart';
-import 'package:logging/logging.dart';
-import 'package:meta/meta.dart';
-import 'package:stream_chat/src/api/channel.dart';
-import 'package:stream_chat/src/api/retry_policy.dart';
-import 'package:stream_chat/src/event_type.dart';
-import 'package:stream_chat/src/exceptions.dart';
-import 'package:stream_chat/src/models/message.dart';
-import 'package:stream_chat/stream_chat.dart';
-
-/// The retry queue associated to a channel
-class RetryQueue {
- /// Instantiate a new RetryQueue object
- RetryQueue({
- @required this.channel,
- this.logger,
- }) {
- _retryPolicy = channel.client.retryPolicy;
-
- _listenConnectionRecovered();
-
- _listenFailedEvents();
- }
-
- /// The channel of this queue
- final Channel channel;
-
- /// The logger associated to this queue
- final Logger logger;
-
- final _subscriptions = [];
-
- void _listenConnectionRecovered() {
- _subscriptions
- .add(channel.client.on(EventType.connectionRecovered).listen((event) {
- if (!_isRetrying && event.online) {
- _startRetrying();
- }
- }));
- }
-
- final HeapPriorityQueue _messageQueue = HeapPriorityQueue(_byDate);
- bool _isRetrying = false;
- RetryPolicy _retryPolicy;
-
- /// Add a list of messages
- void add(List messages) {
- logger?.info('added ${messages.length} messages');
- final messageList = _messageQueue.toList();
- _messageQueue.addAll(messages
- .where((element) => !messageList.any((m) => m.id == element.id)));
-
- if (_messageQueue.isNotEmpty && !_isRetrying) {
- _startRetrying();
- }
- }
-
- Future _startRetrying() async {
- logger?.info('start retrying');
- _isRetrying = true;
- final retryPolicy = _retryPolicy.copyWith(attempt: 0);
-
- while (_messageQueue.isNotEmpty) {
- final message = _messageQueue.first;
- try {
- logger?.info('retry attempt ${retryPolicy.attempt}');
- await _sendMessage(message);
- logger?.info('message sent - removing it from the queue');
- _messageQueue.remove(message);
- logger?.info('now ${_messageQueue.length} messages in the queue');
- retryPolicy.attempt = 0;
- } catch (error) {
- ApiError apiError;
- if (error is DioError) {
- if (error.type == DioErrorType.RESPONSE) {
- _messageQueue.remove(message);
- return;
- }
- apiError = ApiError(
- error.response?.data,
- error.response?.statusCode,
- );
- } else if (error is ApiError) {
- apiError = error;
- if (apiError.status?.toString()?.startsWith('4') == true) {
- _messageQueue.remove(message);
- return;
- }
- }
-
- if (!retryPolicy.shouldRetry(
- channel.client,
- retryPolicy.attempt,
- apiError,
- )) {
- _messageQueue.toList().forEach(_sendFailedEvent);
- _isRetrying = false;
- return;
- }
-
- retryPolicy.attempt++;
- final timeout = retryPolicy.retryTimeout(
- channel.client,
- retryPolicy.attempt,
- apiError,
- );
- await Future.delayed(timeout);
- }
- }
- _isRetrying = false;
- }
-
- void _sendFailedEvent(Message message) {
- final newStatus = message.status == MessageSendingStatus.sending
- ? MessageSendingStatus.failed
- : (message.status == MessageSendingStatus.updating
- ? MessageSendingStatus.failed_update
- : MessageSendingStatus.failed_delete);
- channel.state.addMessage(message.copyWith(
- status: newStatus,
- ));
- }
-
- Future _sendMessage(Message message) async {
- if (message.status == MessageSendingStatus.failed_update ||
- message.status == MessageSendingStatus.updating) {
- await channel.updateMessage(message);
- } else if (message.status == MessageSendingStatus.failed ||
- message.status == MessageSendingStatus.sending) {
- await channel.sendMessage(message);
- } else if (message.status == MessageSendingStatus.failed_delete ||
- message.status == MessageSendingStatus.deleting) {
- await channel.deleteMessage(message);
- }
- }
-
- void _listenFailedEvents() {
- _subscriptions.add(channel.on().listen((event) {
- final messageList = _messageQueue.toList();
- if (event.message != null) {
- final messageIndex =
- messageList.indexWhere((m) => m.id == event.message.id);
- if (messageIndex == -1 &&
- [
- MessageSendingStatus.failed_update,
- MessageSendingStatus.failed,
- MessageSendingStatus.failed_delete,
- ].contains(event.message.status)) {
- logger?.info('add message from events');
- add([event.message]);
- } else if (messageIndex != -1 &&
- [
- MessageSendingStatus.sent,
- null,
- ].contains(event.message.status)) {
- _messageQueue.remove(messageList[messageIndex]);
- }
- }
- }));
- }
-
- /// Call this method to dispose this object
- void dispose() {
- _messageQueue.clear();
- _subscriptions.forEach((s) => s.cancel());
- }
-
- static int _byDate(Message m1, Message m2) {
- final date1 = _getMessageDate(m1);
- final date2 = _getMessageDate(m2);
-
- return date1.compareTo(date2);
- }
-
- static DateTime _getMessageDate(Message m1) {
- switch (m1.status) {
- case MessageSendingStatus.failed_delete:
- case MessageSendingStatus.deleting:
- return m1.deletedAt;
-
- case MessageSendingStatus.failed:
- case MessageSendingStatus.sending:
- return m1.createdAt;
-
- case MessageSendingStatus.failed_update:
- case MessageSendingStatus.updating:
- return m1.updatedAt;
- default:
- return null;
- }
- }
-}
diff --git a/packages/stream_chat/lib/src/api/web_socket_channel_html.dart b/packages/stream_chat/lib/src/api/web_socket_channel_html.dart
deleted file mode 100644
index 9ddd83e5..00000000
--- a/packages/stream_chat/lib/src/api/web_socket_channel_html.dart
+++ /dev/null
@@ -1,7 +0,0 @@
-import 'package:web_socket_channel/html.dart';
-import 'package:web_socket_channel/web_socket_channel.dart';
-
-/// Html version of websocket implementation
-/// Used in Flutter web version
-WebSocketChannel connectWebSocket(String url, {Iterable protocols}) =>
- HtmlWebSocketChannel.connect(url, protocols: protocols);
diff --git a/packages/stream_chat/lib/src/api/web_socket_channel_io.dart b/packages/stream_chat/lib/src/api/web_socket_channel_io.dart
deleted file mode 100644
index ed37ba7f..00000000
--- a/packages/stream_chat/lib/src/api/web_socket_channel_io.dart
+++ /dev/null
@@ -1,7 +0,0 @@
-import 'package:web_socket_channel/io.dart';
-import 'package:web_socket_channel/web_socket_channel.dart';
-
-/// IO version of websocket implementation
-/// Used in Flutter mobile version
-WebSocketChannel connectWebSocket(String url, {Iterable protocols}) =>
- IOWebSocketChannel.connect(url, protocols: protocols);
diff --git a/packages/stream_chat/lib/src/api/web_socket_channel_stub.dart b/packages/stream_chat/lib/src/api/web_socket_channel_stub.dart
deleted file mode 100644
index 7e2e47bd..00000000
--- a/packages/stream_chat/lib/src/api/web_socket_channel_stub.dart
+++ /dev/null
@@ -1,9 +0,0 @@
-import 'package:web_socket_channel/web_socket_channel.dart';
-
-/// Stub version of websocket implementation
-/// Used just for conditional library import
-WebSocketChannel connectWebSocket(String url,
- {Iterable protocols,
- Map headers,
- Duration pingInterval}) =>
- throw UnimplementedError();
diff --git a/packages/stream_chat/lib/src/api/websocket.dart b/packages/stream_chat/lib/src/api/websocket.dart
deleted file mode 100644
index 0f78b1bf..00000000
--- a/packages/stream_chat/lib/src/api/websocket.dart
+++ /dev/null
@@ -1,323 +0,0 @@
-import 'dart:async';
-import 'dart:convert';
-import 'dart:math';
-
-import 'package:logging/logging.dart';
-import 'package:meta/meta.dart';
-import 'package:rxdart/rxdart.dart';
-import 'package:stream_chat/src/api/connection_status.dart';
-import 'package:stream_chat/src/models/event.dart';
-import 'package:stream_chat/src/models/user.dart';
-import 'package:web_socket_channel/web_socket_channel.dart';
-
-/// Typedef which exposes an [Event] as the only parameter.
-typedef EventHandler = void Function(Event);
-
-/// Typedef used for connecting to a websocket. Method returns a
-/// [WebSocketChannel] and accepts a connection [url] and an optional
-/// [Iterable] of `protocols`.
-typedef ConnectWebSocket = WebSocketChannel Function(String url,
- {Iterable protocols});
-
-// TODO: parse error even
-// TODO: if parsing an error into an event fails we should not hide the
-// TODO: original error
-/// A WebSocket connection that reconnects upon failure.
-class WebSocket {
- /// Creates a new websocket
- /// To connect the WS call [connect]
- WebSocket({
- @required this.baseUrl,
- this.user,
- this.connectParams,
- this.connectPayload,
- this.handler,
- this.logger,
- this.connectFunc,
- this.reconnectionMonitorInterval = 1,
- this.healthCheckInterval = 20,
- this.reconnectionMonitorTimeout = 40,
- }) {
- final qs = Map.from(connectParams);
-
- final data = Map.from(connectPayload);
-
- data['user_details'] = user.toJson();
- qs['json'] = json.encode(data);
-
- if (baseUrl.startsWith('https')) {
- _path = baseUrl.replaceFirst('https://', '');
- _path = Uri.https(_path, 'connect', qs)
- .toString()
- .replaceFirst('https', 'wss');
- } else if (baseUrl.startsWith('http')) {
- _path = baseUrl.replaceFirst('http://', '');
- _path =
- Uri.http(_path, 'connect', qs).toString().replaceFirst('http', 'ws');
- } else {
- _path = Uri.https(baseUrl, 'connect', qs)
- .toString()
- .replaceFirst('https', 'wss');
- }
- }
-
- /// WS base url
- final String baseUrl;
-
- /// User performing the WS connection
- final User user;
-
- /// Querystring connection parameters
- final Map connectParams;
-
- /// WS connection payload
- final Map connectPayload;
-
- /// Functions that will be called every time a new event is received from the
- /// connection
- final EventHandler handler;
-
- /// A WS specific logger instance
- final Logger logger;
-
- /// Connection function
- /// Used only for testing purpose
- @visibleForTesting
- final ConnectWebSocket connectFunc;
-
- /// Interval of the reconnection monitor timer
- /// This checks that it received a new event in the last
- /// [reconnectionMonitorTimeout] seconds, otherwise it considers the
- /// connection unhealthy and reconnects the WS
- final int reconnectionMonitorInterval;
-
- /// Interval of the health event sending timer
- /// This sends a health event every [healthCheckInterval] seconds in order to
- /// make the server aware that the client is still listening
- final int healthCheckInterval;
-
- /// The timeout that uses the reconnection monitor timer to consider the
- /// connection unhealthy
- final int reconnectionMonitorTimeout;
-
- final _connectionStatusController =
- BehaviorSubject.seeded(ConnectionStatus.disconnected);
-
- set _connectionStatus(ConnectionStatus status) =>
- _connectionStatusController.add(status);
-
- /// The current connection status value
- ConnectionStatus get connectionStatus => _connectionStatusController.value;
-
- /// This notifies of connection status changes
- Stream get connectionStatusStream =>
- _connectionStatusController.stream;
-
- String _path;
- int _retryAttempt = 1;
- WebSocketChannel _channel;
- Timer _healthCheck, _reconnectionMonitor;
- DateTime _lastEventAt;
- bool _manuallyDisconnected = false;
- bool _connecting = false;
- bool _reconnecting = false;
-
- Event _decodeEvent(String source) => Event.fromJson(json.decode(source));
-
- Completer _connectionCompleter = Completer();
-
- /// Connect the WS using the parameters passed in the constructor
- Future connect() {
- _manuallyDisconnected = false;
-
- if (_connecting) {
- logger.severe('already connecting');
- return null;
- }
-
- _connecting = true;
- _connectionStatus = ConnectionStatus.connecting;
-
- logger.info('connecting to $_path');
-
- _channel =
- connectFunc?.call(_path) ?? WebSocketChannel.connect(Uri.parse(_path));
- _channel.stream.listen(
- (data) {
- final jsonData = json.decode(data);
- if (jsonData['error'] != null) {
- return _onConnectionError(jsonData['error']);
- }
- _onData(data);
- },
- onError: (error, stacktrace) {
- _onConnectionError(error, stacktrace);
- },
- onDone: () {
- _onDone();
- },
- );
- return _connectionCompleter.future;
- }
-
- void _onDone() {
- _connecting = false;
- if (_manuallyDisconnected) {
- return;
- }
-
- logger.info('connection closed | closeCode: ${_channel.closeCode} | '
- 'closedReason: ${_channel.closeReason}');
-
- if (!_reconnecting) {
- _reconnect();
- }
- }
-
- void _onData(data) {
- if (_manuallyDisconnected) {
- return;
- }
-
- final event = _decodeEvent(data);
- logger.info('received new event: $data');
-
- if (_lastEventAt == null) {
- logger.info('connection estabilished');
- _connecting = false;
- _reconnecting = false;
- _lastEventAt = DateTime.now();
-
- _connectionStatus = ConnectionStatus.connected;
- _retryAttempt = 1;
-
- if (!_connectionCompleter.isCompleted) {
- _connectionCompleter.complete(event);
- }
-
- _startReconnectionMonitor();
- _startHealthCheck();
- }
-
- handler(event);
- _lastEventAt = DateTime.now();
- }
-
- Future _onConnectionError(error, [stacktrace]) async {
- logger..severe('error connecting')..severe(error);
- if (stacktrace != null) {
- logger.severe(stacktrace);
- }
- _connecting = false;
-
- if (!_reconnecting) {
- _connectionStatus = ConnectionStatus.disconnected;
- }
-
- if (!_connectionCompleter.isCompleted) {
- _cancelTimers();
- _connectionCompleter.completeError(error, stacktrace);
- } else if (!_reconnecting) {
- return _reconnect();
- }
- }
-
- void _reconnectionTimer(_) {
- final now = DateTime.now();
- if (_lastEventAt != null &&
- now.difference(_lastEventAt).inSeconds > reconnectionMonitorTimeout) {
- _channel.sink.close();
- }
- }
-
- void _startReconnectionMonitor() {
- _reconnectionMonitor = Timer.periodic(
- Duration(seconds: reconnectionMonitorInterval),
- _reconnectionTimer,
- );
-
- _reconnectionTimer(_reconnectionMonitor);
- }
-
- void _reconnectTimer() async {
- if (!_reconnecting) {
- return;
- }
- if (_connecting) {
- logger.info('already connecting');
- return;
- }
-
- logger.info('reconnecting..');
-
- _cancelTimers();
-
- try {
- await connect();
- } catch (e) {
- logger.log(Level.SEVERE, e.toString());
- }
- await Future.delayed(
- Duration(seconds: min(_retryAttempt * 5, 25)),
- () {
- _reconnectTimer();
- _retryAttempt++;
- },
- );
- }
-
- Future _reconnect() async {
- logger.info('reconnect');
- if (!_reconnecting) {
- _reconnecting = true;
- _connectionStatus = ConnectionStatus.connecting;
- }
-
- _reconnectTimer();
- }
-
- void _cancelTimers() {
- _lastEventAt = null;
- if (_healthCheck != null) {
- _healthCheck.cancel();
- }
- if (_reconnectionMonitor != null) {
- _reconnectionMonitor.cancel();
- }
- }
-
- void _healthCheckTimer(_) {
- logger.info('sending health.check');
- _channel.sink.add("{'type': 'health.check'}");
- }
-
- void _startHealthCheck() {
- logger.info('start health check monitor');
-
- _healthCheck = Timer.periodic(
- Duration(seconds: healthCheckInterval),
- _healthCheckTimer,
- );
-
- _healthCheckTimer(_healthCheck);
- }
-
- /// Disconnects the WS and releases eventual resources
- Future disconnect() async {
- _connecting = false;
- if (!_connectionCompleter.isCompleted) {
- _connectionCompleter.complete();
- }
- if (_manuallyDisconnected) {
- return;
- }
- logger.info('disconnecting');
- _connectionCompleter = Completer();
- _cancelTimers();
- _reconnecting = false;
- _manuallyDisconnected = true;
- _connectionStatus = ConnectionStatus.disconnected;
- await _connectionStatusController.close();
- return _channel.sink.close();
- }
-}
diff --git a/packages/stream_chat/lib/src/client.dart b/packages/stream_chat/lib/src/client.dart
deleted file mode 100644
index fc6e122a..00000000
--- a/packages/stream_chat/lib/src/client.dart
+++ /dev/null
@@ -1,1516 +0,0 @@
-// ignore_for_file: unnecessary_getters_setters
-
-import 'dart:async';
-import 'dart:convert';
-
-import 'package:dio/dio.dart';
-import 'package:logging/logging.dart';
-import 'package:meta/meta.dart';
-import 'package:rxdart/rxdart.dart';
-import 'package:stream_chat/src/api/channel.dart';
-import 'package:stream_chat/src/api/connection_status.dart';
-import 'package:stream_chat/src/api/requests.dart';
-import 'package:stream_chat/src/api/responses.dart';
-import 'package:stream_chat/src/api/retry_policy.dart';
-import 'package:stream_chat/src/api/websocket.dart';
-import 'package:stream_chat/src/attachment_file_uploader.dart';
-import 'package:stream_chat/src/db/chat_persistence_client.dart';
-import 'package:stream_chat/src/event_type.dart';
-import 'package:stream_chat/src/exceptions.dart';
-import 'package:stream_chat/src/extensions/map_extension.dart';
-import 'package:stream_chat/src/models/attachment_file.dart';
-import 'package:stream_chat/src/models/channel_model.dart';
-import 'package:stream_chat/src/models/channel_state.dart';
-import 'package:stream_chat/src/models/event.dart';
-import 'package:stream_chat/src/models/message.dart';
-import 'package:stream_chat/src/models/own_user.dart';
-import 'package:stream_chat/src/models/user.dart';
-import 'package:stream_chat/src/platform_detector/platform_detector.dart';
-import 'package:stream_chat/version.dart';
-import 'package:uuid/uuid.dart';
-
-/// Handler function used for logging records. Function requires a single
-/// [LogRecord] as the only parameter.
-typedef LogHandlerFunction = void Function(LogRecord record);
-
-/// Used for decoding [Map] data to a generic type `T`.
-typedef DecoderFunction = T Function(Map);
-
-/// A function which can be used to request a Stream Chat API token from your
-/// own backend server. Function requires a single [userId].
-typedef TokenProvider = Future Function(String userId);
-
-/// Provider used to send push notifications.
-enum PushProvider {
- /// Send notifications using Google's Firebase Cloud Messaging
- firebase,
-
- /// Send notifications using Apple's Push Notification service
- apn
-}
-
-extension on PushProvider {
- /// Returns the string notion for [PushProvider].
- String get name {
- if (this == PushProvider.apn) {
- return 'apn';
- } else {
- return 'firebase';
- }
- }
-}
-
-/// The official Dart client for Stream Chat,
-/// a service for building chat applications.
-/// This library can be used on any Dart project and on both mobile and web apps
-/// with Flutter.
-///
-/// You can sign up for a Stream account at https://getstream.io/chat/
-///
-/// The Chat client will manage API call, event handling and manage the
-/// websocket connection to Stream Chat servers.
-///
-/// ```dart
-/// final client = StreamChatClient("stream-chat-api-key");
-/// ```
-class StreamChatClient {
- /// Create a client instance with default options.
- /// You should only create the client once and re-use it across your
- /// application.
- StreamChatClient(
- this.apiKey, {
- this.tokenProvider,
- this.baseURL = _defaultBaseURL,
- this.logLevel = Level.WARNING,
- this.logHandlerFunction,
- Duration connectTimeout = const Duration(seconds: 6),
- Duration receiveTimeout = const Duration(seconds: 6),
- Dio httpClient,
- RetryPolicy retryPolicy,
- this.attachmentFileUploader,
- }) {
- _retryPolicy = retryPolicy ??
- RetryPolicy(
- retryTimeout:
- (StreamChatClient client, int attempt, ApiError error) =>
- Duration(seconds: 1 * attempt),
- shouldRetry: (StreamChatClient client, int attempt, ApiError error) =>
- attempt < 5,
- );
-
- attachmentFileUploader ??= StreamAttachmentFileUploader(this);
-
- state = ClientState(this);
-
- _setupLogger();
- _setupDio(httpClient, receiveTimeout, connectTimeout);
-
- logger.info('instantiating new client');
- }
-
- set chatPersistenceClient(ChatPersistenceClient value) {
- _originalChatPersistenceClient = value;
- }
-
- ChatPersistenceClient _originalChatPersistenceClient;
-
- /// Chat persistence client
- ChatPersistenceClient get chatPersistenceClient => _chatPersistenceClient;
-
- ChatPersistenceClient _chatPersistenceClient;
-
- /// Attachment uploader
- AttachmentFileUploader attachmentFileUploader;
-
- /// Whether the chat persistence is available or not
- bool get persistenceEnabled => _chatPersistenceClient != null;
-
- RetryPolicy _retryPolicy;
-
- bool _synced = false;
-
- /// The retry policy options getter
- RetryPolicy get retryPolicy => _retryPolicy;
-
- /// This client state
- ClientState state;
-
- /// By default the Chat client will write all messages with level Warn or
- /// Error to stdout.
- ///
- /// During development you might want to enable more logging information,
- /// you can change the default log level when constructing the client.
- ///
- /// ```dart
- /// final client = StreamChatClient("stream-chat-api-key",
- /// logLevel: Level.INFO);
- /// ```
- final Level logLevel;
-
- /// Client specific logger instance.
- /// Refer to the class [Logger] to learn more about the specific
- /// implementation.
- final Logger logger = Logger.detached('📡');
-
- /// A function that has a parameter of type [LogRecord].
- /// This is called on every new log record.
- /// By default the client will use the handler returned by
- /// [_getDefaultLogHandler].
- /// Setting it you can handle the log messages directly instead of have them
- /// written to stdout,
- /// this is very convenient if you use an error tracking tool or if you want
- /// to centralize your logs into one facility.
- ///
- /// ```dart
- /// myLogHandlerFunction = (LogRecord record) {
- /// // do something with the record (ie. send it to Sentry or Fabric)
- /// }
- ///
- /// final client = StreamChatClient("stream-chat-api-key",
- /// logHandlerFunction: myLogHandlerFunction);
- ///```
- LogHandlerFunction logHandlerFunction;
-
- /// Your project Stream Chat api key.
- /// Find your API keys here https://getstream.io/dashboard/
- String apiKey;
-
- /// Your project Stream Chat base url.
- final String baseURL;
-
- /// A function in which you send a request to your own backend to get a Stream
- /// Chat API token.
- ///
- /// The token will be the return value of the function.
- /// It's used by the client to refresh the token once expired or to connect
- /// the user without a predefined token using [connectUserWithProvider].
- final TokenProvider tokenProvider;
-
- /// [Dio] httpClient
- /// It's be chosen because it's easy to use and supports interesting features
- /// out of the box (Interceptors, Global configuration, FormData,
- /// File downloading etc.)
- @visibleForTesting
- Dio httpClient = Dio();
-
- static const _defaultBaseURL = 'chat-us-east-1.stream-io-api.com';
- static const _tokenExpiredErrorCode = 40;
- StreamSubscription _connectionStatusSubscription;
- Future Function(ConnectionStatus) _connectionStatusHandler;
-
- final BehaviorSubject _controller = BehaviorSubject();
-
- /// Stream of [Event] coming from websocket connection
- /// Listen to this or use the [on] method to filter specific event types
- Stream get stream => _controller.stream;
-
- final _wsConnectionStatusController =
- BehaviorSubject.seeded(ConnectionStatus.disconnected);
-
- set _wsConnectionStatus(ConnectionStatus status) =>
- _wsConnectionStatusController.add(status);
-
- /// The current status value of the websocket connection
- ConnectionStatus get wsConnectionStatus =>
- _wsConnectionStatusController.value;
-
- /// This notifies the connection status of the websocket connection.
- /// Listen to this to get notified when the websocket tries to reconnect.
- Stream get wsConnectionStatusStream =>
- _wsConnectionStatusController.stream;
-
- /// The current user token
- String token;
-
- /// The id of the current websocket connection
- String get connectionId => _connectionId;
-
- bool _anonymous = false;
- String _connectionId;
- WebSocket _ws;
-
- bool get _hasConnectionId => _connectionId != null;
-
- void _setupDio(
- Dio httpClient,
- Duration receiveTimeout,
- Duration connectTimeout,
- ) {
- logger.info('http client setup');
-
- this.httpClient = httpClient ?? Dio();
-
- String url;
- if (!baseURL.startsWith('https') && !baseURL.startsWith('http')) {
- url = Uri.https(baseURL, '').toString();
- } else {
- url = baseURL;
- }
-
- this.httpClient.options.baseUrl = url;
- this.httpClient.options.receiveTimeout = receiveTimeout.inMilliseconds;
- this.httpClient.options.connectTimeout = connectTimeout.inMilliseconds;
- this.httpClient.interceptors.add(
- InterceptorsWrapper(
- onRequest: (options) async {
- options.queryParameters.addAll(_commonQueryParams);
- options.headers.addAll(_httpHeaders);
-
- if (_connectionId != null &&
- (options.data is Map || options.data == null)) {
- options.data = {
- 'connection_id': _connectionId,
- ...options.data ?? {},
- };
- }
-
- var stringData = options.data.toString();
-
- if (options.data is FormData) {
- final multiPart = (options.data as FormData).files[0]?.value;
- stringData =
- '${multiPart?.filename} - ${multiPart?.contentType}';
- }
-
- logger.info('''
-
- method: ${options.method}
- url: ${options.uri}
- headers: ${options.headers}
- data: $stringData
-
- ''');
-
- return options;
- },
- onError: _tokenExpiredInterceptor,
- ),
- );
- }
-
- Future _tokenExpiredInterceptor(DioError err) async {
- final apiError = ApiError(
- err.response?.data,
- err.response?.statusCode,
- );
-
- if (apiError.code == _tokenExpiredErrorCode) {
- logger.info('token expired');
-
- if (tokenProvider != null) {
- httpClient.lock();
- final userId = state.user.id;
-
- await _disconnect();
-
- final newToken = await tokenProvider(userId);
- await Future.delayed(const Duration(seconds: 4));
- token = newToken;
-
- httpClient.unlock();
-
- await connectUser(User(id: userId), newToken);
-
- try {
- return await httpClient.request(
- err.request.path,
- cancelToken: err.request.cancelToken,
- data: err.request.data,
- onReceiveProgress: err.request.onReceiveProgress,
- onSendProgress: err.request.onSendProgress,
- queryParameters: err.request.queryParameters,
- options: err.request,
- );
- } catch (err) {
- return err;
- }
- }
- }
-
- return err;
- }
-
- LogHandlerFunction _getDefaultLogHandler() {
- final levelEmojiMapper = {
- Level.INFO.name: 'ℹ️',
- Level.WARNING.name: '⚠️',
- Level.SEVERE.name: '🚨',
- };
- return (LogRecord record) {
- print(
- '(${record.time}) '
- '${levelEmojiMapper[record.level.name] ?? record.level.name} '
- '${record.loggerName} ${record.message}',
- );
- if (record.stackTrace != null) {
- print(record.stackTrace);
- }
- };
- }
-
- Logger _detachedLogger(
- String name,
- ) =>
- Logger.detached(name)
- ..level = logLevel
- ..onRecord.listen(logHandlerFunction ?? _getDefaultLogHandler());
-
- void _setupLogger() {
- logger.level = logLevel;
-
- logHandlerFunction ??= _getDefaultLogHandler();
-
- logger.onRecord.listen(logHandlerFunction);
-
- logger.info('logger setup');
- }
-
- /// Call this function to dispose the client
- void dispose() async {
- await _chatPersistenceClient?.disconnect();
- await _disconnect();
- httpClient.close();
- await _controller.close();
- state.dispose();
- await _wsConnectionStatusController.close();
- }
-
- Map get _httpHeaders => {
- 'Authorization': token,
- 'stream-auth-type': _authType,
- 'X-Stream-Client': _userAgent,
- 'Content-Encoding': 'gzip',
- };
-
- /// Set the current user, this triggers a connection to the API.
- /// It returns a [Future] that resolves when the connection is setup.
- @Deprecated('Use `connectUser` instead. Will be removed in Future releases')
- Future setUser(User user, String token) => connectUser(user, token);
-
- /// Connects the current user, this triggers a connection to the API.
- /// It returns a [Future] that resolves when the connection is setup.
- Future connectUser(User user, String token) async {
- if (_connectCompleter != null && !_connectCompleter.isCompleted) {
- logger.warning('Already connecting');
- throw Exception('Already connecting');
- }
-
- _connectCompleter = Completer();
-
- logger.info('connect user');
- state.user = OwnUser.fromJson(user.toJson());
- this.token = token;
- _anonymous = false;
-
- return connect().then((event) {
- _connectCompleter.complete(event);
- return event;
- }).catchError((e, s) {
- _connectCompleter.completeError(e, s);
- throw e;
- });
- }
-
- /// Set the current user using the [tokenProvider] to fetch the token.
- /// It returns a [Future] that resolves when the connection is setup.
- @Deprecated(
- 'Use `connectUserWithProvider` instead. Will be removed in Future releases',
- )
- Future setUserWithProvider(User user) => connectUserWithProvider(user);
-
- /// Connects the current user using the [tokenProvider] to fetch the token.
- /// It returns a [Future] that resolves when the connection is setup.
- Future connectUserWithProvider(User user) async {
- if (tokenProvider == null) {
- throw Exception('''
- TokenProvider must be provided in the constructor in order to use `connectUserWithProvider` method.
- Use `connectUser` providing a token.
- ''');
- }
- final token = await tokenProvider(user.id);
- return connectUser(user, token);
- }
-
- /// Stream of [Event] coming from websocket connection
- /// Pass an eventType as parameter in order to filter just a type of event
- Stream on([
- String eventType,
- String eventType2,
- String eventType3,
- String eventType4,
- ]) =>
- stream.where((event) =>
- eventType == null ||
- (event.type != null &&
- (event.type == eventType ||
- event.type == eventType2 ||
- event.type == eventType3 ||
- event.type == eventType4)));
-
- /// Method called to add a new event to the [_controller].
- void handleEvent(Event event) async {
- logger.info('handle new event: ${event.toJson()}');
- if (event.connectionId != null) {
- _connectionId = event.connectionId;
- }
-
- if (!event.isLocal) {
- if (_synced && event.createdAt != null) {
- await _chatPersistenceClient?.updateConnectionInfo(event);
- await _chatPersistenceClient?.updateLastSyncAt(event.createdAt);
- }
- }
-
- if (event.user != null) {
- state._updateUser(event.user);
- }
-
- if (event.me != null) {
- state.user = event.me;
- }
- _controller.add(event);
- }
-
- Completer _connectCompleter;
-
- /// Connect the client websocket
- Future connect() async {
- logger.info('connecting');
- if (wsConnectionStatus == ConnectionStatus.connecting) {
- logger.warning('Already connecting');
- throw Exception('Already connecting');
- }
-
- if (wsConnectionStatus == ConnectionStatus.connected) {
- logger.warning('Already connected');
- throw Exception('Already connected');
- }
-
- _wsConnectionStatus = ConnectionStatus.connecting;
-
- if (_originalChatPersistenceClient != null) {
- _chatPersistenceClient = _originalChatPersistenceClient;
- await _chatPersistenceClient.connect(state.user.id);
- }
-
- _ws = WebSocket(
- baseUrl: baseURL,
- user: state.user,
- connectParams: {
- 'api_key': apiKey,
- 'authorization': token,
- 'stream-auth-type': _authType,
- 'X-Stream-Client': _userAgent,
- },
- connectPayload: {
- 'user_id': state.user.id,
- 'server_determines_connection_id': true,
- },
- handler: handleEvent,
- logger: _detachedLogger('🔌'),
- );
-
- _connectionStatusHandler = (ConnectionStatus status) async {
- _wsConnectionStatus = status;
- handleEvent(
- Event(
- type: EventType.connectionChanged,
- online: status == ConnectionStatus.connected,
- ),
- );
-
- if (status == ConnectionStatus.connected) {
- handleEvent(Event(
- type: EventType.connectionRecovered,
- online: true,
- ));
- if (state.channels?.isNotEmpty == true) {
- // ignore: unawaited_futures
- queryChannelsOnline(filter: {
- 'cid': {
- '\$in': state.channels.keys.toList(),
- },
- }).then(
- (_) async {
- await resync();
- },
- );
- } else {
- _synced = false;
- }
- }
- };
-
- _connectionStatusSubscription =
- _ws.connectionStatusStream.listen(_connectionStatusHandler);
-
- var event = await _chatPersistenceClient?.getConnectionInfo();
-
- await _ws.connect().then((e) {
- _chatPersistenceClient?.updateConnectionInfo(e);
- event = e;
- resync();
- }).catchError((err, stacktrace) {
- logger.severe('error connecting ws', err, stacktrace);
- if (err is Map) {
- // ignore: only_throw_errors
- throw err;
- }
- });
-
- return event;
- }
-
- /// Get the events missed while offline to sync the offline storage
- Future resync([List cids]) async {
- final lastSyncAt = await _chatPersistenceClient?.getLastSyncAt();
-
- if (lastSyncAt == null) {
- _synced = true;
- return;
- }
-
- cids ??= await _chatPersistenceClient?.getChannelCids();
-
- if (cids?.isEmpty == true) {
- return;
- }
-
- try {
- final rawRes = await post('/sync', data: {
- 'channel_cids': cids,
- 'last_sync_at': lastSyncAt.toUtc().toIso8601String(),
- });
- logger.fine('rawRes: $rawRes');
-
- final res = decode(
- rawRes.data,
- SyncResponse.fromJson,
- );
-
- res.events.sort((a, b) => a.createdAt.compareTo(b.createdAt));
-
- res.events.forEach((element) {
- logger
- ..fine('element.type: ${element.type}')
- ..fine('element.message.text: ${element.message?.text}');
- });
-
- res.events.forEach(handleEvent);
-
- await _chatPersistenceClient?.updateLastSyncAt(DateTime.now());
- _synced = true;
- } catch (error) {
- logger.severe('Error during resync $error');
- }
- }
-
- String _asMap(sort) => sort?.map((s) => s.toJson().toString())?.join('');
-
- final _queryChannelsStreams = >>{};
-
- /// Requests channels with a given query.
- Stream> queryChannels({
- Map filter,
- List> sort,
- Map options,
- PaginationParams paginationParams = const PaginationParams(),
- int messageLimit,
- bool waitForConnect = true,
- }) async* {
- final hash = base64.encode(utf8.encode(
- '$filter${_asMap(sort)}$options${paginationParams?.toJson()}'
- '$messageLimit',
- ));
-
- if (_queryChannelsStreams.containsKey(hash)) {
- yield await _queryChannelsStreams[hash];
- } else {
- final channels = await queryChannelsOffline(
- filter: filter,
- sort: sort,
- paginationParams: paginationParams,
- );
- if (channels.isNotEmpty) yield channels;
-
- try {
- final newQueryChannelsFuture = queryChannelsOnline(
- filter: filter,
- sort: sort,
- options: options,
- paginationParams: paginationParams,
- messageLimit: messageLimit,
- waitForConnect: waitForConnect,
- ).whenComplete(() {
- _queryChannelsStreams.remove(hash);
- });
-
- _queryChannelsStreams[hash] = newQueryChannelsFuture;
-
- yield await newQueryChannelsFuture;
- } catch (_) {
- if (channels.isEmpty) rethrow;
- }
- }
- }
-
- /// Requests channels with a given query from the API.
- Future> queryChannelsOnline({
- @required Map filter,
- List> sort,
- Map options,
- int messageLimit,
- PaginationParams paginationParams = const PaginationParams(),
- bool waitForConnect = true,
- }) async {
- if (waitForConnect) {
- if (_connectCompleter != null && !_connectCompleter.isCompleted) {
- logger.info('awaiting connection completer');
- await _connectCompleter.future;
- }
- if (wsConnectionStatus != ConnectionStatus.connected) {
- throw Exception(
- 'You cannot use queryChannels without an active connection.'
- ' Please call `connectUser` to connect the client.',
- );
- }
- }
-
- logger.info('Query channel start');
- final defaultOptions = {
- 'state': true,
- 'watch': true,
- 'presence': false,
- };
-
- final payload = {
- 'filter_conditions': filter,
- 'sort': sort,
- };
-
- if (messageLimit != null) {
- payload['message_limit'] = messageLimit;
- }
-
- payload.addAll(defaultOptions);
-
- if (options != null) {
- payload.addAll(options);
- }
-
- if (paginationParams != null) {
- payload.addAll(paginationParams.toJson());
- }
-
- final response = await get(
- '/channels',
- queryParameters: {
- 'payload': jsonEncode(payload),
- },
- );
-
- final res = decode(
- response.data,
- QueryChannelsResponse.fromJson,
- );
-
- if ((res.channels ?? []).isEmpty && (paginationParams?.offset ?? 0) == 0) {
- logger.warning(
- '''
- We could not find any channel for this query.
- Please make sure to take a look at the Flutter tutorial: https://getstream.io/chat/flutter/tutorial
- If your application already has users and channels, you might need to adjust your query channel as explained in the docs https://getstream.io/chat/docs/query_channels/?language=dart''',
- );
- return [];
- }
-
- final channels = res.channels;
-
- final users = channels
- .expand((it) => it.members)
- .map((it) => it.user)
- .toList(growable: false);
-
- state._updateUsers(users);
-
- logger.info('Got ${res.channels?.length} channels from api');
-
- final updateData = _mapChannelStateToChannel(channels);
-
- await _chatPersistenceClient?.updateChannelQueries(
- filter,
- channels.map((c) => c.channel.cid).toList(),
- clearQueryCache:
- paginationParams?.offset == null || paginationParams.offset == 0,
- );
-
- state.channels = updateData.key;
- return updateData.value;
- }
-
- /// Requests channels with a given query from the Persistence client.
- Future> queryChannelsOffline({
- @required Map filter,
- @required List> sort,
- PaginationParams paginationParams = const PaginationParams(),
- }) async {
- final offlineChannels = await _chatPersistenceClient?.getChannelStates(
- filter: filter,
- sort: sort,
- paginationParams: paginationParams,
- );
- final updatedData = _mapChannelStateToChannel(offlineChannels);
- state.channels = updatedData.key;
- return updatedData.value;
- }
-
- MapEntry