FurryChat/lib/components/list_items/presence_list_item.dart

62 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
2020-06-18 11:39:24 +00:00
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
2020-06-18 11:39:24 +00:00
import '../../utils/client_presence_extension.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceListItem extends StatelessWidget {
final Presence presence;
const PresenceListItem(this.presence);
2020-06-18 11:39:24 +00:00
void _startChatAction(BuildContext context, String userId) async {
final roomId = await User(userId,
room: Room(client: Matrix.of(context).client, id: ''))
.startDirectChat();
await Navigator.of(context).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(Route r) => r.isFirst);
2020-05-06 15:45:59 +00:00
}
@override
Widget build(BuildContext context) {
return FutureBuilder<Profile>(
2020-06-18 11:39:24 +00:00
future:
Matrix.of(context).client.requestProfileCached(presence.senderId),
builder: (context, snapshot) {
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;
2020-06-18 11:39:24 +00:00
displayname =
snapshot.data.displayname ?? presence.senderId.localpart;
}
return InkWell(
2020-06-18 11:39:24 +00:00
onTap: () => _startChatAction(context, presence.senderId),
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,
2020-05-15 17:57:53 +00:00
),
2020-06-18 11:39:24 +00:00
),
],
),
),
);
});
}
}