treewide: Container -> SizedBox.shrink()

This helps performance without any user-facing changes,
since SizedBox is constant while Container isn't
This commit is contained in:
noob_tea 2023-03-22 20:28:31 +01:00
parent 8422c2bf3c
commit 9ad8550449
21 changed files with 31 additions and 31 deletions

View File

@ -17,7 +17,7 @@ class ChatAppBarTitle extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final room = controller.room; final room = controller.room;
if (room == null) { if (room == null) {
return Container(); return const SizedBox.shrink();
} }
if (controller.selectedEvents.isNotEmpty) { if (controller.selectedEvents.isNotEmpty) {
return Text(controller.selectedEvents.length.toString()); return Text(controller.selectedEvents.length.toString());

View File

@ -91,7 +91,7 @@ class ChatEventList extends StatelessWidget {
), ),
); );
} }
return Container(); return const SizedBox.shrink();
} }
// The message at this index: // The message at this index:
@ -127,7 +127,7 @@ class ChatEventList extends StatelessWidget {
? controller.timeline!.events[i] ? controller.timeline!.events[i]
: null, : null,
) )
: Container(), : const SizedBox.shrink(),
); );
}, },
childCount: controller.timeline!.events.length + 2, childCount: controller.timeline!.events.length + 2,

View File

@ -23,7 +23,7 @@ class ChatInputRow extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (controller.showEmojiPicker && if (controller.showEmojiPicker &&
controller.emojiPickerType == EmojiPickerType.reaction) { controller.emojiPickerType == EmojiPickerType.reaction) {
return Container(); return const SizedBox.shrink();
} }
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
@ -72,7 +72,7 @@ class ChatInputRow extends StatelessWidget {
), ),
), ),
) )
: Container(), : const SizedBox.shrink(),
] ]
: <Widget>[ : <Widget>[
KeyBoardShortcuts( KeyBoardShortcuts(

View File

@ -54,7 +54,7 @@ class Message extends StatelessWidget {
EventTypes.CallInvite EventTypes.CallInvite
}.contains(event.type)) { }.contains(event.type)) {
if (event.type.startsWith('m.call.')) { if (event.type.startsWith('m.call.')) {
return Container(); return const SizedBox.shrink();
} }
return StateMessage(event); return StateMessage(event);
} }

View File

@ -313,7 +313,7 @@ class InputBar extends StatelessWidget {
), ),
); );
} }
return Container(); return const SizedBox.shrink();
} }
void insertSuggestion(_, Map<String, String?> suggestion) { void insertSuggestion(_, Map<String, String?> suggestion) {
@ -458,11 +458,11 @@ class InputBar extends StatelessWidget {
buildSuggestion(c, s, Matrix.of(context).client), buildSuggestion(c, s, Matrix.of(context).client),
onSuggestionSelected: (Map<String, String?> suggestion) => onSuggestionSelected: (Map<String, String?> suggestion) =>
insertSuggestion(context, suggestion), insertSuggestion(context, suggestion),
errorBuilder: (BuildContext context, Object? error) => Container(), errorBuilder: (BuildContext context, Object? error) => const SizedBox.shrink(),
loadingBuilder: (BuildContext context) => Container(), loadingBuilder: (BuildContext context) => const SizedBox.shrink(),
// fix loading briefly flickering a dark box // fix loading briefly flickering a dark box
noItemsFoundBuilder: (BuildContext context) => noItemsFoundBuilder: (BuildContext context) =>
Container(), // fix loading briefly showing no suggestions const SizedBox.shrink(), // fix loading briefly showing no suggestions
), ),
), ),
); );

View File

