Fix bugs found in full code audit
- Edit screens (note, task): cache _initFuture in initState instead of
calling _loadExisting() from FutureBuilder on every rebuild. Prevents
race condition where multiple concurrent loads could overwrite edits.
Also removes unnecessary _loaded flag and simplifies the pattern.
- Note editor: remove onChanged: (_) => setState((){}) on the body
TextField — triggered a full rebuild on every keystroke for no reason.
- SSE streaming: use utf8.decode(chunk, allowMalformed: true) so a
malformed byte sequence from the server skips rather than throwing an
unhandled FormatException that escaped all catch blocks.
- Chat provider: guard msgs.isEmpty before accessing msgs.last during
SSE chunk processing to prevent a potential index error on empty state.
- Offline queue drain: check mounted before and after each async gap in
_drainQueue so ref is never accessed on a disposed widget.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -92,7 +92,7 @@ class ChatApi {
|
||||
String currentEvent = '';
|
||||
|
||||
await for (final chunk in stream) {
|
||||
buf.write(utf8.decode(chunk));
|
||||
buf.write(utf8.decode(chunk, allowMalformed: true));
|
||||
final raw = buf.toString();
|
||||
final lines = raw.split('\n');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user