refactor: Migrate to null safety

This commit is contained in:
Krille Fear 2022-01-29 12:35:03 +01:00 • committed by Christian Pauly
commit 55f0300f9f
163 changed files with 1759 additions and 1903 deletions

View file

@ -18,34 +18,34 @@ import 'package:fluffychat/widgets/matrix.dart';
enum AliasActions { copy, delete, setCanonical }
class ChatDetails extends StatefulWidget {
const ChatDetails({Key key}) : super(key: key);
const ChatDetails({Key? key}) : super(key: key);
@override
ChatDetailsController createState() => ChatDetailsController();
}
class ChatDetailsController extends State<ChatDetails> {
List<User> members;
List<User>? members;
bool displaySettings = false;
void toggleDisplaySettings() =>
setState(() => displaySettings = !displaySettings);
String get roomId => VRouter.of(context).pathParameters['roomid'];
String? get roomId => VRouter.of(context).pathParameters['roomid'];
void setDisplaynameAction() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!)!;
final input = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).changeTheNameOfTheGroup,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
title: L10n.of(context)!.changeTheNameOfTheGroup,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
textFields: [
DialogTextField(
initialText: room.getLocalizedDisplayname(
MatrixLocals(
L10n.of(context),
L10n.of(context)!,
),
),
)
@ -58,12 +58,12 @@ class ChatDetailsController extends State<ChatDetails> {
);
if (success.error == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context).displaynameHasBeenChanged)));
SnackBar(content: Text(L10n.of(context)!.displaynameHasBeenChanged)));
}
}
void editAliases() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!);
// The current endpoint doesnt seem to be implemented in Synapse. This may
// change in the future and then we just need to switch to this api call:
@ -76,7 +76,7 @@ class ChatDetailsController extends State<ChatDetails> {
// While this is not working we use the unstable api:
final aliases = await showFutureLoadingDialog(
context: context,
future: () => room.client
future: () => room!.client
.request(
RequestType.GET,
'/client/unstable/org.matrix.msc2432/rooms/${Uri.encodeComponent(room.id)}/aliases',
@ -86,21 +86,21 @@ class ChatDetailsController extends State<ChatDetails> {
// Switch to the stable api once it is implemented.
if (aliases.error != null) return;
final adminMode = room.canSendEvent('m.room.canonical_alias');
if (aliases.result.isEmpty && (room.canonicalAlias?.isNotEmpty ?? false)) {
aliases.result.add(room.canonicalAlias);
final adminMode = room!.canSendEvent('m.room.canonical_alias');
if (aliases.result!.isEmpty && (room.canonicalAlias.isNotEmpty)) {
aliases.result!.add(room.canonicalAlias);
}
if (aliases.result.isEmpty && adminMode) {
if (aliases.result!.isEmpty && adminMode) {
return setAliasAction();
}
final select = await showConfirmationDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).editRoomAliases,
title: L10n.of(context)!.editRoomAliases,
actions: [
if (adminMode)
AlertDialogAction(label: L10n.of(context).create, key: 'new'),
...aliases.result
AlertDialogAction(label: L10n.of(context)!.create, key: 'new'),
...aliases.result!
.map((alias) => AlertDialogAction(key: alias, label: alias))
.toList(),
],
@ -114,29 +114,30 @@ class ChatDetailsController extends State<ChatDetails> {
title: select,
actions: [
AlertDialogAction(
label: L10n.of(context).copyToClipboard,
label: L10n.of(context)!.copyToClipboard,
key: AliasActions.copy,
isDefaultAction: true,
),
if (adminMode) ...{
AlertDialogAction(
label: L10n.of(context).setAsCanonicalAlias,
label: L10n.of(context)!.setAsCanonicalAlias,
key: AliasActions.setCanonical,
isDestructiveAction: true,
),
AlertDialogAction(
label: L10n.of(context).delete,
label: L10n.of(context)!.delete,
key: AliasActions.delete,
isDestructiveAction: true,
),
},
],
);
if (option == null) return;
switch (option) {
case AliasActions.copy:
await Clipboard.setData(ClipboardData(text: select));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context).copiedToClipboard)),
SnackBar(content: Text(L10n.of(context)!.copiedToClipboard)),
);
break;
case AliasActions.delete:
@ -162,21 +163,21 @@ class ChatDetailsController extends State<ChatDetails> {
}
void setAliasAction() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final domain = room.client.userID.domain;
final room = Matrix.of(context).client.getRoomById(roomId!)!;
final domain = room.client.userID!.domain;
final input = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).setInvitationLink,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
title: L10n.of(context)!.setInvitationLink,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
textFields: [
DialogTextField(
prefixText: '#',
suffixText: domain,
hintText: L10n.of(context).alias,
initialText: room.canonicalAlias?.localpart,
hintText: L10n.of(context)!.alias,
initialText: room.canonicalAlias.localpart,
)
],
);
@ -184,21 +185,21 @@ class ChatDetailsController extends State<ChatDetails> {
await showFutureLoadingDialog(
context: context,
future: () =>
room.client.setRoomAlias('#' + input.single + ':' + domain, room.id),
room.client.setRoomAlias('#' + input.single + ':' + domain!, room.id),
);
}
void setTopicAction() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!)!;
final input = await showTextInputDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context).setGroupDescription,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
title: L10n.of(context)!.setGroupDescription,
okLabel: L10n.of(context)!.ok,
cancelLabel: L10n.of(context)!.cancel,
textFields: [
DialogTextField(
hintText: L10n.of(context).setGroupDescription,
hintText: L10n.of(context)!.setGroupDescription,
initialText: room.topic,
minLines: 1,
maxLines: 4,
@ -212,7 +213,7 @@ class ChatDetailsController extends State<ChatDetails> {
);
if (success.error == null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(L10n.of(context).groupDescriptionHasBeenChanged)));
content: Text(L10n.of(context)!.groupDescriptionHasBeenChanged)));
}
}
@ -220,7 +221,7 @@ class ChatDetailsController extends State<ChatDetails> {
context: context,
future: () => Matrix.of(context)
.client
.getRoomById(roomId)
.getRoomById(roomId!)!
.setGuestAccess(guestAccess),
);
@ -229,7 +230,7 @@ class ChatDetailsController extends State<ChatDetails> {
context: context,
future: () => Matrix.of(context)
.client
.getRoomById(roomId)
.getRoomById(roomId!)!
.setHistoryVisibility(historyVisibility),
);
@ -237,12 +238,12 @@ class ChatDetailsController extends State<ChatDetails> {
context: context,
future: () => Matrix.of(context)
.client
.getRoomById(roomId)
.getRoomById(roomId!)!
.setJoinRules(joinRule),
);
void goToEmoteSettings() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!)!;
// okay, we need to test if there are any emote state events other than the default one
// if so, we need to be directed to a selection screen for which pack we want to look at
// otherwise, we just open the normal one.
@ -256,24 +257,24 @@ class ChatDetailsController extends State<ChatDetails> {
}
void setAvatarAction() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!);
final actions = [
if (PlatformInfos.isMobile)
SheetAction(
key: AvatarAction.camera,
label: L10n.of(context).openCamera,
label: L10n.of(context)!.openCamera,
isDefaultAction: true,
icon: Icons.camera_alt_outlined,
),
SheetAction(
key: AvatarAction.file,
label: L10n.of(context).openGallery,
label: L10n.of(context)!.openGallery,
icon: Icons.photo_outlined,
),
if (room?.avatar != null)
SheetAction(
key: AvatarAction.remove,
label: L10n.of(context).delete,
label: L10n.of(context)!.delete,
isDestructiveAction: true,
icon: Icons.delete_outlined,
),
@ -282,14 +283,14 @@ class ChatDetailsController extends State<ChatDetails> {
? actions.single
: await showModalActionSheet<AvatarAction>(
context: context,
title: L10n.of(context).editRoomAvatar,
title: L10n.of(context)!.editRoomAvatar,
actions: actions,
);
if (action == null) return;
if (action == AvatarAction.remove) {
await showFutureLoadingDialog(
context: context,
future: () => room.setAvatar(null),
future: () => room!.setAvatar(null),
);
return;
}
@ -309,22 +310,22 @@ class ChatDetailsController extends State<ChatDetails> {
} else {
final result =
await FilePickerCross.importFromStorage(type: FileTypeCross.image);
if (result == null) return;
if (result.fileName == null) return;
file = MatrixFile(
bytes: result.toUint8List(),
name: result.fileName,
name: result.fileName!,
);
}
await showFutureLoadingDialog(
context: context,
future: () => room.setAvatar(file),
future: () => room!.setAvatar(file),
);
}
void requestMoreMembersAction() async {
final room = Matrix.of(context).client.getRoomById(roomId);
final room = Matrix.of(context).client.getRoomById(roomId!);
final participants = await showFutureLoadingDialog(
context: context, future: () => room.requestParticipants());
context: context, future: () => room!.requestParticipants());
if (participants.error == null) {
setState(() => members = participants.result);
}
@ -334,7 +335,8 @@ class ChatDetailsController extends State<ChatDetails> {
@override
Widget build(BuildContext context) {
members ??= Matrix.of(context).client.getRoomById(roomId).getParticipants();
members ??=
Matrix.of(context).client.getRoomById(roomId!)!.getParticipants();
return SizedBox(
width: fixedWidth,
child: ChatDetailsView(this),