smooch_plugin 2.0.37 copy "smooch_plugin: ^2.0.37" to clipboard
smooch_plugin: ^2.0.37 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;
  bool companySkore = true;

  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();

    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,
    );

    await smoochInit();
  }

  void smoochInit() async {
    List<String> menuItemsAllowed = [
      SKTMenuItemCamera,
      SKTMenuItemDocument,
      SKTMenuItemGallery,
      SKTMenuItemLocation,
    ];

    try {
      final bool result = await SmoochPlugin.init(
          appId: companySkore ? "5c041af62c4b1c002121dfff" : "5a03043874d36900511723cc",
          userId: companySkore ? "1124335" : "387588",
          smoochToken: companySkore
              ? "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YzA0MWIyOTQzYWVhNjAwMjI1MDVjYjMifQ.eyJzY29wZSI6ImFwcFVzZXIiLCJ1c2VySWQiOiIxMTI0MzM1IiwiaWF0IjoxNTk2MjI3NTcwfQ.K0p5edWGQZA5dC5dbJO2Rc5Q5tKbKDWm5ZVqTcmyabs"
              : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcF81YmIzN2QzOGMyYzIwMTAwMjI3M2YyMjgifQ.eyJzY29wZSI6ImFwcFVzZXIiLCJ1c2VySWQiOiIzODc1ODgiLCJpYXQiOjE1ODU1NzQ3MTJ9.5Ep8mMb5cu7-1WQh7ItXJO7UmsShZlv24pS42xkTK5s",
          chatColor: companySkore ? "#0000FF" : "#00FF00",
          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);
    } on PlatformException catch (e) {
      print('Exception: $e');
    }
  }

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

  changeCompany() async {
    await logoutSmooch();
    companySkore = !companySkore;
    await smoochInit();
  }

  @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("Logout"),
              ),
              FlatButton(
                onPressed: changeCompany,
                child: Text("Change Company"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
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