You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.3 KiB

4 years ago
import 'package:bytedesk_kefu/bytedesk_kefu.dart';
4 years ago
import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
4 years ago
// 需要首先调用anonymousLogin之后再调用此接口
4 years ago
// 自定义用户信息接口-对接APP用户信息
class UserInfoPage extends StatefulWidget {
3 years ago
UserInfoPage({Key? key}) : super(key: key);
4 years ago
@override
_UserInfoPageState createState() => _UserInfoPageState();
}
3 years ago
4 years ago
class _UserInfoPageState extends State<UserInfoPage> {
3 years ago
String _uid = ''; // 用户唯一uid
String _username = ''; // 用户唯一用户名
String _nickname = ''; // 用户昵称
String _avatar = BytedeskConstants.DEFAULT_AVATA; // 用户头像
String _description = ''; // 用户备注
4 years ago
@override
void initState() {
_getProfile();
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('设置昵称(见代码)'),
3 years ago
subtitle: Text(_nickname),
4 years ago
onTap: () {
//
_setNickname();
},
),
ListTile(
leading: Image.network(
3 years ago
_avatar,
4 years ago
height: 30,
width: 30,
),
title: Text('设置头像(见代码)'),
onTap: () {
//
_setAvatar();
},
),
3 years ago
ListTile(
title: Text('设置备注(见代码)'),
subtitle: Text(_description),
onTap: () {
//
_setDescription();
},
),
4 years ago
],
).toList()),
);
}
void _getProfile() {
4 years ago
// 查询当前用户信息:昵称、头像
4 years ago
BytedeskKefu.getProfile().then((user) => {
3 years ago
setState(() {
_uid = user.uid!;
_username = user.username!;
_nickname = user.nickname!;
_avatar = user.avatar!;
_description = user.description!;
})
});
4 years ago
}
void _setNickname() {
4 years ago
// 可自定义用户昵称-客服端可见
String mynickname = '自定义APP昵称flutter';
4 years ago
BytedeskKefu.updateNickname(mynickname).then((user) => {
3 years ago
setState(() {
_nickname = mynickname;
}),
Fluttertoast.showToast(msg: "设置昵称成功")
});
4 years ago
}
void _setAvatar() {
4 years ago
// 可自定义用户头像url-客服端可见
3 years ago
String myavatarurl =
'https://chainsnow.oss-cn-shenzhen.aliyuncs.com/avatars/visitor_default_avatar.png'; // 头像网址url
4 years ago
BytedeskKefu.updateAvatar(myavatarurl).then((user) => {
3 years ago
setState(() {
_avatar = myavatarurl;
}),
Fluttertoast.showToast(msg: "设置头像成功")
});
}
void _setDescription() {
// 可自定义用户昵称-客服端可见
String description = '自定义用户备注';
BytedeskKefu.updateDescription(description).then((user) => {
setState(() {
_description = description;
3 years ago
}),
Fluttertoast.showToast(msg: "设置备注成功")
});
4 years ago
}
}