隐私设置
This commit is contained in:
@@ -2,6 +2,7 @@ class UserInfoModel {
|
|||||||
UserInfoModel({
|
UserInfoModel({
|
||||||
required this.userId,
|
required this.userId,
|
||||||
required this.username,
|
required this.username,
|
||||||
|
required this.privacy,
|
||||||
required this.nickname,
|
required this.nickname,
|
||||||
required this.avatar,
|
required this.avatar,
|
||||||
required this.address,
|
required this.address,
|
||||||
@@ -9,6 +10,7 @@ class UserInfoModel {
|
|||||||
|
|
||||||
String userId;
|
String userId;
|
||||||
String username;
|
String username;
|
||||||
|
bool privacy;
|
||||||
String? nickname;
|
String? nickname;
|
||||||
String? avatar;
|
String? avatar;
|
||||||
String? address;
|
String? address;
|
||||||
@@ -16,6 +18,7 @@ class UserInfoModel {
|
|||||||
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
|
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
|
||||||
userId: json['user_id'].toString(),
|
userId: json['user_id'].toString(),
|
||||||
username: json['username'],
|
username: json['username'],
|
||||||
|
privacy: json['privacy'],
|
||||||
nickname: json['nickname'],
|
nickname: json['nickname'],
|
||||||
avatar: json['avatar'],
|
avatar: json['avatar'],
|
||||||
address: json['address'],
|
address: json['address'],
|
||||||
@@ -24,6 +27,7 @@ class UserInfoModel {
|
|||||||
factory UserInfoModel.empty() => UserInfoModel(
|
factory UserInfoModel.empty() => UserInfoModel(
|
||||||
userId: '',
|
userId: '',
|
||||||
username: '',
|
username: '',
|
||||||
|
privacy: true,
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
address: '',
|
address: '',
|
||||||
@@ -32,6 +36,7 @@ class UserInfoModel {
|
|||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"userId": userId,
|
"userId": userId,
|
||||||
"username": username,
|
"username": username,
|
||||||
|
"privacy": privacy,
|
||||||
"nickname": nickname,
|
"nickname": nickname,
|
||||||
"avatar": avatar,
|
"avatar": avatar,
|
||||||
"address": address,
|
"address": address,
|
||||||
|
|||||||
@@ -49,8 +49,17 @@ class UserProvider {
|
|||||||
(x) => SearchUserModel.fromJson(x),
|
(x) => SearchUserModel.fromJson(x),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
UiTools.toast(err.toString());
|
UiTools.toast(e.toString());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<bool?> togglePrivacy() async {
|
||||||
|
try {
|
||||||
|
return await Http.put('user/privacy');
|
||||||
|
} catch (e) {
|
||||||
|
UiTools.toast(e.toString());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:chat/models/user_info_model.dart';
|
import 'package:chat/models/user_info_model.dart';
|
||||||
import 'package:chat/providers/auth_provider.dart';
|
import 'package:chat/providers/auth_provider.dart';
|
||||||
|
import 'package:chat/providers/user_provider.dart';
|
||||||
import 'package:chat/routes/auth_routes.dart';
|
import 'package:chat/routes/auth_routes.dart';
|
||||||
import 'package:chat/services/tim/apply_service.dart';
|
import 'package:chat/services/tim/apply_service.dart';
|
||||||
import 'package:chat/services/tim/block_service.dart';
|
import 'package:chat/services/tim/block_service.dart';
|
||||||
@@ -123,4 +124,14 @@ class AuthService extends GetxService {
|
|||||||
|
|
||||||
_box.write('userInfo', userInfo.toJson());
|
_box.write('userInfo', userInfo.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 更新隐私状态
|
||||||
|
Future<void> togglePrivacy() async {
|
||||||
|
var res = await UserProvider.togglePrivacy();
|
||||||
|
if (res != null) {
|
||||||
|
userInfo.value.privacy = res;
|
||||||
|
userInfo.refresh();
|
||||||
|
}
|
||||||
|
_box.write('userInfo', userInfo.toJson());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,40 @@
|
|||||||
|
import 'package:chat/configs/app_colors.dart';
|
||||||
|
import 'package:chat/services/auth_service.dart';
|
||||||
|
import 'package:chat/views/user/widgets/link_action_item.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get_state_manager/get_state_manager.dart';
|
||||||
|
|
||||||
class UserSettingPrivacyPage extends StatefulWidget {
|
class UserSettingPrivacyPage extends StatelessWidget {
|
||||||
const UserSettingPrivacyPage({Key? key}) : super(key: key);
|
const UserSettingPrivacyPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
|
||||||
_UserSettingPrivacyPageState createState() => _UserSettingPrivacyPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _UserSettingPrivacyPageState extends State<UserSettingPrivacyPage> {
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('隐私权限'),
|
title: const Text('隐私权限'),
|
||||||
),
|
),
|
||||||
body: Container(),
|
body: Column(
|
||||||
|
children: [
|
||||||
|
const Divider(
|
||||||
|
height: 0,
|
||||||
|
color: AppColors.border,
|
||||||
|
),
|
||||||
|
GetX<AuthService>(
|
||||||
|
builder: (_) {
|
||||||
|
return LinkActionItem(
|
||||||
|
title: '允许通过搜索添加我为好友',
|
||||||
|
trailing: Switch(
|
||||||
|
value: _.userInfo.value.privacy,
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
onChanged: (e) {
|
||||||
|
_.togglePrivacy();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user