add log buffer and replace direct list mutation

- Introduce _addLog() helper to manage log insertion
- Enforce a maximum log history of 200 entries to prevent unbounded memory growth
- Replace direct _logsNotifier.value.add(event) with safe, immutable-style list update
- Improve log handling consistency and avoid mutating notifier state in place
This commit is contained in:
NBA2K1 2026-01-08 22:48:34 +01:00
parent 09684a2641
commit f4f344ce29

View file

@ -93,7 +93,7 @@ class _CodeEditorPageState extends ConsumerState<CodeEditorPage> {
_controller.text = source?.sourceCode ?? "";
useLogger = true;
_logSubscription = _logStreamController.stream.listen((event) async {
_logsNotifier.value.add(event);
_addLog(event);
try {
await Future.delayed(const Duration(milliseconds: 5));
if (_scrollController.hasClients) {
@ -103,6 +103,18 @@ class _CodeEditorPageState extends ConsumerState<CodeEditorPage> {
});
}
static const int _maxLogs = 200;
void _addLog((LoggerLevel, String, DateTime) log) {
final logs = _logsNotifier.value;
final newLogs = List<(LoggerLevel, String, DateTime)>.from(logs);
if (newLogs.length >= _maxLogs) {
newLogs.removeAt(0);
}
newLogs.add(log);
_logsNotifier.value = newLogs;
}
List<dynamic> filters = [];
Future<String?> filterDialog(BuildContext context) async {