flutter_freshchat 1.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

💬 Flutter Freshchat

A Flutter plugin for integrating Freshchat in your mobile app.

Setup #

Android #

Add this to your AndroidManifest.xml

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.example.demoapp.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/freshchat_file_provider_paths" />
</provider>

If you have migrated to AndroidX your might need change the provider attribute android:name to this:

<provider android:name="androidx.core.content.FileProvider">
</provider>

Add this to your Strings.xml located inside android/src/res/values

<string name="freshchat_file_provider_authority">com.example.demoapp.provider</string>

IOS #

  1. If you are using Objective-C in your flutter project then you will need to create a briging header between objective-C and swift to do that follow the steps below:

    • Bridging Header must be created.
    • Open the project with XCode. Then choose File -> New -> File -> Swift File.
    • A dialog will be displayed when creating the swift file(Since this file is deleted, any name can be used.).
    • XCode will ask you if you wish to create Bridging Header, click yes.
    • Make sure you have use_frameworks! in the Runner block, in ios/Podfile。
    • Make sure you have SWIFT_VERSION 4.2 selected in you XCode -> Build Settings
    • Do flutter clean.
    • Go to your ios folder, delete Podfile.lock and Pods folder and then execute pod install --repo-update
  2. Add use_frameworks! at the top of your Podfile.

  3. Add this to info.plist

    Starting with iOS 10, Apple requires developers to declare access to privacy-sensitive controls ahead of time.

    <key>NSPhotoLibraryUsageDescription</key>
    <string>To Enable access to Photo Library</string>
    <key>NSCameraUsageDescription</key>
    <string>To take Images from Camera</string>

Usage #

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

import 'package:flutter_freshchat/flutter_freshchat.dart';

Initialize the Freshchat app with appID, appKey & domain which you could get from here: Where to find App ID and App Key<br/><br/> It has following [FreshchatConfig] properties:

  • domain Each Freshchat cluster falls in to one of this domains:

  • cameraEnabled property is used to either enable or disable camera within freshchat conversation widget. It default value is set to true.

  • gallerySelectionEnabled property is used to either enable or disable gallery within freshchat conversation widget. It default value is set to true.

  • teamMemberInfoVisible property is used to show team member info within freshchat conversation widget. It default value is set to true.

  • responseExpectationEnabled property is used to show exceptions that occur within freshchat conversation widget. It default value is set to true.

  • showNotificationBanner property is used enabled or disable in-app notification banner. It default value is set to true. (NOTE: IOS only).

  • notificationSoundEnabled property is used enabled or disable in-app notification sound. It default value is set to true. (NOTE: IOS only).

await FlutterFreshchat.init(
  appID: 'YOUR_APP_ID_HERE', 
  appKey: 'YOUR_APP_KEY_HERE',
  domain: 'https://msdk.freshchat.com'
  );

Update the user info by setting by creating a FreshchatUser object

FreshchatUser user = FreshchatUser.initial();
user.email = "john@test.com";
user.firstName = "john";
user.lastName = "doe";
user.phoneCountryCode = "+91";
user.phone = "0123456789";

await FlutterFreshchat.updateUserInfo(user: user);

// Custom properties can be set by creating a Map<String, String>
Map<String, String> customProperties = Map<String, String>();
customProperties["loggedIn"] = "true";

await FlutterFreshchat.updateUserInfo(user: user, customProperties: customProperties);

Identify the user user by usin email address or any way you uniquely identify the user. externalID is required and returns a restoreID you can save it and use to restore the chats

await FlutterFreshchat.identifyUser(externalID: 'USER_UNIQUE_ID', restoreID: 'USER_RESTORE_ID');

Show conversation opens a conversation screen and also list all the other conversation if a list obejct is supplied to it. You can also pass a title for the chat screen.

await FlutterFreshchat.showConversations(tags: const [], title: 'CHAT_SCREEN_TITLE');

Send message directly within the app without opening the Freshchat interface. tag is optional.

await FlutterFreshchat.send(message: 'YOUR_MESSAGE_HERE', tag: 'YOUR_TAG_HERE');

ShowFAQs opens a FAQ screen in a grid like format as default you can change the default setting by changing this paramters.
showFaqCategoriesAsGrid = true
showContactUsOnAppBar = true
showContactUsOnFaqScreens = false
showContactUsOnFaqNotHelpful = false

await FlutterFreshchat.showFAQs();

Gets the unseen message count from freshchat you can use this to show a counter.

int count = await FlutterFreshchat.getUnreadMsgCount();

Reset user data at logout or when deemed appropriate based on user action in the app.

await FlutterFreshchat.resetUser();

Example #

Find the example wiring in the Flutter_Freshchat example application.

API details #

See the flutter_freshchat.dart for more API details

Issues and feedback #

Please file issues to send feedback or report a bug. Thank you!

1.3.2 #

  • Fixed Typos

1.3.1 #

  • Added support for domain.
  • Fixed an issue with android where Picaso was unsupported.

1.3.0 #

  • Freshchat dependency for android upgraded to 3.3.0
  • Freshchat dependency for IOS upgraded to 3.4.0

