refactor: Remove unnecessary FutureBuilder
This commit is contained in:
parent
c447e15949
commit
8a64bdd82d
5 changed files with 76 additions and 129 deletions
|
|
@ -251,34 +251,24 @@ 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>(
|
return Linkify(
|
||||||
future: event.calcLocalizedBody(
|
text: event.calcLocalizedBodyFallback(
|
||||||
MatrixLocals(L10n.of(context)!),
|
MatrixLocals(L10n.of(context)!),
|
||||||
hideReply: true,
|
hideReply: true,
|
||||||
),
|
),
|
||||||
builder: (context, snapshot) {
|
style: TextStyle(
|
||||||
return Linkify(
|
color: textColor,
|
||||||
text: snapshot.data ??
|
fontSize: bigEmotes ? fontSize * 3 : fontSize,
|
||||||
event.calcLocalizedBodyFallback(
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
MatrixLocals(L10n.of(context)!),
|
),
|
||||||
hideReply: true,
|
options: const LinkifyOptions(humanize: false),
|
||||||
),
|
linkStyle: TextStyle(
|
||||||
style: TextStyle(
|
color: textColor.withAlpha(150),
|
||||||
color: textColor,
|
fontSize: bigEmotes ? fontSize * 3 : fontSize,
|
||||||
fontSize: bigEmotes ? fontSize * 3 : fontSize,
|
decoration: TextDecoration.underline,
|
||||||
decoration:
|
decorationColor: textColor.withAlpha(150),
|
||||||
event.redacted ? TextDecoration.lineThrough : null,
|
),
|
||||||
),
|
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
||||||
options: const LinkifyOptions(humanize: false),
|
|
||||||
linkStyle: TextStyle(
|
|
||||||
color: textColor.withAlpha(150),
|
|
||||||
fontSize: bigEmotes ? fontSize * 3 : fontSize,
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
decorationColor: textColor.withAlpha(150),
|
|
||||||
),
|
|
||||||
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case EventTypes.CallInvite:
|
case EventTypes.CallInvite:
|
||||||
|
|
|
||||||
|
|
@ -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)!)),
|
event.calcLocalizedBodyFallback(
|
||||||
builder: (context, snapshot) {
|
MatrixLocals(L10n.of(context)!),
|
||||||
return Text(
|
),
|
||||||
snapshot.data ??
|
textAlign: TextAlign.center,
|
||||||
event.calcLocalizedBodyFallback(
|
style: TextStyle(
|
||||||
MatrixLocals(L10n.of(context)!),
|
fontSize: 12 * AppConfig.fontSizeFactor,
|
||||||
),
|
decoration: event.redacted ? TextDecoration.lineThrough : null,
|
||||||
textAlign: TextAlign.center,
|
),
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12 * AppConfig.fontSizeFactor,
|
|
||||||
decoration:
|
|
||||||
event.redacted ? TextDecoration.lineThrough : null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -63,33 +63,24 @@ 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)!),
|
MatrixLocals(L10n.of(context)!),
|
||||||
withSenderNamePrefix: true,
|
withSenderNamePrefix: true,
|
||||||
hideReply: true,
|
hideReply: true,
|
||||||
),
|
) ??
|
||||||
builder: (context, snapshot) => ChatAppBarListTile(
|
L10n.of(context)!.loadingPleaseWait,
|
||||||
title: snapshot.data ??
|
leading: IconButton(
|
||||||
event?.calcLocalizedBodyFallback(
|
splashRadius: 20,
|
||||||
MatrixLocals(L10n.of(context)!),
|
iconSize: 20,
|
||||||
withSenderNamePrefix: true,
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
hideReply: true,
|
icon: const Icon(Icons.push_pin),
|
||||||
) ??
|
tooltip: L10n.of(context)!.unpin,
|
||||||
L10n.of(context)!.loadingPleaseWait,
|
onPressed: controller.room.canSendEvent(EventTypes.RoomPinnedEvents)
|
||||||
leading: IconButton(
|
? () => controller.unpinEvent(event!.eventId)
|
||||||
splashRadius: 20,
|
: null,
|
||||||
iconSize: 20,
|
|
||||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
||||||
icon: const Icon(Icons.push_pin),
|
|
||||||
tooltip: L10n.of(context)!.unpin,
|
|
||||||
onPressed:
|
|
||||||
controller.room.canSendEvent(EventTypes.RoomPinnedEvents)
|
|
||||||
? () => controller.unpinEvent(event!.eventId)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
onTap: () => _displayPinnedEventsDialog(context),
|
|
||||||
),
|
),
|
||||||
|
onTap: () => _displayPinnedEventsDialog(context),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -66,27 +66,17 @@ 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(
|
event.calcLocalizedBodyFallback(
|
||||||
MatrixLocals(L10n.of(context)!),
|
MatrixLocals(L10n.of(context)!),
|
||||||
withSenderNamePrefix: false,
|
withSenderNamePrefix: false,
|
||||||
hideReply: true,
|
hideReply: true,
|
||||||
),
|
),
|
||||||
builder: (context, snapshot) {
|
overflow: TextOverflow.ellipsis,
|
||||||
return Text(
|
maxLines: 1,
|
||||||
snapshot.data ??
|
style: TextStyle(
|
||||||
event.calcLocalizedBodyFallback(
|
color: Theme.of(context).textTheme.bodyMedium!.color,
|
||||||
MatrixLocals(L10n.of(context)!),
|
),
|
||||||
withSenderNamePrefix: false,
|
|
||||||
hideReply: true,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 1,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context).textTheme.bodyMedium!.color,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -226,51 +226,34 @@ class ChatListItem extends StatelessWidget {
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
)
|
)
|
||||||
: FutureBuilder<String>(
|
: Text(
|
||||||
future: room.lastEvent?.calcLocalizedBody(
|
room.membership == Membership.invite
|
||||||
MatrixLocals(L10n.of(context)!),
|
? isDirectChat
|
||||||
hideReply: true,
|
? L10n.of(context)!.invitePrivateChat
|
||||||
hideEdit: true,
|
: L10n.of(context)!.inviteGroupChat
|
||||||
plaintextBody: true,
|
: room.lastEvent?.calcLocalizedBodyFallback(
|
||||||
removeMarkdown: true,
|
MatrixLocals(L10n.of(context)!),
|
||||||
withSenderNamePrefix: !isDirectChat ||
|
hideReply: true,
|
||||||
directChatMatrixId !=
|
hideEdit: true,
|
||||||
room.lastEvent?.senderId,
|
plaintextBody: true,
|
||||||
) ??
|
removeMarkdown: true,
|
||||||
Future.value(L10n.of(context)!.emptyChat),
|
withSenderNamePrefix: !isDirectChat ||
|
||||||
builder: (context, snapshot) {
|
directChatMatrixId !=
|
||||||
return Text(
|
room.lastEvent?.senderId,
|
||||||
room.membership == Membership.invite
|
) ??
|
||||||
? isDirectChat
|
L10n.of(context)!.emptyChat,
|
||||||
? L10n.of(context)!.invitePrivateChat
|
softWrap: false,
|
||||||
: L10n.of(context)!.inviteGroupChat
|
maxLines: 1,
|
||||||
: snapshot.data ??
|
overflow: TextOverflow.ellipsis,
|
||||||
room.lastEvent
|
style: TextStyle(
|
||||||
?.calcLocalizedBodyFallback(
|
fontWeight: unread || room.hasNewMessages
|
||||||
MatrixLocals(L10n.of(context)!),
|
? FontWeight.bold
|
||||||
hideReply: true,
|
: null,
|
||||||
hideEdit: true,
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
plaintextBody: true,
|
decoration: room.lastEvent?.redacted == true
|
||||||
removeMarkdown: true,
|
? TextDecoration.lineThrough
|
||||||
withSenderNamePrefix: !isDirectChat ||
|
: null,
|
||||||
directChatMatrixId !=
|
),
|
||||||
room.lastEvent?.senderId,
|
|
||||||
) ??
|
|
||||||
L10n.of(context)!.emptyChat,
|
|
||||||
softWrap: false,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: unread || room.hasNewMessages
|
|
||||||
? FontWeight.bold
|
|
||||||
: null,
|
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
|
||||||
decoration: room.lastEvent?.redacted == true
|
|
||||||
? TextDecoration.lineThrough
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue