feat: Button to remove avatar
This commit is contained in:
parent
9f91bf349c
commit
2840e62909
5 changed files with 71 additions and 11 deletions
|
|
@ -194,6 +194,37 @@ class SettingsController extends State<Settings> {
|
|||
}
|
||||
|
||||
void setAvatarAction() async {
|
||||
final action = await showConfirmationDialog<AvatarAction>(
|
||||
context: context,
|
||||
title: L10n.of(context).pleaseChoose,
|
||||
actions: [
|
||||
AlertDialogAction(
|
||||
key: AvatarAction.change,
|
||||
label: L10n.of(context).changeYourAvatar,
|
||||
isDefaultAction: true,
|
||||
),
|
||||
AlertDialogAction(
|
||||
key: AvatarAction.remove,
|
||||
label: L10n.of(context).removeYourAvatar,
|
||||
isDestructiveAction: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (action == null) return;
|
||||
final matrix = Matrix.of(context);
|
||||
if (action == AvatarAction.remove) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => matrix.client.setAvatarUrl(matrix.client.userID, null),
|
||||
);
|
||||
if (success.error == null) {
|
||||
setState(() {
|
||||
profileFuture = null;
|
||||
profile = null;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
MatrixFile file;
|
||||
if (PlatformInfos.isMobile) {
|
||||
final result = await ImagePicker().getImage(
|
||||
|
|
@ -215,7 +246,6 @@ class SettingsController extends State<Settings> {
|
|||
name: result.fileName,
|
||||
);
|
||||
}
|
||||
final matrix = Matrix.of(context);
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => matrix.client.setAvatar(file),
|
||||
|
|
@ -358,7 +388,13 @@ class SettingsController extends State<Settings> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = Matrix.of(context).client;
|
||||
profileFuture ??= client.ownProfile.then((p) {
|
||||
profileFuture ??= client
|
||||
.getProfileFromUserId(
|
||||
client.userID,
|
||||
cache: false,
|
||||
getFromRooms: false,
|
||||
)
|
||||
.then((p) {
|
||||
if (mounted) setState(() => profile = p);
|
||||
return p;
|
||||
});
|
||||
|
|
@ -377,3 +413,5 @@ class SettingsController extends State<Settings> {
|
|||
return SettingsView(this);
|
||||
}
|
||||
}
|
||||
|
||||
enum AvatarAction { change, remove }
|
||||
|
|
|
|||
|
|
@ -63,8 +63,11 @@ class SettingsView extends StatelessWidget {
|
|||
],
|
||||
backgroundColor: Theme.of(context).appBarTheme.color,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: ContentBanner(controller.profile?.avatarUrl,
|
||||
onEdit: controller.setAvatarAction),
|
||||
background: ContentBanner(
|
||||
controller.profile?.avatarUrl,
|
||||
onEdit: controller.setAvatarAction,
|
||||
defaultIcon: Icons.account_circle_outlined,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue