smooch_plugin 2.0.28 copy "smooch_plugin: ^2.0.28" to clipboard
smooch_plugin: ^2.0.28 copied to clipboard

outdated

Smooch resources on Flutter

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"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Smooch resources on Flutter

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on smooch_plugin