feat: Button to remove avatar

This commit is contained in:
Christian Pauly 2021-05-31 19:33:40 +02:00
parent ebbdf9abef
commit 2467cab539
5 changed files with 71 additions and 11 deletions

View File

@ -1228,6 +1228,21 @@
"type": "text",
"placeholders": {}
},
"pleaseChoose": "Please choose",
"@pleaseChoose": {
"type": "text",
"placeholders": {}
},
"changeYourAvatar": "Change your avatar",
"@changeYourAvatar": {
"type": "text",
"placeholders": {}
},
"removeYourAvatar": "Remove your avatar",
"@removeYourAvatar": {
"type": "text",
"placeholders": {}
},
"oopsPushError": "Oops! Unfortunately, an error occurred when setting up the push notifications.",
"@oopsPushError": {
"type": "text",

View File

@ -60,6 +60,7 @@ abstract class FluffyThemes {
),
),
popupMenuTheme: PopupMenuThemeData(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),

View File

@ -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 }

View File

@ -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,
),
),
),
],

View File

@ -51,13 +51,14 @@ class ContentBanner extends StatelessWidget {
bottom: 0,
child: Opacity(
opacity: opacity,
child: (!loading && mxContent != null)
? CachedNetworkImage(
imageUrl: src.toString(),
height: 300,
fit: BoxFit.cover,
)
: Icon(defaultIcon, size: 200),
child:
(!loading && mxContent != null && mxContent.host.isNotEmpty)
? CachedNetworkImage(
imageUrl: src.toString(),
height: 300,
fit: BoxFit.cover,
)
: Icon(defaultIcon, size: 200),
),
),
if (onEdit != null)
@ -67,6 +68,8 @@ class ContentBanner extends StatelessWidget {
child: FloatingActionButton(
mini: true,
onPressed: onEdit,
backgroundColor: Theme.of(context).backgroundColor,
foregroundColor: Theme.of(context).textTheme.bodyText1.color,
child: Icon(Icons.camera_alt_outlined),
),
),