2020-04-26 16:15:48 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-05-15 17:57:53 +00:00
|
|
|
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
|
2020-04-26 16:15:48 +00:00
|
|
|
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-05-06 17:03:57 +00:00
|
|
|
_presences[presence.sender] ??=
|
|
|
|
await Matrix.of(context).client.getProfileFromUserId(presence.sender);
|
|
|
|
return _presences[presence.sender];
|
2020-05-06 15:45:59 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 16:15:48 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder<Profile>(
|
2020-05-06 15:45:59 +00:00
|
|
|
future: _requestProfile(context),
|
2020-04-26 16:15:48 +00:00
|
|
|
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-05-13 13:58:59 +00:00
|
|
|
var displayname = presence.sender.localpart;
|
2020-04-26 16:15:48 +00:00
|
|
|
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(
|
2020-04-26 16:15:48 +00:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
2020-04-26 16:15:48 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|