---
url: https://talkjs.com/docs/UI_Components/Flutter/Talk_Object
---

Ask a question Copy for LLM [View as Markdown](/docs/UI_Components/Flutter/Talk_Object.md)

## class Talk

Provides static utility functions to help use TalkJS. `Talk` cannot be instantiated.

### oneOnOneId

```dart
static String oneOnOneId(String me, String other)
```

Use this helper method to predictably compute a Conversation ID based on participants' ids in the given conversation. Use this method if you want to simply create a conversation between two users, not related to a particular product, order or transaction.
The order of the parameters does not matter. For example, `Talk.oneOnOneId("a", "b")` yields the same result as `Talk.oneOnOneId("b", "a")`.
This method takes the following steps:

1. Take two ids of users and put them in an array
2. Sort them lexicographically
3. JSON encode them
4. Hash the result using SHA1, return the first 20 characters
In pseudocode, this is what this function does:

```dart
final ids = [me, other];
ids.sort();

final encoded = json.encode(ids);
final hash = sha1.convert(utf8.encode(encoded)).toString().toLowerCase(); // as lowercase hex

return hash.substring(0, 20);
```

#### Parameters

##### me

: String

A string containing the user ID.

##### other

: String

Another string containing the user ID.

### registerPushNotificationHandlers

```dart
static Future<void> registerPushNotificationHandlers({
  AndroidSettings? androidSettings,
  IOSSettings? iosSettings,
});
```

This function sets up the push notification handlers.
It is meant to be called in the app's `main()` function before `runApp()`.
This is critical to ensuring that notifications are received and handled
properly especially when the app is stopped.

**Note**: For versions 0.9.3 and older, calling this function would also implicitly request
permissions on iOS. From version 0.10.0, this is no longer the case.

#### Parameters

##### androidSettings (optional)

: [AndroidSettings](#AndroidSettings)?

An object describing the Android [Notification Channel](https://developer.android.com/guide/topics/ui/notifiers/notifications#ManageChannels) to be created. Without a channel, notifications will not work.

##### iosSettings (optional)

: [IOSSettings](#IOSSettings)?

An object indicating the different iOS push notification settings.

#### Returns

`Future<void>`

#### Example

```dart
// Inside your app's main.dart
import 'package:flutter/material.dart';
import 'package:talkjs_flutter/talkjs_flutter.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (Platform.isAndroid) {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
  }

  await Talk.registerPushNotificationHandlers(
    androidSettings: const AndroidSettings(
      channelId: 'com.example.talkjsflutter.messages',
      channelName: 'Messages',
    ),
    iosSettings: const IOSSettings(useFirebase: false),
  );

  runApp(const MyApp());
}
```

### handleFCMBackgroundMessage

```dart
static Future<bool> handleFCMBackgroundMessage(RemoteMessage firebaseMessage);
```

This function handles TalkJS originated push notifications on Android.
It is expected to be called inside a custom `FirebaseMessaging.onBackgroundMessage` handler.

**Note**: In order to be able to use this function, you have to call the `Talk.registerPushNotificationHandlers` function with the `registerBackgroundHandler: false` `androidSettings` option, and manually register `FirebaseMessaging.onBackgroundMessage`.

#### Parameters

##### firebaseMessage

: RemoteMessage

The remote FCM message payload.

#### Returns

`Future<bool>`

The return value is `true` if the push notification was TalkJS originated and handled by this function.
A `false` return value means that the push notification was not TalkJS originated and not handled by this function.

#### Example

```dart
import 'package:flutter/material.dart';
import 'package:talkjs_flutter/talkjs_flutter.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (Platform.isAndroid) {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
  }

  await Talk.registerPushNotificationHandlers(
    androidSettings: const AndroidSettings(
      channelId: 'com.example.talkjsflutter.messages',
      channelName: 'Messages',
      registerBackgroundHandler: false,
    ),
    iosSettings: const IOSSettings(useFirebase: false),
  );

  FirebaseMessaging.onBackgroundMessage(myBackgroundMessageHandler);

  runApp(const MyApp());
}

@pragma("vm:entry-point")
Future<void> myBackgroundMessageHandler(RemoteMessage firebaseMessage) async {
  // Call the TalkJS-specific push notification handler
  final notificationHandled = await Talk.handleFCMBackgroundMessage(firebaseMessage);

  if (!notificationHandled) {
    // Handle non-TalkJS originated push notification
  }
}
```

## class AndroidSettings

```dart
const AndroidSettings({
  required String channelId,
  required String channelName,
  bool? badge,
  String? channelDescription,
  bool? lights,
  Color? lightColor,
  String playSound = 'default',
  AndroidImportance? importance,
  AndroidVisibility? visibility,
  bool? vibrate,
  Int64List? vibrationPattern,
  bool? registerBackgroundHandler,
});
```

This object describes the properties of the Notification Channel on Android.

#### Parameters

##### channelId

: String

The unique id of the channel.

##### channelName

: String

The user visible name of the channel.
The recommended maximum length is **40** characters;
the value may be truncated if it is too long.

##### badge (optional)

: bool?

Sets whether badges are enabled for the channel.
Defaults to `true`.

This setting cannot be overridden once the channel is created.

##### channelDescription (optional)

: String?

This is the description that the user sees in the system settings.
The recommended maximum length is **300** characters;
the value may be truncated if it is too long.
Default: `null`

##### lights (optional)

: bool?

Sets whether notifications posted to this channel should display notification
lights, on devices that support that feature.
Defaults to `true`.

This setting cannot be overridden once the channel is created.

##### lightColor (optional)

: Color?

If lights are enabled (via `lights`), sets/overrides the light color for
notifications posted to this channel.

This setting cannot be overridden once the channel is created.

##### playSound (optional)

: String

Sound to play when the notification is shown.

Value of `'default'` plays the default sound; an empty string disables the notification sound.

It can be set to a custom sound such as `'my_sound'`.
It will look for the `my_sound.mp3` audio file in `[project_root]/android/app/src/main/res/raw` directory and play it.

Default: `'default'`

##### importance (optional)

: [AndroidImportance](#AndroidImportance)?

The importance of the channel.
This controls how interruptive notifications posted to this channel are. [Read more.](https://developer.android.com/training/notify-user/channels#importance).

Default: `AndroidImportance.HIGH`

##### visibility (optional)

: [AndroidVisibility](#AndroidVisibility)?

Sets whether notifications posted to this channel appear on the lockscreen or
not, and if so, whether they appear in a redacted form.

##### vibrate (optional)

: bool?

Creates the default vibration pattern if true.
Default: `true`

##### vibrationPattern (optional)

: Int64List?

Sets/overrides the vibration pattern for notifications posted to this channel.
The pattern in milliseconds.
Must be an even amount of numbers.

##### registerBackgroundHandler (optional)

: bool?

Automatically registers the `FirebaseMessaging.onBackgroundMessage` handler.
Default: `true`

## class IOSSettings

```dart
const IOSSettings({ bool useFirebase = false });
```

This object configures the appropriate iOS push notification service.

#### Parameters

##### useFirebase (optional)

: bool

Whether your app is using Firebase push notifications on iOS.

Default: `false`

## enum AndroidImportance

##### HIGH

##### DEFAULT

##### LOW

##### MIN

##### NONE

## enum AndroidVisibility

##### PRIVATE

##### PUBLIC

##### SECRET