🐛 Bug fixes

This commit is contained in:
LittleSheep 2024-05-03 23:38:51 +08:00
parent f96ca899b5
commit efc46dbbc5
2 changed files with 38 additions and 31 deletions

View File

@ -68,21 +68,23 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
void resetInputs() async { void resetInputs() async {
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
final prof = await auth.getProfiles(); final prof = await auth.getProfiles();
_usernameController.text = prof['name']; setState(() {
_nicknameController.text = prof['nick']; _usernameController.text = prof['name'];
_descriptionController.text = prof['description']; _nicknameController.text = prof['nick'];
_firstNameController.text = prof['profile']['first_name']; _descriptionController.text = prof['description'];
_lastNameController.text = prof['profile']['last_name']; _firstNameController.text = prof['profile']['first_name'];
if (prof['avatar'] != null && prof['avatar'].isNotEmpty) { _lastNameController.text = prof['profile']['last_name'];
_avatar = getRequestUri('passport', '/api/avatar/${prof['avatar']}').toString(); if (prof['avatar'] != null && prof['avatar'].isNotEmpty) {
} _avatar = getRequestUri('passport', '/api/avatar/${prof['avatar']}').toString();
if (prof['banner'] != null && prof['banner'].isNotEmpty) { }
_banner = getRequestUri('passport', '/api/avatar/${prof['banner']}').toString(); if (prof['banner'] != null && prof['banner'].isNotEmpty) {
} _banner = getRequestUri('passport', '/api/avatar/${prof['banner']}').toString();
if (prof['profile']['birthday'] != null) { }
_birthday = DateTime.parse(prof['profile']['birthday']); if (prof['profile']['birthday'] != null) {
_birthdayController.text = DateFormat('yyyy-MM-dd hh:mm').format(_birthday!); _birthday = DateTime.parse(prof['profile']['birthday']);
} _birthdayController.text = DateFormat('yyyy-MM-dd hh:mm').format(_birthday!);
}
});
} }
void applyChanges() async { void applyChanges() async {
@ -107,9 +109,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
); );
if (res.statusCode == 200) { if (res.statusCode == 200) {
await auth.fetchProfiles(); await auth.fetchProfiles();
setState(() { resetInputs();
resetInputs();
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.personalizeApplied), content: Text(AppLocalizations.of(context)!.personalizeApplied),
@ -122,7 +122,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
setState(() => _isSubmitting = false); setState(() => _isSubmitting = false);
} }
Future<void> applyAvatar(String position) async { Future<void> applyImage(String position) async {
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
@ -139,9 +139,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
var res = await auth.client!.send(req); var res = await auth.client!.send(req);
if (res.statusCode == 200) { if (res.statusCode == 200) {
await auth.fetchProfiles(); await auth.fetchProfiles();
setState(() { resetInputs();
resetInputs();
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.personalizeApplied), content: Text(AppLocalizations.of(context)!.personalizeApplied),
@ -161,9 +159,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
super.initState(); super.initState();
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {
setState(() { resetInputs();
resetInputs();
});
}); });
} }
@ -182,7 +178,8 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
bottom: 0, bottom: 0,
left: 40, left: 40,
child: FloatingActionButton.small( child: FloatingActionButton.small(
onPressed: () => applyAvatar('avatar'), heroTag: const Key('avatar-editor'),
onPressed: () => applyImage('avatar'),
child: const Icon( child: const Icon(
Icons.camera, Icons.camera,
), ),
@ -222,7 +219,8 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
bottom: 16, bottom: 16,
right: 16, right: 16,
child: FloatingActionButton( child: FloatingActionButton(
onPressed: () => applyAvatar('banner'), heroTag: const Key('banner-editor'),
onPressed: () => applyImage('banner'),
child: const Icon( child: const Icon(
Icons.camera_alt, Icons.camera_alt,
), ),

View File

@ -32,17 +32,26 @@ class _UserInfoScreenState extends State<UserInfoScreen> {
_client.get(getRequestUri('passport', '/api/users/${widget.name}')), _client.get(getRequestUri('passport', '/api/users/${widget.name}')),
_client.get(getRequestUri('passport', '/api/users/${widget.name}/page')) _client.get(getRequestUri('passport', '/api/users/${widget.name}/page'))
], eagerError: true); ], eagerError: true);
final mistakeRes = res.indexWhere((x) => x.statusCode != 200); final mistakeRes = res.indexWhere((x) => x.statusCode != 200 && x.statusCode != 400);
if (mistakeRes > -1) { if (mistakeRes > -1) {
var message = utf8.decode(res[0].bodyBytes); var message = utf8.decode(res[mistakeRes].bodyBytes);
context.showErrorDialog(message); context.showErrorDialog(message);
throw Exception(message); throw Exception(message);
} else { } else {
final info = Account.fromJson(jsonDecode(utf8.decode(res[0].bodyBytes))); final info = Account.fromJson(jsonDecode(utf8.decode(res[0].bodyBytes)));
final page = PersonalPage.fromJson(jsonDecode(utf8.decode(res[1].bodyBytes))); final page = res[1].statusCode == 200 ? PersonalPage.fromJson(jsonDecode(utf8.decode(res[1].bodyBytes))) : null;
setState(() { setState(() {
_userinfo = info; _userinfo = info;
_page = page; _page = page ??
PersonalPage(
id: 0,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
content: '',
script: '',
style: '',
accountId: info.id,
);
}); });
return info; return info;
} }