Home > database >  Is there a difference between putting dispose on the first line and putting it on the last line?
Is there a difference between putting dispose on the first line and putting it on the last line?

Time:05-02

What is the difference between the two code blocks?

First code block

  TextEditingController textEditingController = TextEditingController();

  @override
  void dispose() {
    super.dispose();
    textEditingController.dispose();
  }

second code block

  TextEditingController textEditingController = TextEditingController();

  @override
  void dispose() {
    textEditingController.dispose();
    super.dispose();
  }

CodePudding user response:

super.dispose() should always be the last line in the overrided dispose function, because you should deactivate your specific widget before deactivating the super class widgets. https://api.flutter.dev/flutter/widgets/State/dispose.html

  • Related