chatsasa_livechat 1.0.11 copy "chatsasa_livechat: ^1.0.11" to clipboard
chatsasa_livechat: ^1.0.11 copied to clipboard

A live-chat customer support flutter sdk

ChatSasa Live-Chat SDK #

Welcome to the ChatSasa Flutter SDK. This SDK allows you to easily integrate ChatSasa's live chat functionality into your Flutter mobile applications.

Getting started #

For you to start using Chatsasa Live chat SDK you need an admin/agent account and an organisation for manning the incoming messages.

Here are the steps to get you started.

  • Sign up in Chatsasa.
  • Create an Organisation.
  • Create a Customer Support Widget.
  • Create a Customer Support Channel.
  • Link a Customer Support Channel to a Widget (Go to your widget and click Edit).
  • Copy and pass the widgetUUID to the Flutter SDK.

Add dependency #

Add this to your package's pubspec.yaml file, use the latest version.

dependencies:
 chatsasa_livechat: ^latest_version

You should then run flutter packages get

Changelog #

Check out the changelog on pub.dev to see the latest changes in the package.

Initialization #

Initialize the ChatSasa SDK in your main.dart file:

import 'package:flutter/material.dart';
import 'package:chatsasa_flutter_sdk/chatsasa_flutter_sdk.dart';

Future<void> main() async {
  // initilize the sdk
  WidgetsFlutterBinding.ensureInitialized();
  var chatSDK = ChatSasaLiveChat();
  chatSDK.initSDK();
  runApp(const MyApp());
}

Usage #

To launch the chat widget, use the following code in your main widget file:

You need to pass the user details under the AppUserModel. UserIdentifier field is mandatory. Launch the Chat Widget by providing the widgetUUID and the appUserModel.

import 'package:chatsasa_livechat/chatsasa_livechat.dart';
import 'package:chatsasa_livechat/export.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  // initilize the sdk
  WidgetsFlutterBinding.ensureInitialized();
  var chatSDK = ChatSasaLiveChat();
  chatSDK.initSDK();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "ChatSasa Live-Chat Example",
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({
    super.key,
  });

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // Create a chat user
    // userIdentifier is a required field
    var sampleAppUser = AppUserModel(
      name: 'user',
      email: 'user@gmail.com',
      userIdentifier:
          'user@gmail.com', // userIdentifier is anything you use to uniquely identify your users on ChatSasa API
    );
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
        title: const Text(
          "ChatSasa Live-Chat Example",
          style: TextStyle(color: Colors.white),
        ),
      ),
      body: Center(
        child: Container(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (_) => LiveChatChannels(
                      widgetUUID:
                          "YOUR_WIDGET_UUID", // Replace with your widget UUID
                      appUserModel: sampleAppUser)));
        },
        tooltip: 'launch live chat',
        child: const Icon(Icons.chat_bubble_outline),
      ),
    );
  }
}