mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-30 16:29:30 +01:00
feat: Button to remove avatar
This commit is contained in:
parent
ebbdf9abef
commit
2467cab539
@ -1228,6 +1228,21 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders": {}
|
"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": "Oops! Unfortunately, an error occurred when setting up the push notifications.",
|
||||||
"@oopsPushError": {
|
"@oopsPushError": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -60,6 +60,7 @@ abstract class FluffyThemes {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
popupMenuTheme: PopupMenuThemeData(
|
popupMenuTheme: PopupMenuThemeData(
|
||||||
|
elevation: 4,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
),
|
),
|
||||||
|
@ -194,6 +194,37 @@ class SettingsController extends State<Settings> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setAvatarAction() async {
|
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;
|
MatrixFile file;
|
||||||
if (PlatformInfos.isMobile) {
|
if (PlatformInfos.isMobile) {
|
||||||
final result = await ImagePicker().getImage(
|
final result = await ImagePicker().getImage(
|
||||||
@ -215,7 +246,6 @@ class SettingsController extends State<Settings> {
|
|||||||
name: result.fileName,
|
name: result.fileName,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final matrix = Matrix.of(context);
|
|
||||||
final success = await showFutureLoadingDialog(
|
final success = await showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
future: () => matrix.client.setAvatar(file),
|
future: () => matrix.client.setAvatar(file),
|
||||||
@ -358,7 +388,13 @@ class SettingsController extends State<Settings> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final client = Matrix.of(context).client;
|
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);
|
if (mounted) setState(() => profile = p);
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
@ -377,3 +413,5 @@ class SettingsController extends State<Settings> {
|
|||||||
return SettingsView(this);
|
return SettingsView(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum AvatarAction { change, remove }
|
||||||
|
@ -63,8 +63,11 @@ class SettingsView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
backgroundColor: Theme.of(context).appBarTheme.color,
|
backgroundColor: Theme.of(context).appBarTheme.color,
|
||||||
flexibleSpace: FlexibleSpaceBar(
|
flexibleSpace: FlexibleSpaceBar(
|
||||||
background: ContentBanner(controller.profile?.avatarUrl,
|
background: ContentBanner(
|
||||||
onEdit: controller.setAvatarAction),
|
controller.profile?.avatarUrl,
|
||||||
|
onEdit: controller.setAvatarAction,
|
||||||
|
defaultIcon: Icons.account_circle_outlined,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -51,13 +51,14 @@ class ContentBanner extends StatelessWidget {
|
|||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: opacity,
|
opacity: opacity,
|
||||||
child: (!loading && mxContent != null)
|
child:
|
||||||
? CachedNetworkImage(
|
(!loading && mxContent != null && mxContent.host.isNotEmpty)
|
||||||
imageUrl: src.toString(),
|
? CachedNetworkImage(
|
||||||
height: 300,
|
imageUrl: src.toString(),
|
||||||
fit: BoxFit.cover,
|
height: 300,
|
||||||
)
|
fit: BoxFit.cover,
|
||||||
: Icon(defaultIcon, size: 200),
|
)
|
||||||
|
: Icon(defaultIcon, size: 200),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (onEdit != null)
|
if (onEdit != null)
|
||||||
@ -67,6 +68,8 @@ class ContentBanner extends StatelessWidget {
|
|||||||
child: FloatingActionButton(
|
child: FloatingActionButton(
|
||||||
mini: true,
|
mini: true,
|
||||||
onPressed: onEdit,
|
onPressed: onEdit,
|
||||||
|
backgroundColor: Theme.of(context).backgroundColor,
|
||||||
|
foregroundColor: Theme.of(context).textTheme.bodyText1.color,
|
||||||
child: Icon(Icons.camera_alt_outlined),
|
child: Icon(Icons.camera_alt_outlined),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user