From 29fd4a3f5f150dd0635e6957ca1a77c1452c4fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=A0=E6=96=87=E8=BD=A9?= <12812285557@qq.com> Date: Fri, 23 Dec 2022 11:59:14 +0800 Subject: [PATCH] 1.4.2 --- bytedesk_kefu/example/lib/main.dart | 11 ++ .../example/lib/page/switch_user_page.dart | 109 ++++++++++++++++++ .../lib/ui/chat/page/chat_kf_page.dart | 2 +- 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100755 bytedesk_kefu/example/lib/page/switch_user_page.dart diff --git a/bytedesk_kefu/example/lib/main.dart b/bytedesk_kefu/example/lib/main.dart index 464786e..c6401e8 100644 --- a/bytedesk_kefu/example/lib/main.dart +++ b/bytedesk_kefu/example/lib/main.dart @@ -7,6 +7,7 @@ import 'package:bytedesk_kefu_example/page/chat_type_page.dart'; import 'package:bytedesk_kefu_example/page/history_thread_page.dart'; import 'package:bytedesk_kefu_example/page/online_status_page.dart'; import 'package:bytedesk_kefu_example/page/setting_page.dart'; +import 'package:bytedesk_kefu_example/page/switch_user_page.dart'; import 'package:bytedesk_kefu_example/page/user_info_page.dart'; import 'package:overlay_support/overlay_support.dart'; import 'package:flutter/material.dart'; @@ -139,6 +140,16 @@ class _MyAppState extends State with WidgetsBindingObserver { })); }, ), + ListTile( + title: Text('切换用户'), + trailing: Icon(Icons.keyboard_arrow_right), + onTap: () { + Navigator.of(context) + .push(new MaterialPageRoute(builder: (context) { + return new SwitchUserPage(); + })); + }, + ), // ListTile( // title: Text('退出登录'), // onTap: () { diff --git a/bytedesk_kefu/example/lib/page/switch_user_page.dart b/bytedesk_kefu/example/lib/page/switch_user_page.dart new file mode 100755 index 0000000..dced185 --- /dev/null +++ b/bytedesk_kefu/example/lib/page/switch_user_page.dart @@ -0,0 +1,109 @@ +import 'package:bytedesk_kefu/bytedesk_kefu.dart'; +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +import 'user_info_page.dart'; + +// 切换用户 +class SwitchUserPage extends StatefulWidget { + SwitchUserPage({Key? key}) : super(key: key); + + @override + _SwitchUserPageState createState() => _SwitchUserPageState(); +} + +class _SwitchUserPageState extends State { + // 获取appkey,登录后台->渠道管理->Flutter->添加应用->获取appkey + String _appKey = '81f427ea-4467-4c7c-b0cd-5c0e4b51456f'; + // 获取subDomain,也即企业号:登录后台->客服管理->客服账号->企业号 + String _subDomain = "vip"; + + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('切换用户'), + elevation: 0, + ), + body: ListView( + children: ListTile.divideTiles( + context: context, + tiles: [ + ListTile( + title: Text('用户信息'), + trailing: Icon(Icons.keyboard_arrow_right), + onTap: () { + _userInfo(); + }, + ), + ListTile( + title: Text('用户1男'), + onTap: () { + _userBoyLogin(); + }, + ), + ListTile( + title: Text('用户2女'), + onTap: () { + _userGirlLogin(); + }, + ), + ListTile( + title: Text('退出登录'), + onTap: () { + _userLogout(); + }, + ), + ], + ).toList()), + ); + } + + void _userInfo() { + Navigator.of(context).push(new MaterialPageRoute(builder: (context) { + return new UserInfoPage(); + })); + } + + void _userBoyLogin() { + if (BytedeskKefu.isLogin()) { + Fluttertoast.showToast(msg: '请先退出登录'); + return; + } + _initWithUsernameAndNicknameAndAvatar( + "myflutteruserboy", + "我是帅哥flutter", + "https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/boy.png", + _appKey, + _subDomain); + } + + void _userGirlLogin() { + if (BytedeskKefu.isLogin()) { + Fluttertoast.showToast(msg: '请先退出登录'); + return; + } + Fluttertoast.showToast(msg: '登录中'); + _initWithUsernameAndNicknameAndAvatar( + "myflutterusergirl", + "我是美女flutter", + "https://bytedesk.oss-cn-shenzhen.aliyuncs.com/avatars/girl.png", + _appKey, + _subDomain); + } + + void _initWithUsernameAndNicknameAndAvatar(String username, String nickname, + String avatar, String appKey, String subDomain) { + BytedeskKefu.initWithUsernameAndNicknameAndAvatar(username, nickname, avatar, appKey, subDomain); + } + + void _userLogout() { + Fluttertoast.showToast(msg: '退出中'); + BytedeskKefu.logout(); + } +} diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart index 943547a..df1b937 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart @@ -594,7 +594,7 @@ class _ChatKFPageState extends State color: Colors.white ), // child: _textComposerWidget(), - child: _chatInput(), + child: (BytedeskUtils.isWeb || BytedeskUtils.isAndroid) ? _textComposerWidget() : _chatInput(), ), ],