diff --git a/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart b/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart index cc8234126f..6a1d01d01b 100644 --- a/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart +++ b/lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:fluffychat/utils/string_extension.dart'; +import 'package:matrix/matrix.dart'; typedef OnExpansionListTileTap = void Function(); @@ -22,82 +23,102 @@ class ExpansionContactListTile extends StatelessWidget { Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.only(left: 8.0, top: 8.0, bottom: 12.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - FutureBuilder( - future: getAvatarUrl(context), - builder: (context, snapshot) { - return Avatar(mxContent: snapshot.data, name: contact.displayName); - }, - ), - const SizedBox( - width: 12.0, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (contact.displayName != null)...[ - IntrinsicWidth( - child: Row( - children: [ - Expanded( - child: Row( - children: [ - Flexible( - child: Text(contact.displayName!, style: TextStyle( - fontWeight: FontWeight.w700, - fontSize: 17.0, - letterSpacing: -0.15, - color: Theme.of(context).colorScheme.onSurface, - overflow: TextOverflow.ellipsis, - )), - ), - ], + child: FutureBuilder( + future: getProfiles(context), + builder: (context, snapshot) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Avatar(mxContent: snapshot.data?.avatarUrl, name: contact.displayName), + const SizedBox( + width: 12.0, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + IntrinsicWidth( + child: Row( + children: [ + Expanded( + child: Row( + children: [ + Flexible( + child: _buildDisplayName(context, snapshot.data), + ), + ], + ), ), - ), - if (contact.matrixId != null && contact.matrixId!.isCurrentMatrixId(context)) ... [ - const SizedBox(width: 8.0), - TwakeChip( - text: L10n.of(context)!.owner, - textColor: Theme.of(context).colorScheme.primary, - ) + if (contact.matrixId != null && contact.matrixId!.isCurrentMatrixId(context)) ... [ + const SizedBox(width: 8.0), + TwakeChip( + text: L10n.of(context)!.owner, + textColor: Theme.of(context).colorScheme.primary, + ) + ], + const SizedBox(width: 8.0,), + if (contact.status != null) + ContactStatusWidget(status: contact.status!,), ], - const SizedBox(width: 8.0,), - if (contact.status != null) - ContactStatusWidget(status: contact.status!,), - ], - ), - ), - ], - if (contact.matrixId != null) - Text(contact.matrixId!, - style: Theme.of(context).textTheme.labelLarge?.copyWith( - letterSpacing: 0.1, - color: LinagoraRefColors.material().neutral[30], + ), ), - ), - if (contact.email != null) - Text(contact.email!, - style: Theme.of(context).textTheme.bodyMedium?.copyWith( - letterSpacing: 0.25, - color: LinagoraRefColors.material().neutral[30], - ),) - ], - ), - ) - ], + if (contact.matrixId != null) + Text(contact.matrixId!, + style: Theme.of(context).textTheme.labelLarge?.copyWith( + letterSpacing: 0.1, + color: LinagoraRefColors.material().neutral[30], + ), + ), + if (contact.email != null) + Text(contact.email!, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + letterSpacing: 0.25, + color: LinagoraRefColors.material().neutral[30], + ),) + ], + ), + ) + ], + ); + }, ), ); } - Future getAvatarUrl(BuildContext context) async { + Widget _displayName(BuildContext context, String displayName) { + return Text( + displayName, + style: TextStyle( + fontWeight: FontWeight.w700, + fontSize: 17.0, + letterSpacing: -0.15, + color: Theme.of(context).colorScheme.onSurface, + overflow: TextOverflow.ellipsis, + ) + ); + } + + Widget _buildDisplayName(BuildContext context, ProfileInformation? profile) { + if (profile != null) { + return _displayName(context, profile.displayname!); + } else if (contact.displayName != null) { + return _displayName(context, contact.displayName!); + } else { + return const SizedBox.shrink(); + } + } + + Future getProfiles(BuildContext context) async { final client = Matrix.of(context).client; + if (contact.matrixId == null) { + return Future.error(Exception("MatrixId is null")); + } try { - return await client.getAvatarUrl(contact.matrixId!); + final profile = await client.getUserProfile(contact.matrixId!); + Logs().d("ExpansionContactListTile()::getProfiles(): ${profile.avatarUrl}"); + return profile; } catch (e) { - return Future.error(e.toString()); + return ProfileInformation(avatarUrl: null, displayname: contact.displayName); } } }