-1

I am creating 100's of TextEditing Controllers in my app. Here's what im doing:

TextEditingController _customerName = TextEditingController();

I'm just curious, but if I have 100s of these elements, am I meant to do anything in

@override
void initState()
{ .... }

or

@override
void dispose()
{... } 

???

Im just asking as my app is sluggish and I have a feeling it maybe because I'm using 1000s of these controllers.

Thanks

houba
  • 496
  • 7
  • 20

1 Answers1

2

You should dispose every TextEditingController before disposing its screen. For example:

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

Docs: https://api.flutter.dev/flutter/widgets/TextEditingController-class.html

Ruben Röhner
  • 593
  • 4
  • 16