fluffychat/lib/components/list_items/presence_list_item.dart

101 lines
3.3 KiB
Dart
Raw Normal View History

import 'package:famedlysdk/famedlysdk.dart';
2020-06-19 15:10:26 +02:00
import 'package:fluffychat/components/dialogs/presence_dialog.dart';
2020-06-18 13:39:24 +02:00
import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/views/chat.dart';
import 'package:flutter/material.dart';
import '../avatar.dart';
import '../matrix.dart';
class PresenceListItem extends StatelessWidget {
2020-06-19 15:10:26 +02:00
final Room room;
2020-06-19 15:10:26 +02:00
const PresenceListItem(this.room);
2020-06-18 13:39:24 +02: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 17:45:59 +02:00
}
@override
Widget build(BuildContext context) {
2020-06-19 15:10:26 +02:00
final user = room.getUserByMXIDSync(room.directChatMatrixID);
final presence =
Matrix.of(context).client.presences[room.directChatMatrixID];
2020-08-23 18:10:33 +02:00
final hasStatus = presence?.presence?.statusMsg != null;
2020-06-19 15:10:26 +02:00
return InkWell(
2020-09-20 14:14:46 +02:00
borderRadius: BorderRadius.circular(8),
2020-06-19 15:10:26 +02:00
onTap: () => presence?.presence?.statusMsg == null
? _startChatAction(context, user.id)
: showDialog(
context: context,
builder: (_) => PresenceDialog(
presence,
avatarUrl: user.avatarUrl,
displayname: user.calcDisplayname(),
),
),
2020-06-19 15:10:26 +02:00
child: Container(
2020-09-20 14:14:46 +02:00
width: 76,
2020-06-19 15:10:26 +02:00
child: Column(
children: <Widget>[
2020-09-20 14:14:46 +02:00
SizedBox(height: 10),
2020-06-27 13:09:21 +02:00
Container(
2020-08-23 18:10:33 +02:00
child: Stack(
children: [
Avatar(user.avatarUrl, user.calcDisplayname()),
if (presence?.presence?.currentlyActive == true)
Positioned(
bottom: 0,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.green,
),
),
),
],
),
2020-06-27 13:09:21 +02:00
decoration: BoxDecoration(
border: Border.all(
width: 1,
2020-08-23 18:10:33 +02:00
color: !hasStatus
? Theme.of(context).secondaryHeaderColor
2020-06-27 13:09:21 +02:00
: Theme.of(context).primaryColor,
),
borderRadius: BorderRadius.circular(80),
),
padding: EdgeInsets.all(2),
),
2020-06-19 15:10:26 +02:00
Padding(
2020-06-27 13:09:21 +02:00
padding: const EdgeInsets.only(left: 6.0, top: 0.0, right: 6.0),
2020-06-19 15:10:26 +02:00
child: Text(
2020-06-27 13:09:21 +02:00
user.calcDisplayname().trim().split(' ').first,
overflow: TextOverflow.clip,
2020-06-19 15:10:26 +02:00
maxLines: 1,
style: TextStyle(
2020-06-27 13:09:21 +02:00
color: Theme.of(context)
.textTheme
.bodyText2
.color
2020-08-23 18:10:33 +02:00
.withOpacity(hasStatus ? 1 : 0.66),
2020-06-24 09:42:28 +02:00
fontSize: 13,
2020-06-19 15:10:26 +02:00
),
),
),
],
),
),
);
}
}