refactor: Migrate to null safety
This commit is contained in:
parent
5269f04a99
commit
55f0300f9f
163 changed files with 1759 additions and 1903 deletions
|
|
@ -12,7 +12,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
import '../../utils/localized_exception_extension.dart';
|
||||
|
||||
class InvitationSelection extends StatefulWidget {
|
||||
const InvitationSelection({Key key}) : super(key: key);
|
||||
const InvitationSelection({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
InvitationSelectionController createState() =>
|
||||
|
|
@ -21,16 +21,16 @@ class InvitationSelection extends StatefulWidget {
|
|||
|
||||
class InvitationSelectionController extends State<InvitationSelection> {
|
||||
TextEditingController controller = TextEditingController();
|
||||
String currentSearchTerm;
|
||||
late String currentSearchTerm;
|
||||
bool loading = false;
|
||||
List<Profile> foundProfiles = [];
|
||||
Timer coolDown;
|
||||
Timer? coolDown;
|
||||
|
||||
String get roomId => VRouter.of(context).pathParameters['roomid'];
|
||||
String? get roomId => VRouter.of(context).pathParameters['roomid'];
|
||||
|
||||
Future<List<User>> getContacts(BuildContext context) async {
|
||||
final client = Matrix.of(context).client;
|
||||
final room = client.getRoomById(roomId);
|
||||
final room = client.getRoomById(roomId!)!;
|
||||
final participants = await room.requestParticipants();
|
||||
participants.removeWhere(
|
||||
(u) => ![Membership.join, Membership.invite].contains(u.membership),
|
||||
|
|
@ -38,7 +38,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
final participantsIds = participants.map((p) => p.stateKey).toList();
|
||||
final contacts = client.rooms
|
||||
.where((r) => r.isDirectChat)
|
||||
.map((r) => r.getUserByMXIDSync(r.directChatMatrixID))
|
||||
.map((r) => r.getUserByMXIDSync(r.directChatMatrixID!))
|
||||
.toList()
|
||||
..removeWhere((u) => participantsIds.contains(u.stateKey));
|
||||
contacts.sort(
|
||||
|
|
@ -50,14 +50,14 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
}
|
||||
|
||||
void inviteAction(BuildContext context, String id) async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!);
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.invite(id),
|
||||
future: () => room!.invite(id),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(L10n.of(context).contactHasBeenInvitedToTheGroup)));
|
||||
content: Text(L10n.of(context)!.contactHasBeenInvitedToTheGroup)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
response = await matrix.client.searchUserDirectory(text, limit: 10);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text((e as Object).toLocalizedString(context))));
|
||||
SnackBar(content: Text((e).toLocalizedString(context))));
|
||||
return;
|
||||
} finally {
|
||||
setState(() => loading = false);
|
||||
|
|
@ -99,7 +99,7 @@ class InvitationSelectionController extends State<InvitationSelection> {
|
|||
}
|
||||
final participants = Matrix.of(context)
|
||||
.client
|
||||
.getRoomById(roomId)
|
||||
.getRoomById(roomId!)!
|
||||
.getParticipants()
|
||||
.where((user) =>
|
||||
[Membership.join, Membership.invite].contains(user.membership))
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
class InvitationSelectionView extends StatelessWidget {
|
||||
final InvitationSelectionController controller;
|
||||
|
||||
const InvitationSelectionView(this.controller, {Key key}) : super(key: key);
|
||||
const InvitationSelectionView(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final room = Matrix.of(context).client.getRoomById(controller.roomId);
|
||||
final groupName =
|
||||
room.name?.isEmpty ?? false ? L10n.of(context).group : room.name;
|
||||
final room = Matrix.of(context).client.getRoomById(controller.roomId!)!;
|
||||
final groupName = room.name.isEmpty ? L10n.of(context)!.group : room.name;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: VRouter.of(context).path.startsWith('/spaces/')
|
||||
|
|
@ -27,12 +26,12 @@ class InvitationSelectionView extends StatelessWidget {
|
|||
: IconButton(
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
onPressed: () => VRouter.of(context)
|
||||
.toSegments(['rooms', controller.roomId]),
|
||||
.toSegments(['rooms', controller.roomId!]),
|
||||
),
|
||||
titleSpacing: 0,
|
||||
title: DefaultAppBarSearchField(
|
||||
autofocus: true,
|
||||
hintText: L10n.of(context).inviteContactToGroup(groupName),
|
||||
hintText: L10n.of(context)!.inviteContactToGroup(groupName),
|
||||
onChanged: controller.searchUserWithCoolDown,
|
||||
),
|
||||
),
|
||||
|
|
@ -51,7 +50,7 @@ class InvitationSelectionView extends StatelessWidget {
|
|||
),
|
||||
title: Text(
|
||||
controller.foundProfiles[i].displayName ??
|
||||
controller.foundProfiles[i].userId.localpart,
|
||||
controller.foundProfiles[i].userId.localpart!,
|
||||
),
|
||||
subtitle: Text(controller.foundProfiles[i].userId),
|
||||
onTap: () => controller.inviteAction(
|
||||
|
|
@ -66,7 +65,7 @@ class InvitationSelectionView extends StatelessWidget {
|
|||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||
);
|
||||
}
|
||||
final contacts = snapshot.data;
|
||||
final contacts = snapshot.data!;
|
||||
return ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue