From 1829bf1b7a11f6c2f510eefcde636c7aa1349a4d Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 5 Sep 2023 12:05:14 +0200 Subject: [PATCH] fix(neon,neon_files,neon_news,neon_notes): properly dispoe TextEditingController Signed-off-by: Nikolas Rimikis --- .../neon/neon/lib/src/utils/rename_dialog.dart | 14 +++++++++++++- .../neon/neon_files/lib/dialogs/create_folder.dart | 6 ++++++ packages/neon/neon_news/lib/dialogs/add_feed.dart | 6 ++++++ .../neon/neon_news/lib/dialogs/create_folder.dart | 6 ++++++ .../neon/neon_notes/lib/dialogs/create_note.dart | 6 ++++++ packages/neon/neon_notes/lib/pages/note.dart | 9 +++++++-- 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/neon/neon/lib/src/utils/rename_dialog.dart b/packages/neon/neon/lib/src/utils/rename_dialog.dart index 24ec4876..bef84826 100644 --- a/packages/neon/neon/lib/src/utils/rename_dialog.dart +++ b/packages/neon/neon/lib/src/utils/rename_dialog.dart @@ -34,7 +34,19 @@ class _RenameDialog extends StatefulWidget { class _RenameDialogState extends State<_RenameDialog> { final formKey = GlobalKey(); - late final controller = TextEditingController()..text = widget.value; + final controller = TextEditingController(); + + @override + void initState() { + controller.text = widget.value; + super.initState(); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } void submit() { if (formKey.currentState!.validate()) { diff --git a/packages/neon/neon_files/lib/dialogs/create_folder.dart b/packages/neon/neon_files/lib/dialogs/create_folder.dart index fab90b8e..d2d628f3 100644 --- a/packages/neon/neon_files/lib/dialogs/create_folder.dart +++ b/packages/neon/neon_files/lib/dialogs/create_folder.dart @@ -14,6 +14,12 @@ class _FilesCreateFolderDialogState extends State { final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + void submit() { if (formKey.currentState!.validate()) { Navigator.of(context).pop(controller.text.split('/')); diff --git a/packages/neon/neon_news/lib/dialogs/add_feed.dart b/packages/neon/neon_news/lib/dialogs/add_feed.dart index c1f4fb98..4c640a29 100644 --- a/packages/neon/neon_news/lib/dialogs/add_feed.dart +++ b/packages/neon/neon_news/lib/dialogs/add_feed.dart @@ -42,6 +42,12 @@ class _NewsAddFeedDialogState extends State { ); } + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + @override Widget build(final BuildContext context) => ResultBuilder>.behaviorSubject( stream: widget.bloc.folders, diff --git a/packages/neon/neon_news/lib/dialogs/create_folder.dart b/packages/neon/neon_news/lib/dialogs/create_folder.dart index 18c9106c..be4b2ca9 100644 --- a/packages/neon/neon_news/lib/dialogs/create_folder.dart +++ b/packages/neon/neon_news/lib/dialogs/create_folder.dart @@ -14,6 +14,12 @@ class _NewsCreateFolderDialogState extends State { final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + void submit() { if (formKey.currentState!.validate()) { Navigator.of(context).pop(controller.text); diff --git a/packages/neon/neon_notes/lib/dialogs/create_note.dart b/packages/neon/neon_notes/lib/dialogs/create_note.dart index 0fb0d02c..fd3d8598 100644 --- a/packages/neon/neon_notes/lib/dialogs/create_note.dart +++ b/packages/neon/neon_notes/lib/dialogs/create_note.dart @@ -19,6 +19,12 @@ class _NotesCreateNoteDialogState extends State { final controller = TextEditingController(); String? selectedCategory; + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + void submit() { if (formKey.currentState!.validate()) { Navigator.of(context).pop((controller.text, widget.category ?? selectedCategory)); diff --git a/packages/neon/neon_notes/lib/pages/note.dart b/packages/neon/neon_notes/lib/pages/note.dart index f5336f83..d49d4552 100644 --- a/packages/neon/neon_notes/lib/pages/note.dart +++ b/packages/neon/neon_notes/lib/pages/note.dart @@ -15,8 +15,8 @@ class NotesNotePage extends StatefulWidget { } class _NotesNotePageState extends State { - late final _contentController = TextEditingController()..text = widget.bloc.initialContent; - late final _titleController = TextEditingController()..text = widget.bloc.initialTitle; + final _contentController = TextEditingController(); + final _titleController = TextEditingController(); final _contentFocusNode = FocusNode(); final _titleFocusNode = FocusNode(); bool _showEditor = false; @@ -36,6 +36,9 @@ class _NotesNotePageState extends State { handleNotesException(context, error); }); + _contentController.text = widget.bloc.initialContent; + _titleController.text = widget.bloc.initialTitle; + _contentStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateContent); _titleStreamController.stream.debounceTime(const Duration(seconds: 1)).listen(widget.bloc.updateTitle); _contentController.addListener(() => _contentStreamController.add(_contentController.text)); @@ -56,6 +59,8 @@ class _NotesNotePageState extends State { @override void dispose() { + _contentController.dispose(); + _titleController.dispose(); unawaited(_contentStreamController.close()); unawaited(_titleStreamController.close()); super.dispose();