隐私设置

This commit is contained in:
2022-11-01 11:06:51 +08:00
parent 0b5d510766
commit ff612bcc56
4 changed files with 54 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ class UserInfoModel {
UserInfoModel({
required this.userId,
required this.username,
required this.privacy,
required this.nickname,
required this.avatar,
required this.address,
@@ -9,6 +10,7 @@ class UserInfoModel {
String userId;
String username;
bool privacy;
String? nickname;
String? avatar;
String? address;
@@ -16,6 +18,7 @@ class UserInfoModel {
factory UserInfoModel.fromJson(Map<String, dynamic> json) => UserInfoModel(
userId: json['user_id'].toString(),
username: json['username'],
privacy: json['privacy'],
nickname: json['nickname'],
avatar: json['avatar'],
address: json['address'],
@@ -24,6 +27,7 @@ class UserInfoModel {
factory UserInfoModel.empty() => UserInfoModel(
userId: '',
username: '',
privacy: true,
nickname: '',
avatar: '',
address: '',
@@ -32,6 +36,7 @@ class UserInfoModel {
Map<String, dynamic> toJson() => {
"userId": userId,
"username": username,
"privacy": privacy,
"nickname": nickname,
"avatar": avatar,
"address": address,

View File

@@ -49,8 +49,17 @@ class UserProvider {
(x) => SearchUserModel.fromJson(x),
),
);
} catch (err) {
UiTools.toast(err.toString());
} catch (e) {
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;
}

View File

@@ -1,5 +1,6 @@
import 'package:chat/models/user_info_model.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/services/tim/apply_service.dart';
import 'package:chat/services/tim/block_service.dart';
@@ -123,4 +124,14 @@ class AuthService extends GetxService {
_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());
}
}

View File

@@ -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:get/get_state_manager/get_state_manager.dart';
class UserSettingPrivacyPage extends StatefulWidget {
class UserSettingPrivacyPage extends StatelessWidget {
const UserSettingPrivacyPage({Key? key}) : super(key: key);
@override
_UserSettingPrivacyPageState createState() => _UserSettingPrivacyPageState();
}
class _UserSettingPrivacyPageState extends State<UserSettingPrivacyPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
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();
},
),
);
},
),
],
),
);
}
}