1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/ui/routes/conversation_message_stats_route.dart

94 lines
2.9 KiB
Dart
Raw Normal View History

2021-03-11 16:27:20 +00:00
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/ui/routes/main_route/main_route.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Conversation message statistics route
///
/// @author Pierre Hubert
class ConversationMessageStatsRoute extends StatefulWidget {
final Conversation conv;
final ConversationMessage message;
const ConversationMessageStatsRoute({
Key? key,
required this.conv,
required this.message,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2021-03-11 16:27:20 +00:00
@override
_ConversationMessageStatsRouteState createState() =>
_ConversationMessageStatsRouteState();
}
class _ConversationMessageStatsRouteState
extends State<ConversationMessageStatsRoute> {
late UsersList _users;
2021-03-11 16:27:20 +00:00
Future<void> _init() async {
_users = await UsersHelper()
.getList(widget.conv.membersID..add(widget.message.userID));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(tr("Message statistics")!),
2021-03-11 16:27:20 +00:00
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () => MainController.of(context)!.popPage(),
2021-03-11 16:27:20 +00:00
),
),
body: AsyncScreenWidget(
onReload: _init,
onBuild: _buildScreen,
errorMessage: tr("Failed to load message information!")!),
2021-03-11 16:27:20 +00:00
);
}
List<Widget> get _firstItems => [
ListTile(
leading: Icon(Icons.access_time_rounded),
title: Text(tr("Created on")!),
2021-03-11 16:27:20 +00:00
subtitle: Text(dateTimeToString(widget.message.date)),
),
ListTile(
leading: AccountImageWidget(
user: _users.getUser(widget.message.userID),
),
title: Text(_users.getUser(widget.message.userID).fullName),
subtitle: Text(tr("Creator")!),
2021-03-11 16:27:20 +00:00
),
];
Widget _buildScreen() => ListView.builder(
itemCount: _firstItems.length + widget.conv.members!.length,
2021-03-11 16:27:20 +00:00
itemBuilder: (c, i) {
final firstItems = _firstItems;
if (i < firstItems.length) return firstItems[i];
final convMember = widget.conv.members![i - firstItems.length];
2021-03-11 16:27:20 +00:00
if (convMember.userID == widget.message.userID) return Container();
return ListTile(
leading: AccountImageWidget(
user: _users.getUser(convMember.userID),
),
title: Text(_users.getUser(convMember.userID).fullName),
subtitle: Text(convMember.lastMessageSeen < widget.message.id!
? tr("Message not seen yet")!
: tr("Message seen")!),
2021-03-11 16:27:20 +00:00
);
},
);
}