> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Learn how to install QuickBlox SDK and send your first message.

QuickBlox SDK helps you implement real-time chat, video chat, and push notifications to your app. You can fully concentrate on your mobile app development.

## Start with sample app

Choose the code sample below to jump-start the development. We use GitHub repositories to make it easy to explore, copy, and modify our code samples. The guide on how to launch and configure the sample app is on GitHub.

<CardGroup>
  <Card title="Flutter Chat Sample App" icon="flutter">
    <a className="inline-link" href="https://github.com/QuickBlox/quickblox-flutter-samples/tree/master/chat%5Fsample">
      <Icon icon="github" /> View on GitHub
    </a>

    <br />

    <a className="inline-link" href="/sdks/flutter-chat">
      <Icon icon="book" />  Documentation
    </a>
  </Card>
</CardGroup>

## Flutter Chat Sample App

[View on GitHub](https://github.com/QuickBlox/quickblox-flutter-samples/tree/master/chat%5Fsample) [Documentation](https://docs.quickblox.com/sdks/flutter-chat)

For more samples, head to our [Code Samples](/code-samples/code-samples) page. These sample apps are available on GitHub so feel free to browse them there.

## Get application credentials

QuickBlox application includes everything that brings messaging right into your application - chat, video calling, users, push notifications, etc. To create a QuickBlox application, follow the steps below:

1. Register a new account following [this link](https://admin.quickblox.com/signup). Type in your email and password to sign in. You can also sign in with your Google or GitHub accounts.
2. Create the app clicking **New app** button.
3. Configure the app. Type in the information about your organization into corresponding fields and click **Add** button.
4. Go to **Dashboard => *YOUR\_APP* => Overview**  section and copy your **Application ID**, **Authorization Key**, **Authorization Secret**, and **Account Key** .

## Requirements

The minimum requirements for QuickBlox Flutter SDK are:

* iOS 13.0
* Android (minimum version 5.0, API 21)
* Flutter (minimum version 2.12.0)

## Install QuickBlox SDK into your app

<Note>
  To manage project dependencies [Flutter](https://flutter.dev/docs/get-started/install) should be installed.
</Note>

To connect QuickBlox to your app just add it into your project dependencies in **pubspec.yaml** file located in the **root project directory => dependencies** section.

```YAML YAML theme={null}
dependencies:
  flutter:
    sdk: flutter

  # The following adds the QuickBlox SDK to your application.
  quickblox_sdk: 0.18.0
```

#### ⚠️ Android – Breaking Change (from 0.18.0 and above)

Starting from **0.18.0**, the SDK **no longer manages permissions** required for calling functionality on Android.

If your app uses calling features, you must **manually declare** the necessary permissions in your app’s `AndroidManifest.xml` file.

<Note>
  Kindly ensure you're modifying the main `AndroidManifest.xml` file located at the application level — not a test or variant manifest.
</Note>

```xml XML theme={null}
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <!-- Permissions required for QuickBlox calling functionality -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
    <!-- other manifest entries -->
</manifest>
```

## Send your first message

### Initialize QuickBlox SDK

Initialize the framework with your application credentials. Pass `appId`, `authKey`, `authSecret`, `accountKey` to the `init()` method using the code snippet below.

```Dart Dart theme={null}
String appId = 76730;
String authKey = "XydaWcf8OO9xhGT";
String authSecret = "iiohfdija792hjt";
String accountKey = "7yvNe17TnjNUqDoPwfqp";

void init() async {
  try {
    await QB.settings.init(appId, authKey, authSecret, accountKey);
  } on PlatformException catch (e) {
    // Some error occurred, look at the exception message for more details
  }
}
```

<Warning>
  You must initialize SDK before calling any methods through the SDK, except for the `init()` method. If you attempt to call a method without connecting, the error is returned.
</Warning>

<Tip>
  **Security**

  It's not recommended to keep your **authKey** and **authSecret** inside an application in production mode, instead of this, the best approach will be to store them on your backend and initialize QuickBlox SDK with applicationId and acountKey only. More details you can find in [Initialize QuickBlox SDK without Authorization Key and Secret](/sdks/flutter-setup#initialize-quickblox-sdk-without-authorization-key-and-secret) section.
</Tip>

### Authorize user

Now, it is time to log in with the user. To get it done, set the login and password of the user, call the `login()` method and pass the `login` and `password` to it using the code snippet below.

```Dart Dart theme={null}
String login = "chrispeterson";
String password = "superPassword";

void login() async {
  try {
    QBLoginResult result = await QB.auth.login(login, password);
    QBUser qbUser = result.qbUser;
    QBSession qbSession = result.qbSession;
  } on PlatformException catch (e) {
     // Some error occurred, look at the exception message for more details
  }
}
```

### Connect to chat

Having authorized a user, you can proceed with connecting to the chat server to start using Chat module functionality. Call the `connect()` method and pass `userId` and `password` to it.

```Dart Dart theme={null}
int userId = 38457619;
String password = "superPassword";

void connect() async {
  try {
    await QB.chat.connect(userId, password);
  } on PlatformException catch (e) {
    // Some error occurred, look at the exception message for more details
  }
}
```

### Create dialog

QuickBlox provides three types of dialogs: **1-1 dialog**, **group dialog**, and **public dialog**. Learn more about dialogs [here](/sdks/flutter-chat-dialogs#create-dialog).

Let’s create a simple **1-1 dialog**. Call the `createDialog()` method and pass the `occupantsIds`, `dialogName`, and `dialogType` to it.

```Dart Dart theme={null}
List<int> occupantsIds = [98987887, 76894569];
String dialogName = "test dialog";
int dialogType = QBChatDialogTypes.CHAT;

void createDialog() async {
  try {
    QBDialog? createdDialog = await QB.chat.createDialog(occupantsIds, dialogName, dialogType: dialogType);
    if(createdDialog != null) {
      String _dialogId = createdDialog.id!;
    }
  } on PlatformException catch (e) {
    // Some error occurred, look at the exception message for more details
  }
}
```

### Subscribe to receive messages

QuickBlox SDK emits events to notify about chat events. Thus, when a message has been received, a user receives the event from SDK about a new incoming message. To process events, you need to provide an event handler that SDK will call. See the code snippet below.

```Dart Dart theme={null}
String eventName = QBChatEvents.RECEIVED_NEW_MESSAGE;

void subscribeNewMessage() async {
  try {
    await QB.chat.subscribeChatEvent(eventName, (data) {
      Map<dynamic, dynamic> map = Map<dynamic, dynamic>.from(data);
      Map<dynamic, dynamic> payload = Map<dynamic, dynamic>.from(map["payload"]);
      String messageId = payload["id"] as String;
    }, onErrorMethod: (error) {
      // Some error occurred, look at the exception message for more details
    });
  } on PlatformException catch (e) {
    // Some error occurred, look at the exception message for more details
  }
}
```

### Send message

To send a message, call the `sendMessage()` method and pass the `dialogId` and `body` as arguments to it.

```Dart Dart theme={null}
String dialogId = "8b75a6c7191285499d890a81df4ee7fe49bc732a";
String body = "hey there!";
bool saveToHistory = true;

void sendMessage() async {
  try {
    await QB.chat.sendMessage(dialogId, body: body, saveToHistory: saveToHistory);
  } on PlatformException catch (e) {
    // Some error occurred, look at the exception message for more details
  }
}
```

<Note>
  Set the `saveToHistory` parameter if you want this message to be saved in chat history.
</Note>
