Kaynağa Gözat

Merge pull request #132 from tauu/fix-terminalview-dispose

fix: dispose controllers of TerminalView
xuty 3 yıl önce
ebeveyn
işleme
c1f0b94f5d
1 değiştirilmiş dosya ile 13 ekleme ve 1 silme
  1. 13 1
      lib/src/terminal_view.dart

+ 13 - 1
lib/src/terminal_view.dart

@@ -124,7 +124,7 @@ class TerminalView extends StatefulWidget {
 }
 
 class TerminalViewState extends State<TerminalView> {
-  late final FocusNode _focusNode;
+  late FocusNode _focusNode;
 
   late final ShortcutManager _shortcutManager;
 
@@ -163,9 +163,15 @@ class TerminalViewState extends State<TerminalView> {
       _focusNode = widget.focusNode ?? FocusNode();
     }
     if (oldWidget.controller != widget.controller) {
+      if (oldWidget.controller == null) {
+        _controller.dispose();
+      }
       _controller = widget.controller ?? TerminalController();
     }
     if (oldWidget.scrollController != widget.scrollController) {
+      if (oldWidget.scrollController == null) {
+        _scrollController.dispose();
+      }
       _scrollController = widget.scrollController ?? ScrollController();
     }
     super.didUpdateWidget(oldWidget);
@@ -176,6 +182,12 @@ class TerminalViewState extends State<TerminalView> {
     if (widget.focusNode == null) {
       _focusNode.dispose();
     }
+    if (widget.controller == null) {
+      _controller.dispose();
+    }
+    if (widget.scrollController == null) {
+      _scrollController.dispose();
+    }
     _shortcutManager.dispose();
     super.dispose();
   }