---
updatedAt: 2025-02-14T21:05:04.000Z
agentTools:
  projectIndex: https://developers.atlas.so/llms.txt
---

# Atlas Flutter SDK

# Getting started

To use it with Android you may need to ensure that AndroidManifest.xml includes `<uses-permission android:name="android.permission.INTERNET" />`

# Usage

You can run [sample application](https://github.com/atlas-support-inc/flutter-sdk/blob/master/example) by changing credentials in the [main.dart](https://github.com/atlas-support-inc/flutter-sdk/blob/master/example/lib/main.dart) file.

## Using the widget to add the chat

```go
import 'package:atlas_support_sdk/atlas_support_widget.dart';

// Use widget:
AtlasSupportWidget(appId: "...", userId: "...", userHash: "...", onError: print)
```

## Listening for stats changes

Each conversation stat instance contains `id`, `unread` (amount of unread messages), and `closed` flag.

```go
import 'package:atlas_support_sdk/watch_atlas_support_stats.dart';

// Listen:
class _MyWidgetState extends State<MyWidget> {
  int _unreadCount = 0;
  Function? _unsubscribe = null;

  @override
  void initState() {
    super.initState();
    _unsubscribe = watchAtlasSupportStats(
        appId: "...",
        userId: "...",
        userHash: "...",
        onStatsChange: (stats) {
          setState(() {
            _unreadCount = stats.conversations
                .fold(0, (sum, conversation) => sum + conversation.closed ? 0 : conversation.unread);
          });
        },
        onError: print);
  }

  @override
  void dispose() {
    _unsubscribe?.call();
    super.dispose();
  }

  // ...
}
```

## Updating user custom fields

```Text Go
import 'package:atlas_support_sdk/update_atlas_custom_fields.dart';

AtlasSupportWidget(
  appId: "...",
  onNewTicket: (data) {
    updateAtlasCustomFields(
      "...", // atlasId
      data["ticketId"], // ticketId
      {"prop": "value"}, // customFields
      // If needed:
      userHash: "...",
    );
  },
);
```

## Using instance with shared settings

Using SDK instance you can change user for all widgets and watches by calling `sdk.identify(userId: "...", userHash: "...")`.

```Text Go
import 'package:atlas_support_sdk/atlas_support_sdk.dart';

// Listen:
class _MyWidgetState extends State<MyWidget> {
  int _unreadCount = 0;
  Function? _unsubscribe = null;
  AtlasSupportSDK atlasSdk = createAtlasSupportSDK(appId: "...", userId: "...", userHash: "...", onError: print);

  @override
  void initState() {
    super.initState();
    _unsubscribe = atlasSdk.watchStats((stats) {
      setState(() {
        _unreadCount = stats.conversations
            .fold(0, (sum, conversation) => sum + conversation.closed ? 0 : conversation.unread);
      });
    });
  }

  @override
  void dispose() {
    _unsubscribe?.call();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: atlasSdk.Widget(
        onNewTicket: (data) {
          atlasSdk.updateCustomFields(
            data["ticketId"], // ticketId
            {"prop": "value"}, // customFields
          );
        },
      )
    );
  }

  // ...
}
```

When using the widget via SDK instance you can also persist its state to prevent loading Atlas more than once. Use `persist` property with the unique string value at any place and after the initial load the app will render immediately:

```Text Go
sdk.Widget(persist: "main")
```