fluffychat/lib/pages/chat/seen_by_row.dart

69 lines
2.3 KiB
Dart
Raw Normal View History

2021-11-13 13:06:36 +01:00
import 'package:flutter/material.dart';
2021-11-13 19:02:26 +01:00
import 'package:fluffychat/config/themes.dart';
2021-11-13 13:06:36 +01:00
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/utils/room_status_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
class SeenByRow extends StatelessWidget {
final ChatController controller;
2022-01-29 12:35:03 +01:00
const SeenByRow(this.controller, {Key? key}) : super(key: key);
2021-11-13 13:06:36 +01:00
@override
Widget build(BuildContext context) {
final seenByUsers = controller.room!.getSeenByUsers(controller.timeline!);
2021-11-13 13:06:36 +01:00
const maxAvatars = 7;
2021-11-13 19:36:39 +01:00
return Container(
width: double.infinity,
alignment: Alignment.center,
child: AnimatedContainer(
2021-11-13 19:02:26 +01:00
constraints:
const BoxConstraints(maxWidth: FluffyThemes.columnWidth * 2.5),
2021-11-13 19:36:39 +01:00
height: seenByUsers.isEmpty ? 0 : 24,
duration: seenByUsers.isEmpty
? const Duration(milliseconds: 0)
: const Duration(milliseconds: 300),
alignment: controller.timeline!.events.isNotEmpty &&
controller.timeline!.events.first.senderId ==
2021-11-13 19:36:39 +01:00
Matrix.of(context).client.userID
? Alignment.topRight
: Alignment.topLeft,
2021-11-14 11:53:43 +01:00
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 4),
2021-11-13 19:02:26 +01:00
child: Wrap(
spacing: 4,
children: [
...(seenByUsers.length > maxAvatars
? seenByUsers.sublist(0, maxAvatars)
: seenByUsers)
.map(
(user) => Avatar(
2021-11-20 10:42:23 +01:00
mxContent: user.avatarUrl,
name: user.calcDisplayname(),
2021-11-13 19:02:26 +01:00
size: 16,
fontSize: 9,
),
)
.toList(),
if (seenByUsers.length > maxAvatars)
SizedBox(
width: 16,
height: 16,
child: Material(
color: Theme.of(context).backgroundColor,
borderRadius: BorderRadius.circular(32),
child: Center(
child: Text(
'+${seenByUsers.length - maxAvatars}',
style: const TextStyle(fontSize: 9),
),
2021-11-13 13:06:36 +01:00
),
),
),
2021-11-13 19:02:26 +01:00
],
),
2021-11-13 13:06:36 +01:00
),
);
}
}