2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-04-13 16:25:08 +02:00
|
|
|
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'package:fluffychat/pages/invitation_selection/invitation_selection.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-04-13 16:25:08 +02:00
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class InvitationSelectionView extends StatelessWidget {
|
2021-04-13 16:25:08 +02:00
|
|
|
final InvitationSelectionController controller;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const InvitationSelectionView(this.controller, {Key? key}) : super(key: key);
|
2021-04-13 16:25:08 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-01-29 12:35:03 +01:00
|
|
|
final room = Matrix.of(context).client.getRoomById(controller.roomId!)!;
|
|
|
|
final groupName = room.name.isEmpty ? L10n.of(context)!.group : room.name;
|
2021-04-13 16:25:08 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-08-04 10:15:42 +02:00
|
|
|
leading: VRouter.of(context).path.startsWith('/spaces/')
|
|
|
|
? null
|
|
|
|
: IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.close_outlined),
|
2021-08-15 13:26:16 +02:00
|
|
|
onPressed: () => VRouter.of(context)
|
2022-01-29 12:35:03 +01:00
|
|
|
.toSegments(['rooms', controller.roomId!]),
|
2021-08-04 10:15:42 +02:00
|
|
|
),
|
2021-04-13 16:25:08 +02:00
|
|
|
titleSpacing: 0,
|
|
|
|
title: DefaultAppBarSearchField(
|
|
|
|
autofocus: true,
|
2022-01-29 12:35:03 +01:00
|
|
|
hintText: L10n.of(context)!.inviteContactToGroup(groupName),
|
2021-04-13 16:25:08 +02:00
|
|
|
onChanged: controller.searchUserWithCoolDown,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: MaxWidthBody(
|
|
|
|
withScrolling: true,
|
|
|
|
child: controller.foundProfiles.isNotEmpty
|
|
|
|
? ListView.builder(
|
2021-10-14 18:09:30 +02:00
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
2021-04-13 16:25:08 +02:00
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: controller.foundProfiles.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) => ListTile(
|
|
|
|
leading: Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: controller.foundProfiles[i].avatarUrl,
|
|
|
|
name: controller.foundProfiles[i].displayName ??
|
2021-04-13 16:25:08 +02:00
|
|
|
controller.foundProfiles[i].userId,
|
|
|
|
),
|
|
|
|
title: Text(
|
2021-08-18 17:24:59 +02:00
|
|
|
controller.foundProfiles[i].displayName ??
|
2022-01-29 12:35:03 +01:00
|
|
|
controller.foundProfiles[i].userId.localpart!,
|
2021-04-13 16:25:08 +02:00
|
|
|
),
|
|
|
|
subtitle: Text(controller.foundProfiles[i].userId),
|
|
|
|
onTap: () => controller.inviteAction(
|
|
|
|
context, controller.foundProfiles[i].userId),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: FutureBuilder<List<User>>(
|
|
|
|
future: controller.getContacts(context),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
2021-10-14 18:09:30 +02:00
|
|
|
return const Center(
|
2021-10-10 13:38:06 +02:00
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
2021-04-13 16:25:08 +02:00
|
|
|
);
|
|
|
|
}
|
2022-01-29 12:35:03 +01:00
|
|
|
final contacts = snapshot.data!;
|
2021-04-13 16:25:08 +02:00
|
|
|
return ListView.builder(
|
2021-10-14 18:09:30 +02:00
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
2021-04-13 16:25:08 +02:00
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: contacts.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) => ListTile(
|
|
|
|
leading: Avatar(
|
2021-11-20 10:42:23 +01:00
|
|
|
mxContent: contacts[i].avatarUrl,
|
|
|
|
name: contacts[i].calcDisplayname(),
|
2021-04-13 16:25:08 +02:00
|
|
|
),
|
|
|
|
title: Text(contacts[i].calcDisplayname()),
|
|
|
|
subtitle: Text(contacts[i].id),
|
|
|
|
onTap: () =>
|
|
|
|
controller.inviteAction(context, contacts[i].id),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|