@ -49,7 +49,7 @@ class PinnedEvents extends StatelessWidget {
final pinnedEventIds = controller.room!.pinnedEventIds; final pinnedEventIds = controller.room!.pinnedEventIds;
if (pinnedEventIds.isEmpty) { if (pinnedEventIds.isEmpty) {
return Container(); return const SizedBox.shrink();
} }
final completers = pinnedEventIds.map<Completer<Event?>>((e) { final completers = pinnedEventIds.map<Completer<Event?>>((e) {
final completer = Completer<Event?>(); final completer = Completer<Event?>();

View File

@ -15,7 +15,7 @@ class ReactionsPicker extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (controller.showEmojiPicker) return Container(); if (controller.showEmojiPicker) return const SizedBox.shrink();
final display = controller.editEvent == null && final display = controller.editEvent == null &&
controller.replyEvent == null && controller.replyEvent == null &&
controller.room!.canSendDefaultMessages && controller.room!.canSendDefaultMessages &&
@ -29,7 +29,7 @@ class ReactionsPicker extends StatelessWidget {
child: Builder( child: Builder(
builder: (context) { builder: (context) {
if (!display) { if (!display) {
return Container(); return const SizedBox.shrink();
} }
final proposals = proposeEmojis( final proposals = proposeEmojis(
controller.selectedEvents.first.plaintextBody, controller.selectedEvents.first.plaintextBody,

View File

@ -58,7 +58,7 @@ class _EditContent extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final event = this.event; final event = this.event;
if (event == null) { if (event == null) {
return Container(); return const SizedBox.shrink();
} }
return Row( return Row(
children: <Widget>[ children: <Widget>[

View File

@ -39,7 +39,7 @@ class StickerPickerDialogState extends State<StickerPickerDialog> {
final imageKeys = final imageKeys =
filteredImagePackImageEntried.map((e) => e.key).toList(); filteredImagePackImageEntried.map((e) => e.key).toList();
if (imageKeys.isEmpty) { if (imageKeys.isEmpty) {
return Container(); return const SizedBox.shrink();
} }
final packName = pack.pack.displayName ?? packSlugs[packIndex]; final packName = pack.pack.displayName ?? packSlugs[packIndex];
return Column( return Column(

View File

@ -12,7 +12,7 @@ class TombstoneDisplay extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (controller.room!.getState(EventTypes.RoomTombstone) == null) { if (controller.room!.getState(EventTypes.RoomTombstone) == null) {
return Container(); return const SizedBox.shrink();
} }
return SizedBox( return SizedBox(
height: 72, height: 72,

View File

@ -409,7 +409,7 @@ class ChatDetailsView extends StatelessWidget {
), ),
onTap: () => VRouter.of(context).to('invite'), onTap: () => VRouter.of(context).to('invite'),
) )
: Container(), : const SizedBox.shrink(),
], ],
) )
: i < controller.members!.length + 1 : i < controller.members!.length + 1

View File

@ -62,7 +62,7 @@ class ParticipantListItem extends StatelessWidget {
), ),
), ),
membershipBatch[user.membership]!.isEmpty membershipBatch[user.membership]!.isEmpty
? Container() ? const SizedBox.shrink()
: Container( : Container(
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(4),
margin: const EdgeInsets.symmetric(horizontal: 8), margin: const EdgeInsets.symmetric(horizontal: 8),

View File

@ -227,7 +227,7 @@ class ChatListViewBody extends StatelessWidget {
.contains( .contains(
controller.searchController.text.toLowerCase(), controller.searchController.text.toLowerCase(),
)) { )) {
return Container(); return const SizedBox.shrink();
} }
return ChatListItem( return ChatListItem(
rooms[i], rooms[i],

View File

@ -326,7 +326,7 @@ class ChatListItem extends StatelessWidget {
fontSize: 13, fontSize: 13,
), ),
) )
: Container(), : const SizedBox.shrink(),
), ),
), ),
], ],

View File

@ -189,7 +189,7 @@ class ClientChooserButton extends StatelessWidget {
index, index,
context, context,
), ),
child: Container(), child: const SizedBox.shrink(),
), ),
), ),
KeyBoardShortcuts( KeyBoardShortcuts(
@ -199,7 +199,7 @@ class ClientChooserButton extends StatelessWidget {
}, },
helpLabel: L10n.of(context)!.nextAccount, helpLabel: L10n.of(context)!.nextAccount,
onKeysPressed: () => _nextAccount(matrix, context), onKeysPressed: () => _nextAccount(matrix, context),
child: Container(), child: const SizedBox.shrink(),
), ),
KeyBoardShortcuts( KeyBoardShortcuts(
keysToPress: { keysToPress: {
@ -209,7 +209,7 @@ class ClientChooserButton extends StatelessWidget {
}, },
helpLabel: L10n.of(context)!.previousAccount, helpLabel: L10n.of(context)!.previousAccount,
onKeysPressed: () => _previousAccount(matrix, context), onKeysPressed: () => _previousAccount(matrix, context),
child: Container(), child: const SizedBox.shrink(),
), ),
PopupMenuButton<Object>( PopupMenuButton<Object>(
onSelected: (o) => _clientSelected(o, context), onSelected: (o) => _clientSelected(o, context),

View File

@ -121,7 +121,7 @@ class StoriesHeader extends StatelessWidget {
final displayname = creator.calcDisplayname(); final displayname = creator.calcDisplayname();
final avatarUrl = creator.avatarUrl; final avatarUrl = creator.avatarUrl;
if (!displayname.toLowerCase().contains(filter.toLowerCase())) { if (!displayname.toLowerCase().contains(filter.toLowerCase())) {
return Container(); return const SizedBox.shrink();
} }
return _StoryButton( return _StoryButton(
profile: Profile( profile: Profile(

View File

@ -107,7 +107,7 @@ class EmotesSettingsView extends StatelessWidget {
) )
: ListView.separated( : ListView.separated(
separatorBuilder: (BuildContext context, int i) => separatorBuilder: (BuildContext context, int i) =>
Container(), const SizedBox.shrink(),
itemCount: imageKeys.length + 1, itemCount: imageKeys.length + 1,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
if (i >= imageKeys.length) { if (i >= imageKeys.length) {

View File

@ -35,7 +35,7 @@ class MultipleEmotesSettingsView extends StatelessWidget {
final keys = packs.keys.toList(); final keys = packs.keys.toList();
keys.sort(); keys.sort();
return ListView.separated( return ListView.separated(
separatorBuilder: (BuildContext context, int i) => Container(), separatorBuilder: (BuildContext context, int i) => const SizedBox.shrink(),
itemCount: keys.length, itemCount: keys.length,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
final event = packs[keys[i]]; final event = packs[keys[i]];

View File

@ -207,7 +207,7 @@ class StoryView extends StatelessWidget {
final videoPlayerController = snapshot.data; final videoPlayerController = snapshot.data;
if (videoPlayerController == null) { if (videoPlayerController == null) {
controller.loadingModeOn(); controller.loadingModeOn();
return Container(); return const SizedBox.shrink();
} }
controller.loadingModeOff(); controller.loadingModeOff();
return Center(child: VideoPlayer(videoPlayerController)); return Center(child: VideoPlayer(videoPlayerController));
@ -226,7 +226,7 @@ class StoryView extends StatelessWidget {
final matrixFile = snapshot.data; final matrixFile = snapshot.data;
if (matrixFile == null) { if (matrixFile == null) {
controller.loadingModeOn(); controller.loadingModeOn();
return Container(); return const SizedBox.shrink();
} }
controller.loadingModeOff(); controller.loadingModeOff();
return Container( return Container(

View File

@ -115,7 +115,7 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
}, },
helpLabel: L10n.of(context)!.chatDetails, helpLabel: L10n.of(context)!.chatDetails,
onKeysPressed: _showChatDetails, onKeysPressed: _showChatDetails,
child: Container(), child: const SizedBox.shrink(),
), ),
KeyBoardShortcuts( KeyBoardShortcuts(
keysToPress: { keysToPress: {
@ -124,7 +124,7 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
}, },
helpLabel: L10n.of(context)!.matrixWidgets, helpLabel: L10n.of(context)!.matrixWidgets,
onKeysPressed: _showWidgets, onKeysPressed: _showWidgets,
child: Container(), child: const SizedBox.shrink(),
), ),
PopupMenuButton( PopupMenuButton(
onSelected: (String choice) async { onSelected: (String choice) async {

View File

@ -163,7 +163,7 @@ class _MxcImageState extends State<MxcImage> {
data == null ? CrossFadeState.showFirst : CrossFadeState.showSecond, data == null ? CrossFadeState.showFirst : CrossFadeState.showSecond,
firstChild: placeholder(context), firstChild: placeholder(context),
secondChild: data == null || data.isEmpty secondChild: data == null || data.isEmpty
? Container() ? const SizedBox.shrink()
: Image.memory( : Image.memory(
data, data,
width: widget.width, width: widget.width,