diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index e6f77f40..b64b20d6 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -51,8 +51,6 @@ class ChatController extends State { Timeline? timeline; - MatrixState? matrix; - String? readMarkerEventId; String? get roomId => context.vRouter.pathParameters['roomid']; @@ -694,14 +692,14 @@ class ChatController extends State { } List get currentRoomBundle { - final clients = matrix!.currentBundle!; + final clients = Matrix.of(context).currentBundle!; clients.removeWhere((c) => c!.getRoomById(roomId!) == null); return clients; } bool get canRedactSelectedEvents { if (isArchived) return false; - final clients = matrix!.currentBundle; + final clients = Matrix.of(context).currentBundle; for (final event in selectedEvents) { if (event.canRedact == false && !(clients!.any((cl) => event.senderId == cl!.userID))) return false; @@ -1039,7 +1037,7 @@ class ChatController extends State { await prefs.setString('draft_$roomId', text); }); setReadMarker(); - if (text.endsWith(' ') && matrix!.hasComplexBundles) { + if (text.endsWith(' ') && Matrix.of(context).hasComplexBundles) { final clients = currentRoomBundle; for (final client in clients) { final prefix = client!.sendPrefix; diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index f6394e02..605fbbab 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -215,9 +215,9 @@ class ChatInputRow extends StatelessWidget { ), ), ), - if (controller.matrix!.isMultiAccount && - controller.matrix!.hasComplexBundles && - controller.matrix!.currentBundle!.length > 1) + if (Matrix.of(context).isMultiAccount && + Matrix.of(context).hasComplexBundles && + Matrix.of(context).currentBundle!.length > 1) Container( height: 56, alignment: Alignment.center, @@ -279,8 +279,9 @@ class _ChatAccountPicker extends StatelessWidget { const _ChatAccountPicker(this.controller, {Key? key}) : super(key: key); - void _popupMenuButtonSelected(String mxid) { - final client = controller.matrix!.currentBundle! + void _popupMenuButtonSelected(String mxid, BuildContext context) { + final client = Matrix.of(context) + .currentBundle! .firstWhere((cl) => cl!.userID == mxid, orElse: () => null); if (client == null) { Logs().w('Attempted to switch to a non-existing client $mxid'); @@ -291,14 +292,13 @@ class _ChatAccountPicker extends StatelessWidget { @override Widget build(BuildContext context) { - controller.matrix ??= Matrix.of(context); final clients = controller.currentRoomBundle; return Padding( padding: const EdgeInsets.all(8.0), child: FutureBuilder( future: controller.sendingClient!.fetchOwnProfile(), builder: (context, snapshot) => PopupMenuButton( - onSelected: _popupMenuButtonSelected, + onSelected: (mxid) => _popupMenuButtonSelected(mxid, context), itemBuilder: (BuildContext context) => clients .map( (client) => PopupMenuItem( @@ -322,7 +322,7 @@ class _ChatAccountPicker extends StatelessWidget { child: Avatar( mxContent: snapshot.data?.avatarUrl, name: snapshot.data?.displayName ?? - controller.matrix!.client.userID!.localpart, + Matrix.of(context).client.userID!.localpart, size: 20, ), ), diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index ad3f3f0b..e4974d7c 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -139,8 +139,7 @@ class ChatView extends StatelessWidget { @override Widget build(BuildContext context) { - controller.matrix ??= Matrix.of(context); - final client = controller.matrix!.client; + final client = Matrix.of(context).client; controller.sendingClient ??= client; controller.room = controller.sendingClient!.getRoomById(controller.roomId!); controller.readMarkerEventId ??= controller.room!.fullyRead;