2020-05-09 10:37:06 +00:00
|
|
|
import 'package:comunic/helpers/conversations_helper.dart';
|
|
|
|
import 'package:comunic/helpers/users_helper.dart';
|
|
|
|
import 'package:comunic/lists/users_list.dart';
|
|
|
|
import 'package:comunic/models/conversation.dart';
|
|
|
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Conversation members screen
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class ConversationMembersScreen extends StatefulWidget {
|
|
|
|
final int convID;
|
|
|
|
|
|
|
|
const ConversationMembersScreen({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.convID,
|
2022-03-11 16:02:06 +00:00
|
|
|
}) : super(key: key);
|
2020-05-09 10:37:06 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_ConversationMembersScreenState createState() =>
|
|
|
|
_ConversationMembersScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConversationMembersScreenState extends State<ConversationMembersScreen> {
|
2022-03-10 18:39:57 +00:00
|
|
|
late Conversation _conversation;
|
|
|
|
late UsersList _members;
|
2020-05-09 10:37:06 +00:00
|
|
|
|
|
|
|
Future<void> _refresh() async {
|
|
|
|
_conversation =
|
|
|
|
await ConversationsHelper().getSingle(widget.convID, force: true);
|
2021-03-10 16:54:41 +00:00
|
|
|
_members = await UsersHelper().getListWithThrow(_conversation.membersID);
|
2020-05-09 10:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2022-03-10 18:39:57 +00:00
|
|
|
appBar: AppBar(title: Text(tr("Conversation members")!)),
|
2020-05-09 10:37:06 +00:00
|
|
|
body: AsyncScreenWidget(
|
|
|
|
onReload: _refresh,
|
|
|
|
onBuild: _buildMembersList,
|
|
|
|
errorMessage:
|
2022-03-10 18:39:57 +00:00
|
|
|
tr("Could not load the list of members of this conversation!")!,
|
2020-05-09 10:37:06 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildMembersList() => ListView.builder(
|
|
|
|
itemBuilder: _buildItem,
|
2022-03-10 18:39:57 +00:00
|
|
|
itemCount: _conversation.members!.length,
|
2020-05-09 10:37:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Widget _buildItem(BuildContext context, int index) {
|
2022-03-10 18:39:57 +00:00
|
|
|
final member = _conversation.members![index];
|
2021-03-10 16:54:41 +00:00
|
|
|
final user = _members.getUser(member.userID);
|
2020-05-09 10:37:06 +00:00
|
|
|
return ListTile(
|
|
|
|
leading: AccountImageWidget(user: user),
|
|
|
|
title: Text(user.displayName),
|
2022-03-10 18:39:57 +00:00
|
|
|
subtitle: Text(member.isAdmin ? tr("Admin")! : tr("Member")!),
|
2020-05-09 10:37:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|