refactor: Remove unnecessary FutureBuilder

pull/1117/head
Krille 1 year ago
parent c447e15949
commit 8a64bdd82d
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -251,23 +251,15 @@ class MessageContent extends StatelessWidget {
final bigEmotes = event.onlyEmotes && final bigEmotes = event.onlyEmotes &&
event.numberEmotes > 0 && event.numberEmotes > 0 &&
event.numberEmotes <= 10; event.numberEmotes <= 10;
return FutureBuilder<String>(
future: event.calcLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
),
builder: (context, snapshot) {
return Linkify( return Linkify(
text: snapshot.data ?? text: event.calcLocalizedBodyFallback(
event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!), MatrixLocals(L10n.of(context)!),
hideReply: true, hideReply: true,
), ),
style: TextStyle( style: TextStyle(
color: textColor, color: textColor,
fontSize: bigEmotes ? fontSize * 3 : fontSize, fontSize: bigEmotes ? fontSize * 3 : fontSize,
decoration: decoration: event.redacted ? TextDecoration.lineThrough : null,
event.redacted ? TextDecoration.lineThrough : null,
), ),
options: const LinkifyOptions(humanize: false), options: const LinkifyOptions(humanize: false),
linkStyle: TextStyle( linkStyle: TextStyle(
@ -278,8 +270,6 @@ class MessageContent extends StatelessWidget {
), ),
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
); );
},
);
} }
case EventTypes.CallInvite: case EventTypes.CallInvite:
return FutureBuilder<User?>( return FutureBuilder<User?>(

@ -21,22 +21,15 @@ class StateMessage extends StatelessWidget {
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.background,
borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2), borderRadius: BorderRadius.circular(AppConfig.borderRadius / 2),
), ),
child: FutureBuilder<String>( child: Text(
future: event.calcLocalizedBody(MatrixLocals(L10n.of(context)!)),
builder: (context, snapshot) {
return Text(
snapshot.data ??
event.calcLocalizedBodyFallback( event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!), MatrixLocals(L10n.of(context)!),
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
fontSize: 12 * AppConfig.fontSizeFactor, fontSize: 12 * AppConfig.fontSizeFactor,
decoration: decoration: event.redacted ? TextDecoration.lineThrough : null,
event.redacted ? TextDecoration.lineThrough : null,
), ),
);
},
), ),
), ),
), ),

@ -63,15 +63,8 @@ class PinnedEvents extends StatelessWidget {
future: controller.room.getEventById(pinnedEventIds.last), future: controller.room.getEventById(pinnedEventIds.last),
builder: (context, snapshot) { builder: (context, snapshot) {
final event = snapshot.data; final event = snapshot.data;
return FutureBuilder<String>( return ChatAppBarListTile(
future: event?.calcLocalizedBody( title: event?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: true,
hideReply: true,
),
builder: (context, snapshot) => ChatAppBarListTile(
title: snapshot.data ??
event?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!), MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: true, withSenderNamePrefix: true,
hideReply: true, hideReply: true,
@ -83,13 +76,11 @@ class PinnedEvents extends StatelessWidget {
color: Theme.of(context).colorScheme.onSurfaceVariant, color: Theme.of(context).colorScheme.onSurfaceVariant,
icon: const Icon(Icons.push_pin), icon: const Icon(Icons.push_pin),
tooltip: L10n.of(context)!.unpin, tooltip: L10n.of(context)!.unpin,
onPressed: onPressed: controller.room.canSendEvent(EventTypes.RoomPinnedEvents)
controller.room.canSendEvent(EventTypes.RoomPinnedEvents)
? () => controller.unpinEvent(event!.eventId) ? () => controller.unpinEvent(event!.eventId)
: null, : null,
), ),
onTap: () => _displayPinnedEventsDialog(context), onTap: () => _displayPinnedEventsDialog(context),
),
); );
}, },
); );

@ -66,15 +66,7 @@ class _EditContent extends StatelessWidget {
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
Container(width: 15.0), Container(width: 15.0),
FutureBuilder<String>( Text(
future: event.calcLocalizedBody(
MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: false,
hideReply: true,
),
builder: (context, snapshot) {
return Text(
snapshot.data ??
event.calcLocalizedBodyFallback( event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!), MatrixLocals(L10n.of(context)!),
withSenderNamePrefix: false, withSenderNamePrefix: false,
@ -85,8 +77,6 @@ class _EditContent extends StatelessWidget {
style: TextStyle( style: TextStyle(
color: Theme.of(context).textTheme.bodyMedium!.color, color: Theme.of(context).textTheme.bodyMedium!.color,
), ),
);
},
), ),
], ],
); );

@ -226,27 +226,12 @@ class ChatListItem extends StatelessWidget {
maxLines: 1, maxLines: 1,
softWrap: false, softWrap: false,
) )
: FutureBuilder<String>( : Text(
future: room.lastEvent?.calcLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: !isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId,
) ??
Future.value(L10n.of(context)!.emptyChat),
builder: (context, snapshot) {
return Text(
room.membership == Membership.invite room.membership == Membership.invite
? isDirectChat ? isDirectChat
? L10n.of(context)!.invitePrivateChat ? L10n.of(context)!.invitePrivateChat
: L10n.of(context)!.inviteGroupChat : L10n.of(context)!.inviteGroupChat
: snapshot.data ?? : room.lastEvent?.calcLocalizedBodyFallback(
room.lastEvent
?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!), MatrixLocals(L10n.of(context)!),
hideReply: true, hideReply: true,
hideEdit: true, hideEdit: true,
@ -269,8 +254,6 @@ class ChatListItem extends StatelessWidget {
? TextDecoration.lineThrough ? TextDecoration.lineThrough
: null, : null,
), ),
);
},
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),

Loading…
Cancel
Save