🐛 Bug fixes
This commit is contained in:
parent
f96ca899b5
commit
efc46dbbc5
@ -68,21 +68,23 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
void resetInputs() async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
final prof = await auth.getProfiles();
|
||||
_usernameController.text = prof['name'];
|
||||
_nicknameController.text = prof['nick'];
|
||||
_descriptionController.text = prof['description'];
|
||||
_firstNameController.text = prof['profile']['first_name'];
|
||||
_lastNameController.text = prof['profile']['last_name'];
|
||||
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['profile']['birthday'] != null) {
|
||||
_birthday = DateTime.parse(prof['profile']['birthday']);
|
||||
_birthdayController.text = DateFormat('yyyy-MM-dd hh:mm').format(_birthday!);
|
||||
}
|
||||
setState(() {
|
||||
_usernameController.text = prof['name'];
|
||||
_nicknameController.text = prof['nick'];
|
||||
_descriptionController.text = prof['description'];
|
||||
_firstNameController.text = prof['profile']['first_name'];
|
||||
_lastNameController.text = prof['profile']['last_name'];
|
||||
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['profile']['birthday'] != null) {
|
||||
_birthday = DateTime.parse(prof['profile']['birthday']);
|
||||
_birthdayController.text = DateFormat('yyyy-MM-dd hh:mm').format(_birthday!);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void applyChanges() async {
|
||||
@ -107,9 +109,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
);
|
||||
if (res.statusCode == 200) {
|
||||
await auth.fetchProfiles();
|
||||
setState(() {
|
||||
resetInputs();
|
||||
});
|
||||
resetInputs();
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.personalizeApplied),
|
||||
@ -122,7 +122,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
setState(() => _isSubmitting = false);
|
||||
}
|
||||
|
||||
Future<void> applyAvatar(String position) async {
|
||||
Future<void> applyImage(String position) async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
if (!await auth.isAuthorized()) return;
|
||||
|
||||
@ -139,9 +139,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
var res = await auth.client!.send(req);
|
||||
if (res.statusCode == 200) {
|
||||
await auth.fetchProfiles();
|
||||
setState(() {
|
||||
resetInputs();
|
||||
});
|
||||
resetInputs();
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.personalizeApplied),
|
||||
@ -161,9 +159,7 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
super.initState();
|
||||
|
||||
Future.delayed(Duration.zero, () {
|
||||
setState(() {
|
||||
resetInputs();
|
||||
});
|
||||
resetInputs();
|
||||
});
|
||||
}
|
||||
|
||||
@ -182,7 +178,8 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
bottom: 0,
|
||||
left: 40,
|
||||
child: FloatingActionButton.small(
|
||||
onPressed: () => applyAvatar('avatar'),
|
||||
heroTag: const Key('avatar-editor'),
|
||||
onPressed: () => applyImage('avatar'),
|
||||
child: const Icon(
|
||||
Icons.camera,
|
||||
),
|
||||
@ -222,7 +219,8 @@ class _PersonalizeScreenWidgetState extends State<PersonalizeScreenWidget> {
|
||||
bottom: 16,
|
||||
right: 16,
|
||||
child: FloatingActionButton(
|
||||
onPressed: () => applyAvatar('banner'),
|
||||
heroTag: const Key('banner-editor'),
|
||||
onPressed: () => applyImage('banner'),
|
||||
child: const Icon(
|
||||
Icons.camera_alt,
|
||||
),
|
||||
|
@ -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}/page'))
|
||||
], eagerError: true);
|
||||
final mistakeRes = res.indexWhere((x) => x.statusCode != 200);
|
||||
final mistakeRes = res.indexWhere((x) => x.statusCode != 200 && x.statusCode != 400);
|
||||
if (mistakeRes > -1) {
|
||||
var message = utf8.decode(res[0].bodyBytes);
|
||||
var message = utf8.decode(res[mistakeRes].bodyBytes);
|
||||
context.showErrorDialog(message);
|
||||
throw Exception(message);
|
||||
} else {
|
||||
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(() {
|
||||
_userinfo = info;
|
||||
_page = page;
|
||||
_page = page ??
|
||||
PersonalPage(
|
||||
id: 0,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
content: '',
|
||||
script: '',
|
||||
style: '',
|
||||
accountId: info.id,
|
||||
);
|
||||
});
|
||||
return info;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user