2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/invitation_selection.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
|
2021-04-13 16:25:08 +02:00
|
|
|
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-04-13 16:25:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-05-23 13:28:55 +02:00
|
|
|
import 'package:vrouter/vrouter.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;
|
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
const InvitationSelectionView(this.controller, {Key key}) : super(key: key);
|
2021-04-13 16:25:08 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-23 13:11:55 +02:00
|
|
|
final room = Matrix.of(context).client.getRoomById(controller.roomId);
|
2021-04-13 16:25:08 +02:00
|
|
|
final groupName =
|
|
|
|
room.name?.isEmpty ?? false ? L10n.of(context).group : room.name;
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-05-23 13:28:55 +02:00
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.close_outlined),
|
|
|
|
onPressed: () =>
|
2021-07-08 17:10:20 +02:00
|
|
|
VRouter.of(context).to('/rooms/${controller.roomId}'),
|
2021-05-23 13:28:55 +02:00
|
|
|
),
|
2021-04-13 16:25:08 +02:00
|
|
|
titleSpacing: 0,
|
|
|
|
title: DefaultAppBarSearchField(
|
|
|
|
autofocus: true,
|
|
|
|
hintText: L10n.of(context).inviteContactToGroup(groupName),
|
|
|
|
onChanged: controller.searchUserWithCoolDown,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: MaxWidthBody(
|
|
|
|
withScrolling: true,
|
|
|
|
child: controller.foundProfiles.isNotEmpty
|
|
|
|
? ListView.builder(
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: controller.foundProfiles.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) => ListTile(
|
|
|
|
leading: Avatar(
|
|
|
|
controller.foundProfiles[i].avatarUrl,
|
|
|
|
controller.foundProfiles[i].displayname ??
|
|
|
|
controller.foundProfiles[i].userId,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
controller.foundProfiles[i].displayname ??
|
|
|
|
controller.foundProfiles[i].userId.localpart,
|
|
|
|
),
|
|
|
|
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) {
|
|
|
|
return Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
2021-04-14 13:40:19 +02:00
|
|
|
final contacts = snapshot.data;
|
2021-04-13 16:25:08 +02:00
|
|
|
return ListView.builder(
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: contacts.length,
|
|
|
|
itemBuilder: (BuildContext context, int i) => ListTile(
|
|
|
|
leading: Avatar(
|
|
|
|
contacts[i].avatarUrl,
|
|
|
|
contacts[i].calcDisplayname(),
|
|
|
|
),
|
|
|
|
title: Text(contacts[i].calcDisplayname()),
|
|
|
|
subtitle: Text(contacts[i].id),
|
|
|
|
onTap: () =>
|
|
|
|
controller.inviteAction(context, contacts[i].id),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|