improved performance and battery usage on older devices
This commit is contained in:
@@ -83,12 +83,20 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Called per keystroke, so the text itself is saved silently; only a draft
|
||||
/// appearing or disappearing notifies listeners (the chat list's marker).
|
||||
void _setDraft(String text) {
|
||||
final talkSettings = settings.val(write: true).talkSettings;
|
||||
final drafts = settings.val().talkSettings.drafts;
|
||||
final hadDraft = drafts.containsKey(widget.sendToToken);
|
||||
if (text.isNotEmpty) {
|
||||
talkSettings.drafts[widget.sendToToken] = text;
|
||||
drafts[widget.sendToToken] = text;
|
||||
} else {
|
||||
talkSettings.drafts.removeWhere((key, _) => key == widget.sendToToken);
|
||||
drafts.remove(widget.sendToToken);
|
||||
}
|
||||
if (hadDraft != text.isNotEmpty) {
|
||||
settings.val(write: true);
|
||||
} else {
|
||||
settings.saveSilently();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,17 +284,22 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chatBloc = context.watch<ChatBloc>();
|
||||
final chatState = chatBloc.state.data;
|
||||
final chatBloc = context.read<ChatBloc>();
|
||||
// Only the reply reference is rendered from the chat state; loading flags
|
||||
// and paging emits don't need to rebuild the input.
|
||||
final (referenceMessageId, chatResponse) = context.select(
|
||||
(ChatBloc b) => (
|
||||
b.state.data?.referenceMessageId,
|
||||
b.state.data?.chatResponse,
|
||||
),
|
||||
);
|
||||
|
||||
Widget replyBanner = const SizedBox.shrink();
|
||||
if (chatState != null &&
|
||||
chatState.referenceMessageId != null &&
|
||||
chatState.chatResponse != null) {
|
||||
if (referenceMessageId != null && chatResponse != null) {
|
||||
try {
|
||||
final referenceMessage = chatState.chatResponse!
|
||||
.sortByTimestamp()
|
||||
.firstWhere((e) => e.id == chatState.referenceMessageId);
|
||||
final referenceMessage = chatResponse.data.firstWhere(
|
||||
(e) => e.id == referenceMessageId,
|
||||
);
|
||||
replyBanner = Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user