widgets_sdk_flutter 2.0.0 copy "widgets_sdk_flutter: ^2.0.0" to clipboard
widgets_sdk_flutter: ^2.0.0 copied to clipboard

retractedoutdated

GliaWidgets SDK is a simple and customisable framework built on top of GliaSDK. It provides all the necessary UI components to quickly integrate GliaSDK into your project.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:widgets_sdk_flutter/glia_widgets_sdk.dart';
import 'package:widgets_sdk_flutter/glia_widgets_sdk_platform.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _sdkStatus = '';
  String _remoteConfig = '';
  final _sdk = GliaWidgetsSdk();

  @override
  void initState() {
    super.initState();
    loadConfigsFromAssets();
  }

  Future<void> loadConfigsFromAssets() async {
    var jsonText = await rootBundle.loadString('assets/config.json');

    setState(() {
      _remoteConfig = jsonText;
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> configure() async {
    String configurationStatus;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      await _sdk.configure(
          siteApiKeyId: apikeyIdTextController.value.text,
          siteApiKeySecret: apikeySecretTextController.value.text,
          siteId: siteIdTextController.value.text,
          queueId: queueIdTextController.value.text,
          region: regionTextController.value.text,
          companyName: companyNameTextController.value.text,
          config: _remoteConfig);
      configurationStatus = 'Configured';
    } catch (err) {
      configurationStatus = 'Error $err';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _sdkStatus = configurationStatus;
    });
  }

  Future<void> startChatEngagement() async {
    String startChatStatus = '';
    try {
      await _sdk.startEngagement(kind: EngagementKind.chat);
    } catch (err) {
      startChatStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = startChatStatus;
    });
  }

  Future<void> endEngagement() async {
    String endEngagementStatus = '';
    try {
      await _sdk.endEngagement();
    } catch (err) {
      endEngagementStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = endEngagementStatus;
    });
  }

  Future<void> showVisitorCodeViewController() async {
    String showVisitorCodeStatus = '';
    try {
      await _sdk.showVisitorCodeViewController();
    } catch (err) {
      showVisitorCodeStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = showVisitorCodeStatus;
    });
  }

  Future<void> authenticate() async {
    String authenticateStatus = '';
    try {
      String accessTokenRawValue = accessTokenTextController.value.text;
      String? accessToken =
          accessTokenRawValue.isEmpty ? null : accessTokenRawValue;
      await _sdk.authenticate(
          jwtToken: jwtTokenTextController.value.text,
          accessToken: accessToken);
    } catch (err) {
      authenticateStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = authenticateStatus;
    });
  }

  Future<void> secureConversations() async {
    String secureConversationStatus = '';
    try {
      await _sdk.secureConversations(
          initialScreen: SecureConversationsInitialScreen.welcome);
    } catch (err) {
      secureConversationStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = secureConversationStatus;
    });
  }

  Future<void> clearVisitorSession() async {
    String clearVisitorStatus = '';
    try {
      await _sdk.clearVisitorSession();
    } catch (err) {
      clearVisitorStatus = 'Error $err';
    }
    if (!mounted) return;

    setState(() {
      _sdkStatus = clearVisitorStatus;
    });
  }

  Future<void> updateVisitorInfo() async {
    await _sdk.updateVisitorInfo(
        info: {'external_id': visitorInfoIdTextController.value.text});
  }

  var apikeyIdTextController =
      TextEditingController(text: "45fc1c28-27ab-4410-bcca-3805d9968f64");
  var apikeySecretTextController =
      TextEditingController(text: "gls_bMYHCO0jqQnEWYoW52cdmNfexJ5DTHKQYCfo");
  var siteIdTextController =
      TextEditingController(text: "1fcde86b-26ba-442f-99e1-68e9cff7ddb6");
  var queueIdTextController =
      TextEditingController(text: "e309e779-4093-463b-a334-42332c39ec94");
  var regionTextController = TextEditingController(text: "beta");
  var companyNameTextController =
      TextEditingController(text: "Yurii's company");
  var jwtTokenTextController = TextEditingController(text: "");
  var accessTokenTextController = TextEditingController(text: "");
  var visitorInfoIdTextController = TextEditingController(text: "");

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Container(
            padding: const EdgeInsets.all(16),
            child: ListView(
              children: [
                Column(
                  children: [
                    TextField(
                      controller: apikeyIdTextController,
                      decoration: const InputDecoration(
                          hintText: "site api key id",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: apikeySecretTextController,
                      decoration: const InputDecoration(
                          hintText: "site api key secret",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: siteIdTextController,
                      decoration: const InputDecoration(
                          hintText: "site id",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: queueIdTextController,
                      decoration: const InputDecoration(
                          hintText: "queue id",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: regionTextController,
                      decoration: const InputDecoration(
                          hintText: "region id",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: companyNameTextController,
                      decoration: const InputDecoration(
                          hintText: "company name",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    Text(_sdkStatus),
                    CupertinoButton.filled(
                      onPressed: configure,
                      child: const Text("Configure"),
                    ),
                    const SizedBox(height: 16),
                    CupertinoButton.filled(
                      onPressed: startChatEngagement,
                      child: const Text("Start engagement"),
                    ),
                    const SizedBox(height: 16),
                    CupertinoButton.filled(
                        onPressed: showVisitorCodeViewController,
                        child: const Text("Get Visitor Code")),
                    const SizedBox(height: 16),
                    TextField(
                      controller: jwtTokenTextController,
                      decoration: const InputDecoration(
                          hintText: "integrator authentication token",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    TextField(
                      controller: accessTokenTextController,
                      decoration: const InputDecoration(
                          hintText: "(Optional) access token",
                          contentPadding: EdgeInsets.all(16)),
                    ),
                    CupertinoButton.filled(
                        onPressed: authenticate,
                        child: const Text("Authenticate")),
                    const SizedBox(height: 16),
                    CupertinoButton.filled(
                        onPressed: secureConversations,
                        child: const Text("Secure Conversations")),
                    const SizedBox(height: 16),
                    CupertinoButton.filled(
                        onPressed: endEngagement,
                        child: const Text("End Engagement")),
                    const SizedBox(height: 16),
                    CupertinoButton.filled(
                        onPressed: clearVisitorSession,
                        child: const Text("Clear Visitor Session")),
                    TextField(
                        controller: visitorInfoIdTextController,
                        decoration: const InputDecoration(
                            hintText: "Visitor Info",
                            contentPadding: EdgeInsets.all(16))),
                    CupertinoButton.filled(
                        onPressed: updateVisitorInfo,
                        child: const Text("Update Visitor Info"))
                  ],
                )
              ],
            ),
          )),
    );
  }
}
0
likes
0
points
27
downloads

Publisher

verified publisherglia.com

Weekly Downloads

GliaWidgets SDK is a simple and customisable framework built on top of GliaSDK. It provides all the necessary UI components to quickly integrate GliaSDK into your project.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on widgets_sdk_flutter

Packages that implement widgets_sdk_flutter