smooch_plugin 2.0.29

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

smooch_plugin #

Smooch resources on Flutter

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

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

0.0.1 #

  • TODO: Describe initial release.

1.0.4 #

* Launch navigator when receive contents

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:smooch_plugin/smooch_constants.dart';
import 'package:smooch_plugin/smooch_plugin.dart';

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

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

class _MyAppState extends State<MyApp> {
  static const String START_SMOOCH_ACTION = "android.intent.action.START_SMOOCH";
  static const _channel = MethodChannel("app_state_method_channel");

  Future<String> _startAction;
  int _count = -1;

  void _updateUnreadCount(count) {
    setState(() {
      _count = count;
    });
  }

  void _handleMessageAction(uri) {
    print(uri);
  }

  void _logoutComplete(logoutResult) {
    print("onLogoutComplete");
  }

  void _onHelpClick() {
    print("onHelpClick");
  }

  Future<void> _onPushNotification(Map<String, dynamic> userInfo) async {
    print(userInfo);
  }

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

    // _startAction = _getStartAction();
    if (mounted) initPlatformState();
  }

  Future<String> _getStartAction() async {
    try {
      return _channel.invokeMethod("getIntentAction");
    } on PlatformException catch (e) {
      print("Failed to Invoke: '${e.message}'.");
      return "unknown";
    }
  }

  Future<void> initPlatformState() async {
    SmoochPlugin.initializeChannel(
      onUpdateUnreadCount: _updateUnreadCount,
      onHandleMessageAction: _handleMessageAction,
      onLogout: _logoutComplete,
      onHelpClick: _onHelpClick,
      onPushNotification: _onPushNotification,
    );

    String chatColor = "009900";

    List<String> menuItemsAllowed = [
      SKTMenuItemCamera,
      SKTMenuItemDocument,
      SKTMenuItemGallery,
      SKTMenuItemLocation,
    ];

    //       ---- appId 5a03043874d36900511723cc
    // flutter: ---- userId 955887
    // flutter: ---- SMTK eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YmIzN2QzOGMyYzIwMTAwMjI3M2YyMjgifQ.eyJzY29wZSI6ImFwcFVzZXIiLCJ1c2VySWQiOiI5NTU4ODciLCJpYXQiOjE1ODU1ODMyMDV9.sWtWXaztpBkcVSQkAlTiW8Vy55mt35fS-TTHFVO-lgc
    try {
      final bool result = await SmoochPlugin.init(
          appId: "5a03043874d36900511723cc",
          userId: "387588",
          smoochToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YmIzN2QzOGMyYzIwMTAwMjI3M2YyMjgifQ.eyJzY29wZSI6ImFwcFVzZXIiLCJ1c2VySWQiOiIzODc1ODgiLCJpYXQiOjE1ODU1NzQ3MTJ9.5Ep8mMb5cu7-1WQh7ItXJO7UmsShZlv24pS42xkTK5s",
          // userId: "955887",
          // smoochToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YmIzN2QzOGMyYzIwMTAwMjI3M2YyMjgifQ.eyJzY29wZSI6ImFwcFVzZXIiLCJ1c2VySWQiOiI5NTU4ODciLCJpYXQiOjE1ODU1ODMyMDV9.sWtWXaztpBkcVSQkAlTiW8Vy55mt35fS-TTHFVO-lgc",
          chatColor: chatColor,
          menuItemsAllowed: menuItemsAllowed);

      print('result Initialize $result');

      if (result == false) {
        print("Failed to initialize smooch");
        return;
      }

      _startAction.then((action) {
        print("action received: $action");
        if (action == START_SMOOCH_ACTION) {
          SmoochPlugin.show(lang: "en");
        }
      });
    } on PlatformException catch (e) {
      print('Exception: $e');
    }
  }

  Future<void> showSmooch() async {
    try {
      var accessory = <String, String>{'title': 'Help', 'icon': 'no_icon', 'flow_name': 'flow_name'};

      await SmoochPlugin.show(lang: "es", sendStart: true, accessory: accessory);
//      Future.delayed(Duration(milliseconds: 5000), () async {
//        print("trying to minimize");
//        await SmoochPlugin.minimize();
//      });
    } on PlatformException catch (e) {
      print('Exception: $e');
    }
  }

  logoutSmooch() async {
    bool result  = await SmoochPlugin.logout();
    print('LOGOUT $result');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Smooch plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                onPressed: showSmooch,
                child: Text("Abrir smooch"),
              ),
              Text('Unread messages count: $_count'),
              FlatButton(
                onPressed: logoutSmooch,
                child: Text("Abrir smooch"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  smooch_plugin: ^2.0.29

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

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Format lib/smooch_constants.dart.

Run flutter format to format lib/smooch_constants.dart.

Format lib/smooch_plugin.dart.

Run flutter format to format lib/smooch_plugin.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field http://skore.dev was unreachable.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test