fluffychat/lib/pages/chat_details/participant_list_item.dart

84 lines
2.8 KiB
Dart
Raw Normal View History

2020-01-01 19:10:13 +01:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
2020-01-01 19:10:13 +01:00
2023-01-07 10:29:34 +01:00
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
2021-11-09 21:32:16 +01:00
import '../../widgets/avatar.dart';
import '../user_bottom_sheet/user_bottom_sheet.dart';
2020-01-01 19:10:13 +01:00
class ParticipantListItem extends StatelessWidget {
final User user;
2022-01-29 12:35:03 +01:00
const ParticipantListItem(this.user, {Key? key}) : super(key: key);
2020-01-01 19:10:13 +01:00
@override
Widget build(BuildContext context) {
2021-04-14 10:37:15 +02:00
final membershipBatch = <Membership, String>{
2020-05-13 15:58:59 +02:00
Membership.join: '',
2022-01-29 12:35:03 +01:00
Membership.ban: L10n.of(context)!.banned,
Membership.invite: L10n.of(context)!.invited,
Membership.leave: L10n.of(context)!.leftTheChat,
2020-01-01 19:10:13 +01:00
};
2020-05-13 15:58:59 +02:00
final permissionBatch = user.powerLevel == 100
2022-01-29 12:35:03 +01:00
? L10n.of(context)!.admin
2020-10-02 08:56:28 +02:00
: user.powerLevel >= 50
2022-01-29 12:35:03 +01:00
? L10n.of(context)!.moderator
2020-10-02 08:56:28 +02:00
: '';
2020-02-16 11:41:08 +01:00
return Opacity(
opacity: user.membership == Membership.join ? 1 : 0.5,
child: ListTile(
2023-01-07 10:29:34 +01:00
onTap: () => showAdaptiveBottomSheet(
context: context,
builder: (c) => UserBottomSheet(
user: user,
outerContext: context,
),
2020-10-28 07:23:50 +01:00
),
title: Row(
children: <Widget>[
Text(user.calcDisplayname()),
2023-02-04 19:10:27 +01:00
if (permissionBatch.isNotEmpty)
Container(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
margin: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Theme.of(context).colorScheme.primary,
)),
child: Text(
permissionBatch,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.primary,
2020-01-01 19:10:13 +01:00
),
2023-02-04 19:10:27 +01:00
),
),
2022-01-29 12:35:03 +01:00
membershipBatch[user.membership]!.isEmpty
? Container()
: Container(
padding: const EdgeInsets.all(4),
margin: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
borderRadius: BorderRadius.circular(8),
),
child:
2022-01-29 12:35:03 +01:00
Center(child: Text(membershipBatch[user.membership]!)),
2020-01-01 19:10:13 +01:00
),
],
),
subtitle: Text(user.id),
leading:
Avatar(mxContent: user.avatarUrl, name: user.calcDisplayname()),
2020-01-01 19:10:13 +01:00
),
);
}
}