FurryChat/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 17:57:53 +00: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 13:58:59 +00:00
static final Map<String, Profile> _presences = {};
2020-05-06 17:03:57 +00:00
2020-05-06 15:45:59 +00:00
Future<Profile> _requestProfile(BuildContext context) async {
2020-06-10 08:07:01 +00:00
_presences[presence.senderId] ??=
await Matrix.of(context).client.getProfileFromUserId(presence.senderId);
return _presences[presence.senderId];
2020-05-06 15:45:59 +00:00
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Profile>(
2020-05-06 15:45:59 +00:00
future: _requestProfile(context),
builder: (context, snapshot) {
2020-05-06 16:31:38 +00:00
if (!snapshot.hasData) return Container();
2020-04-28 12:11:56 +00:00
Uri avatarUrl;
2020-06-10 08:07:01 +00:00
var displayname = presence.senderId.localpart;
if (snapshot.hasData) {
avatarUrl = snapshot.data.avatarUrl;
displayname = snapshot.data.displayname;
}
return InkWell(
onTap: () => showDialog(
context: context,
2020-05-15 17:57:53 +00:00
builder: (c) => PresenceDialog(
presence,
avatarUrl: avatarUrl,
displayname: displayname,
),
child: Container(
width: 80,
child: Column(
children: <Widget>[
2020-05-15 17:57:53 +00:00
SizedBox(height: 9),
Avatar(avatarUrl, displayname),
Padding(
padding: const EdgeInsets.all(6.0),
child: Text(
displayname,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
);
});
}
}