Skip to content

Commit

Permalink
Support get profile with URI and DisplayName for `ExpansionContac…
Browse files Browse the repository at this point in the history
…tListTile`
  • Loading branch information
nqhhdev authored and hoangdat committed Jun 20, 2023
1 parent 2065f46 commit 62dd087
Showing 1 changed file with 87 additions and 66 deletions.
153 changes: 87 additions & 66 deletions lib/pages/new_private_chat/widget/expansion_contact_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<Uri?>(
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<ProfileInformation?>(
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<Uri?> 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<ProfileInformation?> 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);
}
}
}

0 comments on commit 62dd087

Please sign in to comment.