From 9ad85504493198439673ef5d8e31375ddb2af051 Mon Sep 17 00:00:00 2001 From: noob_tea <13888774-noob_tea@users.noreply.gitlab.com> Date: Wed, 22 Mar 2023 20:28:31 +0100 Subject: [PATCH] treewide: Container -> SizedBox.shrink() This helps performance without any user-facing changes, since SizedBox is constant while Container isn't --- lib/pages/chat/chat_app_bar_title.dart | 2 +- lib/pages/chat/chat_event_list.dart | 4 ++-- lib/pages/chat/chat_input_row.dart | 4 ++-- lib/pages/chat/events/message.dart | 2 +- lib/pages/chat/input_bar.dart | 8 ++++---- lib/pages/chat/pinned_events.dart | 2 +- lib/pages/chat/reactions_picker.dart | 4 ++-- lib/pages/chat/reply_display.dart | 2 +- lib/pages/chat/sticker_picker_dialog.dart | 2 +- lib/pages/chat/tombstone_display.dart | 2 +- lib/pages/chat_details/chat_details_view.dart | 2 +- lib/pages/chat_details/participant_list_item.dart | 2 +- lib/pages/chat_list/chat_list_body.dart | 2 +- lib/pages/chat_list/chat_list_item.dart | 2 +- lib/pages/chat_list/client_chooser_button.dart | 6 +++--- lib/pages/chat_list/stories_header.dart | 2 +- lib/pages/settings_emotes/settings_emotes_view.dart | 2 +- .../settings_multiple_emotes_view.dart | 2 +- lib/pages/story/story_view.dart | 4 ++-- lib/widgets/chat_settings_popup_menu.dart | 4 ++-- lib/widgets/mxc_image.dart | 2 +- 21 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/pages/chat/chat_app_bar_title.dart b/lib/pages/chat/chat_app_bar_title.dart index cffe7411..c0bc1da8 100644 --- a/lib/pages/chat/chat_app_bar_title.dart +++ b/lib/pages/chat/chat_app_bar_title.dart @@ -17,7 +17,7 @@ class ChatAppBarTitle extends StatelessWidget { Widget build(BuildContext context) { final room = controller.room; if (room == null) { - return Container(); + return const SizedBox.shrink(); } if (controller.selectedEvents.isNotEmpty) { return Text(controller.selectedEvents.length.toString()); diff --git a/lib/pages/chat/chat_event_list.dart b/lib/pages/chat/chat_event_list.dart index 9a263bdb..0d5e7796 100644 --- a/lib/pages/chat/chat_event_list.dart +++ b/lib/pages/chat/chat_event_list.dart @@ -91,7 +91,7 @@ class ChatEventList extends StatelessWidget { ), ); } - return Container(); + return const SizedBox.shrink(); } // The message at this index: @@ -127,7 +127,7 @@ class ChatEventList extends StatelessWidget { ? controller.timeline!.events[i] : null, ) - : Container(), + : const SizedBox.shrink(), ); }, childCount: controller.timeline!.events.length + 2, diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index ec3aed36..f6394e02 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -23,7 +23,7 @@ class ChatInputRow extends StatelessWidget { Widget build(BuildContext context) { if (controller.showEmojiPicker && controller.emojiPickerType == EmojiPickerType.reaction) { - return Container(); + return const SizedBox.shrink(); } return Row( crossAxisAlignment: CrossAxisAlignment.end, @@ -72,7 +72,7 @@ class ChatInputRow extends StatelessWidget { ), ), ) - : Container(), + : const SizedBox.shrink(), ] : [ KeyBoardShortcuts( diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index 685163af..1b6c1510 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -54,7 +54,7 @@ class Message extends StatelessWidget { EventTypes.CallInvite }.contains(event.type)) { if (event.type.startsWith('m.call.')) { - return Container(); + return const SizedBox.shrink(); } return StateMessage(event); } diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index bba5fe00..fa17c7aa 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -313,7 +313,7 @@ class InputBar extends StatelessWidget { ), ); } - return Container(); + return const SizedBox.shrink(); } void insertSuggestion(_, Map suggestion) { @@ -458,11 +458,11 @@ class InputBar extends StatelessWidget { buildSuggestion(c, s, Matrix.of(context).client), onSuggestionSelected: (Map suggestion) => insertSuggestion(context, suggestion), - errorBuilder: (BuildContext context, Object? error) => Container(), - loadingBuilder: (BuildContext context) => Container(), + errorBuilder: (BuildContext context, Object? error) => const SizedBox.shrink(), + loadingBuilder: (BuildContext context) => const SizedBox.shrink(), // fix loading briefly flickering a dark box noItemsFoundBuilder: (BuildContext context) => - Container(), // fix loading briefly showing no suggestions + const SizedBox.shrink(), // fix loading briefly showing no suggestions ), ), ); diff --git a/lib/pages/chat/pinned_events.dart b/lib/pages/chat/pinned_events.dart index ba780876..210bcb76 100644 --- a/lib/pages/chat/pinned_events.dart +++ b/lib/pages/chat/pinned_events.dart @@ -49,7 +49,7 @@ class PinnedEvents extends StatelessWidget { final pinnedEventIds = controller.room!.pinnedEventIds; if (pinnedEventIds.isEmpty) { - return Container(); + return const SizedBox.shrink(); } final completers = pinnedEventIds.map>((e) { final completer = Completer(); diff --git a/lib/pages/chat/reactions_picker.dart b/lib/pages/chat/reactions_picker.dart index 37678ce3..2fc4e3f9 100644 --- a/lib/pages/chat/reactions_picker.dart +++ b/lib/pages/chat/reactions_picker.dart @@ -15,7 +15,7 @@ class ReactionsPicker extends StatelessWidget { @override Widget build(BuildContext context) { - if (controller.showEmojiPicker) return Container(); + if (controller.showEmojiPicker) return const SizedBox.shrink(); final display = controller.editEvent == null && controller.replyEvent == null && controller.room!.canSendDefaultMessages && @@ -29,7 +29,7 @@ class ReactionsPicker extends StatelessWidget { child: Builder( builder: (context) { if (!display) { - return Container(); + return const SizedBox.shrink(); } final proposals = proposeEmojis( controller.selectedEvents.first.plaintextBody, diff --git a/lib/pages/chat/reply_display.dart b/lib/pages/chat/reply_display.dart index 2f78d467..77edee1d 100644 --- a/lib/pages/chat/reply_display.dart +++ b/lib/pages/chat/reply_display.dart @@ -58,7 +58,7 @@ class _EditContent extends StatelessWidget { Widget build(BuildContext context) { final event = this.event; if (event == null) { - return Container(); + return const SizedBox.shrink(); } return Row( children: [ diff --git a/lib/pages/chat/sticker_picker_dialog.dart b/lib/pages/chat/sticker_picker_dialog.dart index 33b66a09..80cae6b5 100644 --- a/lib/pages/chat/sticker_picker_dialog.dart +++ b/lib/pages/chat/sticker_picker_dialog.dart @@ -39,7 +39,7 @@ class StickerPickerDialogState extends State { final imageKeys = filteredImagePackImageEntried.map((e) => e.key).toList(); if (imageKeys.isEmpty) { - return Container(); + return const SizedBox.shrink(); } final packName = pack.pack.displayName ?? packSlugs[packIndex]; return Column( diff --git a/lib/pages/chat/tombstone_display.dart b/lib/pages/chat/tombstone_display.dart index ad8b971b..7604ea96 100644 --- a/lib/pages/chat/tombstone_display.dart +++ b/lib/pages/chat/tombstone_display.dart @@ -12,7 +12,7 @@ class TombstoneDisplay extends StatelessWidget { @override Widget build(BuildContext context) { if (controller.room!.getState(EventTypes.RoomTombstone) == null) { - return Container(); + return const SizedBox.shrink(); } return SizedBox( height: 72, diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index 91af25e7..68f25825 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -409,7 +409,7 @@ class ChatDetailsView extends StatelessWidget { ), onTap: () => VRouter.of(context).to('invite'), ) - : Container(), + : const SizedBox.shrink(), ], ) : i < controller.members!.length + 1 diff --git a/lib/pages/chat_details/participant_list_item.dart b/lib/pages/chat_details/participant_list_item.dart index 31f3789c..63ce965b 100644 --- a/lib/pages/chat_details/participant_list_item.dart +++ b/lib/pages/chat_details/participant_list_item.dart @@ -62,7 +62,7 @@ class ParticipantListItem extends StatelessWidget { ), ), membershipBatch[user.membership]!.isEmpty - ? Container() + ? const SizedBox.shrink() : Container( padding: const EdgeInsets.all(4), margin: const EdgeInsets.symmetric(horizontal: 8), diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index d2cf84f2..8684dd9d 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -227,7 +227,7 @@ class ChatListViewBody extends StatelessWidget { .contains( controller.searchController.text.toLowerCase(), )) { - return Container(); + return const SizedBox.shrink(); } return ChatListItem( rooms[i], diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index 3d0b8eab..a53c2927 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -326,7 +326,7 @@ class ChatListItem extends StatelessWidget { fontSize: 13, ), ) - : Container(), + : const SizedBox.shrink(), ), ), ], diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 392d73cc..d2878f6e 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -189,7 +189,7 @@ class ClientChooserButton extends StatelessWidget { index, context, ), - child: Container(), + child: const SizedBox.shrink(), ), ), KeyBoardShortcuts( @@ -199,7 +199,7 @@ class ClientChooserButton extends StatelessWidget { }, helpLabel: L10n.of(context)!.nextAccount, onKeysPressed: () => _nextAccount(matrix, context), - child: Container(), + child: const SizedBox.shrink(), ), KeyBoardShortcuts( keysToPress: { @@ -209,7 +209,7 @@ class ClientChooserButton extends StatelessWidget { }, helpLabel: L10n.of(context)!.previousAccount, onKeysPressed: () => _previousAccount(matrix, context), - child: Container(), + child: const SizedBox.shrink(), ), PopupMenuButton( onSelected: (o) => _clientSelected(o, context), diff --git a/lib/pages/chat_list/stories_header.dart b/lib/pages/chat_list/stories_header.dart index f2b8ba1f..59ace5ee 100644 --- a/lib/pages/chat_list/stories_header.dart +++ b/lib/pages/chat_list/stories_header.dart @@ -121,7 +121,7 @@ class StoriesHeader extends StatelessWidget { final displayname = creator.calcDisplayname(); final avatarUrl = creator.avatarUrl; if (!displayname.toLowerCase().contains(filter.toLowerCase())) { - return Container(); + return const SizedBox.shrink(); } return _StoryButton( profile: Profile( diff --git a/lib/pages/settings_emotes/settings_emotes_view.dart b/lib/pages/settings_emotes/settings_emotes_view.dart index 88d4cda1..faee4669 100644 --- a/lib/pages/settings_emotes/settings_emotes_view.dart +++ b/lib/pages/settings_emotes/settings_emotes_view.dart @@ -107,7 +107,7 @@ class EmotesSettingsView extends StatelessWidget { ) : ListView.separated( separatorBuilder: (BuildContext context, int i) => - Container(), + const SizedBox.shrink(), itemCount: imageKeys.length + 1, itemBuilder: (BuildContext context, int i) { if (i >= imageKeys.length) { diff --git a/lib/pages/settings_multiple_emotes/settings_multiple_emotes_view.dart b/lib/pages/settings_multiple_emotes/settings_multiple_emotes_view.dart index bfb1431e..6897cc85 100644 --- a/lib/pages/settings_multiple_emotes/settings_multiple_emotes_view.dart +++ b/lib/pages/settings_multiple_emotes/settings_multiple_emotes_view.dart @@ -35,7 +35,7 @@ class MultipleEmotesSettingsView extends StatelessWidget { final keys = packs.keys.toList(); keys.sort(); return ListView.separated( - separatorBuilder: (BuildContext context, int i) => Container(), + separatorBuilder: (BuildContext context, int i) => const SizedBox.shrink(), itemCount: keys.length, itemBuilder: (BuildContext context, int i) { final event = packs[keys[i]]; diff --git a/lib/pages/story/story_view.dart b/lib/pages/story/story_view.dart index bc7315fe..3dc1e431 100644 --- a/lib/pages/story/story_view.dart +++ b/lib/pages/story/story_view.dart @@ -207,7 +207,7 @@ class StoryView extends StatelessWidget { final videoPlayerController = snapshot.data; if (videoPlayerController == null) { controller.loadingModeOn(); - return Container(); + return const SizedBox.shrink(); } controller.loadingModeOff(); return Center(child: VideoPlayer(videoPlayerController)); @@ -226,7 +226,7 @@ class StoryView extends StatelessWidget { final matrixFile = snapshot.data; if (matrixFile == null) { controller.loadingModeOn(); - return Container(); + return const SizedBox.shrink(); } controller.loadingModeOff(); return Container( diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index 1abcc6db..896b94a7 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -115,7 +115,7 @@ class ChatSettingsPopupMenuState extends State { }, helpLabel: L10n.of(context)!.chatDetails, onKeysPressed: _showChatDetails, - child: Container(), + child: const SizedBox.shrink(), ), KeyBoardShortcuts( keysToPress: { @@ -124,7 +124,7 @@ class ChatSettingsPopupMenuState extends State { }, helpLabel: L10n.of(context)!.matrixWidgets, onKeysPressed: _showWidgets, - child: Container(), + child: const SizedBox.shrink(), ), PopupMenuButton( onSelected: (String choice) async { diff --git a/lib/widgets/mxc_image.dart b/lib/widgets/mxc_image.dart index 495fb9ec..beb79425 100644 --- a/lib/widgets/mxc_image.dart +++ b/lib/widgets/mxc_image.dart @@ -163,7 +163,7 @@ class _MxcImageState extends State { data == null ? CrossFadeState.showFirst : CrossFadeState.showSecond, firstChild: placeholder(context), secondChild: data == null || data.isEmpty - ? Container() + ? const SizedBox.shrink() : Image.memory( data, width: widget.width,