From 2f6799470cef06aed8de83b27595b21a196d3430 Mon Sep 17 00:00:00 2001 From: Krille Date: Sat, 25 Mar 2023 14:58:51 +0100 Subject: [PATCH] refactor: Client in ChatPage --- lib/pages/chat/chat.dart | 5 +++-- lib/pages/chat/chat_input_row.dart | 2 +- lib/pages/chat/chat_view.dart | 4 +--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index b64b20d6..86c0ae54 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -47,7 +47,7 @@ class Chat extends StatefulWidget { class ChatController extends State { Room? room; - Client? sendingClient; + late Client sendingClient; Timeline? timeline; @@ -250,6 +250,7 @@ class ChatController extends State { inputFocus.addListener(_inputFocusListener); _loadDraft(); super.initState(); + sendingClient = Matrix.of(context).client; } void updateView() { @@ -324,7 +325,7 @@ class ChatController extends State { TextEditingController sendController = TextEditingController(); - void setSendingClient(Client? c) { + void setSendingClient(Client c) { // first cancle typing with the old sending client if (currentlyTyping) { // no need to have the setting typing to false be blocking diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 605fbbab..a0d70ae7 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -296,7 +296,7 @@ class _ChatAccountPicker extends StatelessWidget { return Padding( padding: const EdgeInsets.all(8.0), child: FutureBuilder( - future: controller.sendingClient!.fetchOwnProfile(), + future: controller.sendingClient.fetchOwnProfile(), builder: (context, snapshot) => PopupMenuButton( onSelected: (mxid) => _popupMenuButtonSelected(mxid, context), itemBuilder: (BuildContext context) => clients diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index e4974d7c..a8e5ca85 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -139,9 +139,7 @@ class ChatView extends StatelessWidget { @override Widget build(BuildContext context) { - final client = Matrix.of(context).client; - controller.sendingClient ??= client; - controller.room = controller.sendingClient!.getRoomById(controller.roomId!); + controller.room = controller.sendingClient.getRoomById(controller.roomId!); controller.readMarkerEventId ??= controller.room!.fullyRead; if (controller.room == null) { return Scaffold(