mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-20 02:59:26 +01:00
63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
import 'package:famedlysdk/famedlysdk.dart';
|
|
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);
|
|
|
|
static final Map<String, Profile> _presences = {};
|
|
|
|
Future<Profile> _requestProfile(BuildContext context) async {
|
|
_presences[presence.sender] ??=
|
|
await Matrix.of(context).client.getProfileFromUserId(presence.sender);
|
|
return _presences[presence.sender];
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder<Profile>(
|
|
future: _requestProfile(context),
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) return Container();
|
|
Uri avatarUrl;
|
|
var displayname = presence.sender.localpart;
|
|
if (snapshot.hasData) {
|
|
avatarUrl = snapshot.data.avatarUrl;
|
|
displayname = snapshot.data.displayname;
|
|
}
|
|
return InkWell(
|
|
onTap: () => showDialog(
|
|
context: context,
|
|
builder: (c) => PresenceDialog(
|
|
presence,
|
|
avatarUrl: avatarUrl,
|
|
displayname: displayname,
|
|
),
|
|
child: Container(
|
|
width: 80,
|
|
child: Column(
|
|
children: <Widget>[
|
|
SizedBox(height: 9),
|
|
Avatar(avatarUrl, displayname),
|
|
Padding(
|
|
padding: const EdgeInsets.all(6.0),
|
|
child: Text(
|
|
displayname,
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|