fluffychat/lib/components/list_items/presence_list_item.dart

63 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
2020-05-15 19:57:53 +02:00
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceListItem extends StatelessWidget {
final Presence presence;
const PresenceListItem(this.presence);
2020-05-13 15:58:59 +02:00
static final Map<String, Profile> _presences = {};
2020-05-06 19:03:57 +02:00
2020-05-06 17:45:59 +02:00
Future<Profile> _requestProfile(BuildContext context) async {
2020-05-06 19:03:57 +02:00
_presences[presence.sender] ??=
await Matrix.of(context).client.getProfileFromUserId(presence.sender);
return _presences[presence.sender];
2020-05-06 17:45:59 +02:00
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Profile>(
2020-05-06 17:45:59 +02:00
future: _requestProfile(context),
builder: (context, snapshot) {
2020-05-06 18:31:38 +02:00
if (!snapshot.hasData) return Container();
2020-04-28 14:11:56 +02:00
Uri avatarUrl;
2020-05-13 15:58:59 +02:00
var displayname = presence.sender.localpart;
if (snapshot.hasData) {
avatarUrl = snapshot.data.avatarUrl;
displayname = snapshot.data.displayname;
}
return InkWell(
onTap: () => showDialog(
context: context,
2020-05-15 19:57:53 +02:00
builder: (c) => PresenceDialog(
presence,
avatarUrl: avatarUrl,
displayname: displayname,
),
child: Container(
width: 80,
child: Column(
children: <Widget>[
2020-05-15 19:57:53 +02:00
SizedBox(height: 9),
Avatar(avatarUrl, displayname),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
displayname,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
);
});
}
}