title: Dispose isn't called when the widgets removed from the window - Flutter
body: <p>I am using the same stateful widget in 2 different views. It's using a list of <code>TextEditingController</code> that I send as a delegate through </p>
  
  <p>this is the list of TextControllers :</p>
  
  <pre><code>var textfieldControllersEx = [
    TextEditingController(),
    TextEditingController(),
    TextEditingController(),
    TextEditingController(),
  ];
  </code></pre>
  
  <p>the Extracted widget is used twice in 2 different views:</p>
  
  <pre><code>ExpiryDateTextField(
    controllers: textfieldControllersEx,
    onChangeF: (String value, int i) {
      setState(() {
          _addValuesToAr(value, i);
      });
    },
  ),
  </code></pre>
  
  <p>on every view I call a dispose and a dispose in the <code>ExpiryDateTextField</code> Function as well with a print to see if it's being disposed:</p>
  
  <p>It doesn't even call the dispose on either pages</p>
  
  <pre><code>@override
    void dispose() {
      Print.yellow('DISPOSED');
      textfieldControllersEx[0].dispose();
      textfieldControllersEx[1].dispose();
      textfieldControllersEx[2].dispose();
      textfieldControllersEx[3].dispose();
      textfieldControllersEx[0].text = null;
      textfieldControllersEx[1].text = null;
      textfieldControllersEx[2].text = null;
      textfieldControllersEx[3].text = null;
      // TODO: implement dispose
      super.dispose();
    }
  </code></pre>
  
  <p>this is the function :</p>
  
  <pre><code>var focusNodes = [
    FocusNode(),
    FocusNode(),
    FocusNode(),
    FocusNode(),
  ];
  class ExpiryDateTextField extends StatefulWidget {
    final List&lt;TextEditingController&gt; controllers;
    final Function onChangeF;
    ExpiryDateTextField({this.controllers, this.onChangeF});
    @override
    _ExpiryDateTextFieldState createState() =&gt; _ExpiryDateTextFieldState();
  }
  class _ExpiryDateTextFieldState extends State&lt;ExpiryDateTextField&gt; {
    @override
    void dispose() {
      // TODO: implement dispose
      super.dispose();
    }
    @override
    Widget build(BuildContext context) {
      bool onSwitchChanged(value, context, index) {
        // print(index++);
        if (index == 4) {
          //if it is on the last text box, do nothing
        } else {
          if (widget.controllers[index].text.length &gt; 0) {
            index++;
            FocusScope.of(context).requestFocus(focusNodes[index]);
            widget.controllers[index].selection = TextSelection(
              baseOffset: 0,
              extentOffset: widget.controllers[index].text.length
            );
            // FocusScope.of(context).focus
          }
        }
        return true;
      }
      return Row(
        children: &lt;Widget&gt;[
          Expanded(
            flex: 1,
            child: SingleDigitTextField(
              onChangedF: (value) {
                widget.onChangeF(value, 0);
                print(this.toString(minLevel: DiagnosticLevel.debug));
                onSwitchChanged(value, context, 0);
              },
              fNode: focusNodes[0],
              cController: widget.controllers[0]
            ),
          ),
          Expanded(
            flex: 1,
            child: SingleDigitTextField(
              onChangedF: (value) {
                widget.onChangeF(value, 1);
                onSwitchChanged(value, context, 1);
              },
              fNode: focusNodes[1],
              cController: widget.controllers[1]
            ),
          ),
          Expanded(
            flex: 1,
            child: Text("/",
              textAlign: TextAlign.center,
              style: Theme.of(context).textTheme.display2
            ),
          ),
          Expanded(
            flex: 1,
            child: SingleDigitTextField(
              onChangedF: (value) {
                widget.onChangeF(value, 2);
                onSwitchChanged(value, context, 2);
              },
              fNode: focusNodes[2],
              cController: widget.controllers[2]
            ),
          ),
          Expanded(
            flex: 1,
            child: SingleDigitTextField(
              onChangedF: (value) {
                widget.onChangeF(value, 3);
                onSwitchChanged(value, context, 3);
              },
              fNode: focusNodes[3],
              cController: widget.controllers[3]
            ),
          ),
        ],
      );
    }
  }
  
  </code></pre>
  
  <p>this is the error given :</p>
  
  <blockquote>
    <p>I/flutter (24293): Another exception was thrown:
    dependOnInheritedWidgetOfExactType&lt;_ModalScopeStatus>() or
    dependOnInheritedElement() was called before _ViewState.initState()
    completed.</p>
  </blockquote>
  
  <p>I saw this example but it didn't work because if a value is changed it disposes of the TextControllers immediately :</p>
  
  <pre><code>@override
    void didChangeDependencies() {
      textfieldControllersEx[0].dispose();
      textfieldControllersEx[1].dispose();
      textfieldControllersEx[2].dispose();
      textfieldControllersEx[3].dispose();
      // TODO: implement didChangeDependencies
      super.didChangeDependencies();
    }
  </code></pre>
  
  <p>this is how I Navigate :</p>
  
  <pre><code>Navigator.of(context).pushNamed("/PlaidPage");
  </code></pre>
  
  <p>Help would be kindly appreciated</p>