zendesk_flutter_plugin 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

Bors enabled

zendesk-flutter-plugin #

A Flutter plugin that integrates Zendesk Chat and Support Center to Flutter

Please check the example folder for a full use case of a flutter app that uses the plugin.

You can check agent status on a specific chat account, send online and offline messages, send attachments like images and videos, check if there are any unread messages from the user, get platform version, start and end a chat session with this plugin.

Getting Started #

To use this plugin, add zendesk_flutter_plugin as a dependency in your pubspec.yaml file.

Get the Crendentials for your Zendesk chat API project.

Import package:zendesk_flutter_plugin/zendesk_flutter_plugin.dart, and initiate ZendeskFlutterPlugin with your credentials.

Integration #

        final ZendeskFlutterPlugin _chatApi = ZendeskFlutterPlugin();
        await _chatApi.init("YOUR ZENDESK ACCOUNT KEY")

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference

1.0.2 (2019-10-18) #

Documentation Changes

Added usage reference on readme

  • release: Updating pubscpec.yaml description for pubspec
New Features
Bug Fixes

Adding fix for regex when parsing new messages from user on android

1.0.1 (2019-10-15) #

Documentation Changes
  • release: Changing description of the plugin
New Features
Bug Fixes

1.0.0 (2019-10-11) #

Documentation Changes
  • release: Initial release to pub dart, adding author, changelog and licenses
New Features
Bug Fixes

example/lib/main.dart

import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:zendesk_flutter_plugin/zendesk_flutter_plugin.dart';
import 'package:zendesk_flutter_plugin/chat_models.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _chatStatus = 'Uninitialized';
  String _zendeskAccountkey = '';

  final ZendeskFlutterPlugin _chatApi = ZendeskFlutterPlugin();

  StreamSubscription<ConnectionStatus> _chatConnectivitySubscription;
  StreamSubscription<AccountStatus> _chatAccountSubscription;
  StreamSubscription<List<Agent>> _chatAgentsSubscription;
  StreamSubscription<List<ChatItem>> _chatItemsSubscription;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await _chatApi.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    _chatConnectivitySubscription =
        _chatApi.onConnectionStatusChanged.listen(_chatConnectivityUpdated);
    _chatAccountSubscription =
        _chatApi.onAccountStatusChanged.listen(_chatAccountUpdated);
    _chatAgentsSubscription =
        _chatApi.onAgentsChanged.listen(_chatAgentsUpdated);
    _chatItemsSubscription =
        _chatApi.onChatItemsChanged.listen(_chatItemsUpdated);

    String chatStatus;
    try {
      await _chatApi.init(_zendeskAccountkey);
      chatStatus = 'INITIALIZED';
    } on PlatformException {
      chatStatus = 'Failed to initialize.';
    }

    // 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(() {
      _platformVersion = platformVersion;
      _chatStatus = chatStatus;
    });
  }

  @override
  void dispose() {
    _chatConnectivitySubscription.cancel();
    _chatAccountSubscription.cancel();
    _chatAgentsSubscription.cancel();
    _chatItemsSubscription.cancel();
    _chatApi.endChat();
    super.dispose();
  }

  void _chatConnectivityUpdated(ConnectionStatus status) {
    print('chatConnectivityUpdated: $status');
  }

  void _chatAccountUpdated(AccountStatus status) {
    print('chatAccountUpdated: $status');
  }

  void _chatAgentsUpdated(List<Agent> agents) {
    print('chatAgentsUpdated:');
    agents.forEach((e) => debugPrint(e.toString()));
  }

  void _chatItemsUpdated(List<ChatItem> chatLog) {
    print('chatItemsUpdated:');
    chatLog.forEach((e) => debugPrint(e.toString()));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            Text('Chat status: $_chatStatus'),
            RaisedButton(
              onPressed: () async {
                await _chatApi.startChat('Test Visitor Name',
                    department: 'Card');
              },
              child: Text("Start Chat"),
            ),
            RaisedButton(
              onPressed: () async {
                await _chatApi.sendMessage('Greeting from Visitor');
              },
              child: Text("Send Greeting Message"),
            ),
            RaisedButton(
              onPressed: () async {
                final file =
                    await ImagePicker.pickImage(source: ImageSource.gallery);
                if (file != null) {
                  try {
                    await _chatApi.sendAttachment(file.path);
                  } on PlatformException catch (e) {
                    debugPrint('An error occurred: ${e.code}');
                  }
                }
                ;
              },
              child: Text("Send Attachment"),
            ),
            RaisedButton(
              onPressed: () async {
                await _chatApi.sendChatRating(ChatRating.GOOD,
                    comment: 'Good service');
              },
              child: Text("Send GOOD Rating"),
            ),
            RaisedButton(
              onPressed: () async {
                await _chatApi.sendChatRating(ChatRating.BAD,
                    comment: 'Bad service');
              },
              child: Text("Send BAD Rating"),
            ),
            RaisedButton(
              onPressed: () async {
                await _chatApi
                    .sendOfflineMessage('Offline Greeting from Visitor');
              },
              child: Text("Send Offline Message"),
            ),
            RaisedButton(
              onPressed: () async {
                await _chatApi.endChat();
              },
              child: Text("EndChat"),
            ),
          ],
        )),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  zendesk_flutter_plugin: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:zendesk_flutter_plugin/zendesk_flutter_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

90 out of 90 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
package_info ^0.4.0+6 0.4.0+16
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test ^1.4.0