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.

92 lines
2.4 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();
}
class _UserInfoPageState extends State<UserInfoPage> {
String _nickname = '';
4 years ago
String _avatar = BytedeskConstants.DEFAULT_AVATA;
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();
},
),
],
).toList()),
);
}
void _getProfile() {
4 years ago
// 查询当前用户信息:昵称、头像
4 years ago
BytedeskKefu.getProfile().then((user) => {
setState(() {
3 years ago
_nickname = user.nickname!;
_avatar = user.avatar!;
4 years ago
})
});
}
void _setNickname() {
4 years ago
// 可自定义用户昵称-客服端可见
String mynickname = '自定义APP昵称flutter';
4 years ago
BytedeskKefu.updateNickname(mynickname).then((user) => {
setState(() {
_nickname = mynickname;
}),
Fluttertoast.showToast(msg: "设置昵称成功")
});
}
void _setAvatar() {
4 years ago
// 可自定义用户头像url-客服端可见
4 years ago
String myavatarurl = 'https://chainsnow.oss-cn-shenzhen.aliyuncs.com/avatars/visitor_default_avatar.png'; // 头像网址url
BytedeskKefu.updateAvatar(myavatarurl).then((user) => {
setState(() {
4 years ago
_avatar = myavatarurl;
}),
4 years ago
Fluttertoast.showToast(msg: "设置头像成功")
});
}
}