From 4453048285c4662a9fafa7a65460903118c42e87 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 3 Nov 2024 11:02:06 +0100 Subject: [PATCH] refactor: Remove unnecessary builder widget --- lib/pages/chat/chat_event_list.dart | 25 +++++++++++++++++-------- lib/pages/chat/chat_view.dart | 15 +-------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/pages/chat/chat_event_list.dart b/lib/pages/chat/chat_event_list.dart index e5f060e5a..57ac404ab 100644 --- a/lib/pages/chat/chat_event_list.dart +++ b/lib/pages/chat/chat_event_list.dart @@ -23,9 +23,18 @@ class ChatEventList extends StatelessWidget { @override Widget build(BuildContext context) { + final timeline = controller.timeline; + if (timeline == null) { + return const Center( + child: CircularProgressIndicator.adaptive( + strokeWidth: 2, + ), + ); + } + final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0; - final events = controller.timeline!.events.filterByVisibleInGui(); + final events = timeline.events.filterByVisibleInGui(); final animateInEventIndex = controller.animateInEventIndex; // create a map of eventId --> index to greatly improve performance of @@ -55,12 +64,12 @@ class ChatEventList extends StatelessWidget { (BuildContext context, int i) { // Footer to display typing indicator and read receipts: if (i == 0) { - if (controller.timeline!.isRequestingFuture) { + if (timeline.isRequestingFuture) { return const Center( child: CircularProgressIndicator.adaptive(strokeWidth: 2), ); } - if (controller.timeline!.canRequestFuture) { + if (timeline.canRequestFuture) { return Center( child: IconButton( onPressed: controller.requestFuture, @@ -79,12 +88,12 @@ class ChatEventList extends StatelessWidget { // Request history button or progress indicator: if (i == events.length + 1) { - if (controller.timeline!.isRequestingHistory) { + if (timeline.isRequestingHistory) { return const Center( child: CircularProgressIndicator.adaptive(strokeWidth: 2), ); } - if (controller.timeline!.canRequestHistory) { + if (timeline.canRequestHistory) { return Builder( builder: (context) { WidgetsBinding.instance @@ -105,8 +114,8 @@ class ChatEventList extends StatelessWidget { // The message at this index: final event = events[i]; final animateIn = animateInEventIndex != null && - controller.timeline!.events.length > animateInEventIndex && - event == controller.timeline!.events[animateInEventIndex]; + timeline.events.length > animateInEventIndex && + event == timeline.events[animateInEventIndex]; return AutoScrollTag( key: ValueKey(event.eventId), @@ -137,7 +146,7 @@ class ChatEventList extends StatelessWidget { longPressSelect: controller.selectedEvents.isNotEmpty, selected: controller.selectedEvents .any((e) => e.eventId == event.eventId), - timeline: controller.timeline!, + timeline: timeline, displayReadMarker: i > 0 && controller.readMarkerEventId == event.eventId, nextEvent: i + 1 < events.length ? events[i + 1] : null, diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index b50e85cc3..14c70459f 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -287,20 +287,7 @@ class ChatView extends StatelessWidget { Expanded( child: GestureDetector( onTap: controller.clearSingleSelectedEvent, - child: Builder( - builder: (context) { - if (controller.timeline == null) { - return const Center( - child: CircularProgressIndicator.adaptive( - strokeWidth: 2, - ), - ); - } - return ChatEventList( - controller: controller, - ); - }, - ), + child: ChatEventList(controller: controller), ), ), if (controller.room.canSendDefaultMessages &&