flutter_sobot 3.3.0 copy "flutter_sobot: ^3.3.0" to clipboard
flutter_sobot: ^3.3.0 copied to clipboard

sobot first flutter plugin

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_sobot/sobotsdk.dart';
import 'dart:async';
import 'package:flutter/services.dart';

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

class ZCSobotWidge extends StatefulWidget {
  @override
  ZCSobotWidgeState createState() => ZCSobotWidgeState();
}

class ZCSobotWidgeState extends State<ZCSobotWidge> {
  String newmesaage = "";
  final zhiChiSobot = SobotApi();
  var  sobotMethodChannel = MethodChannel('flutter_sobot');
  static const EventChannel eventChannel = EventChannel('sobot');

  void _onEvent(Object event) {
    print('zhichi> on Event....1 $event');
    // print(event.toString());
  }

  void _onError(Object error) {
    print('zhichi> on Error.... $error');
    print(error);
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
    // 接收 ios _channel_1 的调用, 并返回给 ios 一个数据回调
    sobotMethodChannel.setMethodCallHandler((call) {
      setState(() {
        // 此处一个 channel 可以调用很多 method,
        if (call.method == 'flutterSobotHandle') {
          print('flutterSobotHandle 收到原生的回调'+call.arguments);
          if (call.arguments['type'] == '5') {
          } else if (call.arguments['type'] == '1') {
            // 点击返回按钮回掉
          } else if (call.arguments['type'] == '4') {
            // 未读消息回掉
            final unreadNumber = call.arguments['value'];
            print(unreadNumber);
          } else if (call.arguments['type'] == '2') {
            var linkStr = call.arguments['value'];
            print('url==='+linkStr);
          }
        }
      });
        return Future.value('测试给原生 传参');
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('text'),
      ),
      body: Container(
        padding: EdgeInsets.all(32.0),
        child: Center(
          child: Column(
            children: <Widget>[
              MaterialButton(
                color: Colors.blue,
                child: Text('启动智齿'),
                onPressed: () {
                  startZhichi();
                },
              ),
              MaterialButton(
                color: Colors.blue,
                child: Text('启动客户服务中心'),
                onPressed: () {
                  openSobotHelpCenter();
                },
              ),
              MaterialButton(
                color: Colors.blue,
                child: Text('关闭智齿'),
                onPressed: () {
                  closeSobotChat();
                },
              ),
              MaterialButton(
                color: Colors.blue,
                child: Text('电商版消息中心'),
                onPressed: () {
                  openSobotHelpMallCenter();
                },
              ),
              MaterialButton(
                color: Colors.blue,
                child: Text('获取未读消息'),
                onPressed: () {
                  getUnReadMessage();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> _buildRows() {
    List<Widget> res = [];
    for (var i = 0; i < 12; i++) {
      res.add(TextButton(
        child: Text("按钮$i"),
        onPressed: () {
          print("按钮$i");
        },
      ));
    }
    return res;
  }


  Future<void> startZhichi() async {
    var params = {
      "app_key": "dd0e991266a94723af14cc23cda5e1f1",
      "api_host": "https://test.sobot.com",
      "isCustomLinkClick": true,
      "partnerid": "1554309398961004545",
      "user_nick": "ZY_34079077",
      "user_name": "ZY_34079077",
      "service_mode": 4,
      "orderStatus": 1,
      "orderCode": "240110033056N60133",
      "autoSendOrderMessage": true,
      "goodsCount": 4,
      "totalFee": 37624,
      "createTime": '1704828656000',
      "absolute_language": "en",
      "orderUrl": "/orderDetail?orderSn=240110033056N60133",
      "isEveryTimeAutoSend": true,
      // "show_permission_tips_pop":true,
      "isDebugMode": true,
      "goods": [
        {
          "name": "White / S",
          "pictureUrl": "https://dev-zhiyi-foreign-ec-1319975145.cos.ap-hongkong.myqcloud.com/ec/sku/img/shopify/1507336675259453440.jpg"
        },
        {
          "name": "Black / M",
          "pictureUrl": "https://dev-zhiyi-foreign-ec-1319975145.cos.ap-hongkong.myqcloud.com/ec/sku/img/2022-08-15/zyScale133zyScale20228215105125_1660547451025.jpg"
        }
      ]
    };
    // var params = {
    //   // "app_key": "fb3634f6c81d4e26b13a698d4fbce43f",
    //   "app_key":"e550c6e4250c4ab490f290c6d7cb5ac2",
    //   // "api_host": "https://sg.sobot.com",
    //   "isCustomLinkClick": true,
    //   "partnerid": "1554309398961004545",
    //   "user_name": "ZY_34079077",
    //   "orderStatus": 1,
    //   "orderCode": "240110033056N60133",
    //   "autoSendOrderMessage": true,
    //   "goodsCount": 2,
    //   "totalFee": 376.24,
    //   "createTime": 1704828656000,
    //   "absolute_language": "en",
    //   // "orderUrl": "/orderDetail?orderSn=240110033056N60133",
    //   "orderUrl":"https://www.sobot.com/",
    //   "isEveryTimeAutoSend": true,
    //   "isDebugMode": true,
    //   "goods": [
    //     {
    //       "name": "White / S",
    //       "pictureUrl": "https://dev-zhiyi-foreign-ec-1319975145.cos.ap-hongkong.myqcloud.com/ec/sku/img/shopify/1507336675259453440.jpg"
    //     },
    //     {
    //       "name": "Black / M",
    //       "pictureUrl": "https://dev-zhiyi-foreign-ec-1319975145.cos.ap-hongkong.myqcloud.com/ec/sku/img/2022-08-15/zyScale133zyScale20228215105125_1660547451025.jpg"
    //     }
    //   ]
    // };
    // var params = {
    //   'app_key': 'e550c6e4250c4ab490f290c6d7cb5ac2',
    //   // 'app_key': '62d864f714394f08b628b8d4c9936107',//测试
    //   // 'app_key': 'fdd8f0f6844c4a2487caa8deb8bb8163',//测试
    //   // 'api_host': 'https://api.sobot.com',
    //   // 'api_host': 'https://www.soboten.com',
    //   'partnerid': '123456789',
    //   'isOpenActiveUser':true,
    //   'robotid':'1',
    //   'faqId':3,
    //   // 'isCustomLinkClick': true,
    //   // 'user_nick': 'sobot123123123',
    //   // 'user_name': '智齿jkhkjhk',
    //   // 'user_tels': '18510002000',
    //   // 'user_emails': '123@qq.com',
    //   // 'qq': '123456789',
    //   // 'remark': '好好学习,天天向上',
    //   // 'params': {
    //   //   // 'actionType': 'to_group',
    //   //   // 'optionId': '4',
    //   //   // 'deciId': 'a457f4dfe92842f8a11d1616c1c58dc1'
    //   // },
    //   // 'service_mode': 0,
    //   // 'title_type': 1,
    //   // 'custom_title': '自定义标题',
    //   // 'is_show_custom_title': true,
    //   // 'is_show_custom_title_url': false,
    //   // 'showNotification': true,
    //   // 'isShowReturnTips': true,
    //   // 'isShowClose': true,
    //   // 'isShowCloseSatisfaction': true,
    //   // 'isCloseAfterEvaluation': true,
    //   // 'isOpenEvaluation': true,
    //   // 'hideRototEvaluationLabels':false,//隐藏机器人是评价标签
    //   // 'hideManualEvaluationLabels':false,//隐藏人工时评价标签
    //   // 'hideChatTime':true,
    //   // 'absolute_language':'en',
    //   // 'goodsTitle': '商品名字',
    //   // 'goodsLabel': '30.5\$',
    //   // 'goodsDesc': '商品描述',
    //   // 'goodsImage':
    //   //     'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png',
    //   // 'goodsLink': 'https://home.firefoxchina.cn/',
    //   // 'isSendInfoCard': true,
    //   'orderStatus': 1,
    //   'orderCode': 'v2131232132',
    //   'autoSendOrderMessage': true,
    //   'goodsCount': 2,
    //   'totalFee': 37624,
    //   'createTime': '1569491413000',
    //   'autoSendOrderMessage': true,
    //   'isSendInfoCard': true,
    //   'orderUrl': 'https://www.sobot.com/',
    //   // 'canSendLocation': true,
    //   // 'isShowTansfer': false,
    //   // 'unWordsCount': 10000,
    //   'goods': [
    //     {
    //       'name': '商品名称',
    //       'pictureUrl':
    //           'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
    //     },
    //     {
    //       'name': '商品名称',
    //       'pictureUrl':
    //           'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
    //     }
    //   ]
    // };
    final result = await zhiChiSobot.startZhichi(params);
    handleJson(result);
  }

  Future<void> openSobotHelpCenter() async {
    var params = {
      'app_key': '1c1da2c0aad047d7ba1d14ecd18ae4f6',
      'api_host': '',
      'isCustomLinkClick': true,
      'partnerid': '123456789',
      'user_nick': 'sobot123123123',
      'user_name': '智齿jkhkjhk',
      'user_tels': '18510002000',
      'user_emails': '123@qq.com',
      'qq': '123456789',
      'remark': '好好学习,天天向上',
      'params': {
        'actionType': 'to_group',
        'optionId': '4',
        'deciId': 'a457f4dfe92842f8a11d1616c1c58dc1'
      },
      'service_mode': 0,
      'title_type': 1,
      'custom_title': '自定义标题',
      'is_show_custom_title': true,
      'is_show_custom_title_url': true,
      'showNotification': true,
      'isShowReturnTips': true,
      'isShowClose': true,
      'isShowCloseSatisfaction': true,
      'isCloseAfterEvaluation': true,
      'isOpenEvaluation': true,
      'goodsTitle': '商品名字',
      'goodsLabel': '30.5\$',
      'goodsDesc': '商品描述',
      'goodsImage':
          'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png',
      'goodsLink': 'https://home.firefoxchina.cn/',
      'isSendInfoCard': true,
      'orderStatus': 1,
      'orderCode': 'v2131232132',
      'autoSendOrderMessage': true,
      'goodsCount': 2,
      'totalFee': 3034,
      'createTime': '1569491413000',
      'goods': [
        {
          'name': '商品名称',
          'pictureUrl':
              'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
        },
        {
          'name': '商品名称',
          'pictureUrl':
              'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
        }
      ]
    };
    final result = zhiChiSobot.openSobotHelpCenter(params);
    // result.then((value) => Map<String,Object>);
    handleJson(result);
  }

  Future<void> openSobotHelpMallCenter() async {
    var params = {
      'app_key': '1c1da2c0aad047d7ba1d14ecd18ae4f6',
      'api_host': '',
      'isCustomLinkClick': true,
      'partnerid': '123456789',
      'user_nick': 'sobot123123123',
      'user_name': '智齿jkhkjhk',
      'user_tels': '18510002000',
      'user_emails': '123@qq.com',
      'qq': '123456789',
      'remark': '好好学习,天天向上',
      'params': {
        'actionType': 'to_group',
        'optionId': '4',
        'deciId': 'a457f4dfe92842f8a11d1616c1c58dc1'
      },
      'isDebugMode': 1,
      'service_mode': 0,
      'title_type': 1,
      'custom_title': '自定义标题',
      'is_show_custom_title': true,
      'is_show_custom_title_url': true,
      'showNotification': true,
      'isShowReturnTips': true,
      'isShowClose': true,
      'isShowCloseSatisfaction': true,
      'isCloseAfterEvaluation': true,
      'isOpenEvaluation': true,
      'goodsTitle': '商品名字',
      'goodsLabel': '30.5\$',
      'goodsDesc': '商品描述',
      'goodsImage':
          'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png',
      'goodsLink': 'https://home.firefoxchina.cn/',
      'isSendInfoCard': true,
      'orderStatus': 1,
      'orderCode': 'v2131232132',
      'autoSendOrderMessage': true,
      'goodsCount': 2,
      'totalFee': 3034,
      'createTime': '1569491413000',
      'goods': [
        {
          'name': '商品名称',
          'pictureUrl':
              'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
        },
        {
          'name': '商品名称',
          'pictureUrl':
              'https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20200612/75574e5fa29a48458d1f57ab5489a4c5123456789/aae707c620744e92bb112de8b67cd3ed.png'
        }
      ]
    };
    final result = zhiChiSobot.openSobotHelpMallCenter(params);

    handleJson(result);
  }

  Future<void> closeSobotChat() async {
    var params = {'isClosePush':true};
    await zhiChiSobot.closeSobotChat(params);
  }

  Future<void> getUnReadMessage() async{
    var params = {'partnerid':'123456789'};
    final result = zhiChiSobot.getUnReadMessage(params);
    handleJson(result);
  }
  // Future<void> messageLinkClic() async {
  //   var params = {'isClosePush':true};
  //   final result = await zhiChiSobot.messageLinkClic();
  //   handleJson(result);
  // }

  Future<void> handleJson(json) async {
    print(json);
    setState(() {
      newmesaage = json['type'];
    });
  }
}


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: ZCSobotWidge(),
    );
  }
}

//
//************************************** 以下为用户测试数据 *************************
// import 'package:flutter/material.dart';
// import 'package:flutter_sobot/sobotsdk.dart';
// import 'zhi_chi_helper.dart';
// // import 'package:zhi_chi/zhi_chi_helper.dart';
//
// void main() {
//   runApp(const MyApp());
// }
//
// class MyApp extends StatelessWidget {
//   const MyApp();
//
//   // This widget is the root of your application.
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       title: 'Flutter Demo',
//       theme: ThemeData(
//         colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
//         useMaterial3: true,
//       ),
//       home: const MyHomePage('Flutter Demo Home Page'),
//     );
//   }
// }
//
// class MyHomePage extends StatefulWidget {
//   const MyHomePage(this.title);
//   // const MyHomePage({super.key, required this.title});
//   final String title;
//
//   @override
//   State<MyHomePage> createState() => _MyHomePageState();
// }
//
// class _MyHomePageState extends State<MyHomePage> {
//   int _counter = 0;
//
//   void _incrementCounter() {
//     setState(() {
//       _counter++;
//     });
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         backgroundColor: Theme.of(context).colorScheme.inversePrimary,
//         title: Text(widget.title),
//       ),
//       body: Column(
//         children: [
//           Expanded(
//               child: Container(
//                   height: 100,
//                   width: double.infinity,
//                   child: TextButton(
//                     child: Text("智齿"),
//                     onPressed: () {
//                       ZhiChiHelper().startService();
//                     },
//                   ))),
//           Container(
//             height: 100,
//             width: double.infinity,
//             child: Row(
//               children: _buildRows(),
//             ),
//           )
//         ],
//       ),
//       // This trailing comma makes auto-formatting nicer for build methods.
//     );
//   }
//
//   List<Widget> _buildRows() {
//     List<Widget> res = [];
//     for (var i = 0; i < 12; i++) {
//       res.add(TextButton(
//         child: Text("按钮$i"),
//         onPressed: () {
//           print("按钮$i");
//         },
//       ));
//     }
//     return res;
//   }
// }
4
likes
20
pub points
40%
popularity

Publisher

unverified uploader

sobot first flutter plugin

Homepage

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_sobot