1.2.6 #

  • Fixed a issue that was causing a crash on iOS.

1.2.5 #

  • A new method added for sending message.

1.2.4 #

  • New properties added to FreshchatConfig.
  • Code documented.
  • Namespace updated.

1.2.3 #

  • Upgraded iOS sdk to 2.9.0.

1.2.2 #

  • Extra info.plist removed from freshchat.

1.2.1 #

  • Freshchat android dependency updated to version 2.9.0 from 2.4.1

1.2.0 #

  • Documentation updated

1.1.8 #

  • IOS crash fixed

1.1.7 #

  • Small type casting issues fixed with IOS plugin

1.1.6 #

  • Meta dependency removed & updated the example

1.1.5 #

  • A type checking issue in IOS plugin while updating use info fixed

1.1.4 #

  • Use application instead of activity to avoid duplicate applications

1.1.3 #

  • Fixed as issue with Map class not being imported in android

1.1.2 #

  • Added a customProperties field to the updateUserInfo method
  • Added support for IOS

1.1.1 #

  • Camera enabled option added

1.1.0 #

  • Added support for all user properties
  • Fixed an issue where installing the same plugin on multiple app would not allow the other app to install due to same ContentProvider was being used

1.0.0 #

  • Added support for IOS

0.0.3 #

  • MIT License added

0.0.2 #

  • README.md updated with links

0.0.1 #

  • Initial Release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'update_userinfo_screen.dart';
import 'package:localstorage/localstorage.dart';
import 'package:flutter_freshchat/flutter_freshchat.dart';

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

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

class _MyAppState extends State<MyApp> {
  final scaffoldKey = GlobalKey<ScaffoldState>();
  List<Item> items = [
    Item(
        text: 'Update User Info',
        onTap: (context) {
          Navigator.push(context,
              MaterialPageRoute(builder: (context) => UpdateUserInfoScreen()));
        }),
    Item(
        text: 'Identify User',
        onTap: (context) async {
          LocalStorage storage = LocalStorage('example_storage');
          //Navigate to update email ID and name screen
          String uid = await storage.getItem('uid');
          String restoreId = await storage.getItem('restoreId');
          if (uid == null) {
            Scaffold.of(context).showSnackBar(
                SnackBar(content: Text("Please update the user info")));
          } else if (restoreId == null) {
            String newRestoreId =
                await FlutterFreshchat.identifyUser(externalID: uid);
            await storage.setItem('restoreId', newRestoreId);
          } else {
            await FlutterFreshchat.identifyUser(
                externalID: uid, restoreID: restoreId);
          }
        }),
    Item(
        text: 'Show Conversation',
        onTap: (context) async {
          await FlutterFreshchat.showConversations();
        }),
    Item(
        text: 'Show FAQs',
        onTap: (context) async {
          await FlutterFreshchat.showFAQs();
        }),
    Item(
        text: 'Get Unread Message Count',
        onTap: (context) async {
          dynamic val = await FlutterFreshchat.getUnreadMsgCount();
          Scaffold.of(context)
              .showSnackBar(SnackBar(content: Text("Message count $val")));
        }),
    Item(
        text: 'Setup Notifications',
        onTap: () {
          //Navigate to update email ID and name screen
        }),
    Item(
        text: 'Reset User',
        onTap: (context) async {
          await FlutterFreshchat.resetUser();
        }),
  ];

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

  Future<void> initPlatformState() async {
    await FlutterFreshchat.init(
      appID: "c55cfd7e-b3d1-4496-a85e-bbb477bf12b4",
      appKey: "4d17dc37-4aca-4c6f-bd5d-8ae660d9cf33",
      domain: "https://msdk.freshchat.com",
      cameraEnabled: true,
      gallerySelectionEnabled: false,
      teamMemberInfoVisible: false,
      responseExpectationEnabled: false,
      showNotificationBanner: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: scaffoldKey,
        appBar: AppBar(
          title: const Text('Flutter Freshchat Example App'),
        ),
        body: ListView.builder(
          padding: const EdgeInsets.all(10.0),
          itemBuilder: (context, i) {
            return ListItem(
              item: items[i].text,
              onTap: () => items[i].onTap(context),
            );
          },
          itemCount: items.length,
        ),
      ),
    );
  }
}

class ListItem extends StatelessWidget {
  final String item;
  final Function onTap;

  ListItem({@required this.item, @required this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Card(
        child: Container(
          padding: EdgeInsets.all(8.0),
          child: Row(
            children: <Widget>[
              new CircleAvatar(
                child: Text('A'),
              ),
              Padding(padding: EdgeInsets.only(right: 10.0)),
              Text(item)
            ],
          ),
        ),
      ),
    );
  }
}

class Item {
  String text;
  Function onTap;

  Item({@required String text, @required Function onTap}) {
    this.text = text;
    this.onTap = onTap;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_freshchat: ^1.3.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:flutter_freshchat/flutter_freshchat.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_freshchat/flutter_freshchat.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_freshchat/flutter_freshchat.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_freshchat/flutter_freshchat.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_freshchat/flutter_freshchat.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_freshchat that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test