master
jack ning 2 years ago
parent 4b4af6f567
commit 6172a08d3f

@ -13,6 +13,8 @@ import 'package:flutter/material.dart';
// import 'package:vibration/vibration.dart'; // import 'package:vibration/vibration.dart';
import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audioplayers.dart';
import 'page/switch_user_page.dart';
void main() { void main() {
// runApp(MyApp()); // runApp(MyApp());
runApp(OverlaySupport( runApp(OverlaySupport(
@ -139,6 +141,16 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
})); }));
}, },
), ),
ListTile(
title: const Text('切换用户'),
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return SwitchUserPage();
}));
},
),
// ListTile( // ListTile(
// title: Text('退出登录'), // title: Text('退出登录'),
// onTap: () { // onTap: () {

@ -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<SwitchUserPage> {
// 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();
}
}

@ -46,7 +46,7 @@ dependencies:
# 请在ios/Podfile中添加use_frameworks! # 请在ios/Podfile中添加use_frameworks!
vibration: ^1.7.3 vibration: ^1.7.3
# 在线客服 https://pub.dev/packages/bytedesk_kefu # 在线客服 https://pub.dev/packages/bytedesk_kefu
bytedesk_kefu: ^1.4.0 bytedesk_kefu: ^1.4.1
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.

@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <bytedesk_kefu/bytedesk_kefu_plugin.h> #include <bytedesk_kefu/bytedesk_kefu_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
BytedeskKefuPluginRegisterWithRegistrar( BytedeskKefuPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BytedeskKefuPlugin")); registry->GetRegistrarForPlugin("BytedeskKefuPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
bytedesk_kefu bytedesk_kefu
url_launcher_windows
) )
set(PLUGIN_BUNDLED_LIBRARIES) set(PLUGIN_BUNDLED_LIBRARIES)

@ -74,6 +74,15 @@ class BytedeskKefu {
} }
} }
//
static bool isLogin() {
String? accessToken = SpUtil.getString(BytedeskConstants.accessToken);
if (accessToken!.isEmpty) {
return false;
}
return true;
}
// 访 // 访
static void anonymousLogin(String appKey, String subDomain) async { static void anonymousLogin(String appKey, String subDomain) async {
/// sp /// sp
@ -231,8 +240,8 @@ class BytedeskKefu {
} }
// //
static void startChatDefault( static void startChatDefault(BuildContext context, String uuid, String type,
BuildContext context, String uuid, String type, String title, bool isV2Robot) { String title, bool isV2Robot) {
startChat(context, uuid, type, title, '', '', isV2Robot, null); startChat(context, uuid, type, title, '', '', isV2Robot, null);
} }
@ -399,7 +408,8 @@ class BytedeskKefu {
} }
// //
static Future<User> updateProfile(String nickname, String avatar, String description) async { static Future<User> updateProfile(
String nickname, String avatar, String description) async {
return BytedeskUserHttpApi().updateProfile(nickname, avatar, description); return BytedeskUserHttpApi().updateProfile(nickname, avatar, description);
} }

Loading…
Cancel
Save