I'm working on a windows application with flutter desktop, for now, everything seems to work smoothly and with no problems. But I suspect that I caused a memory leak when using PageView !!
Basically, I have PageViews with 6 pages. One of those pages is a form with a lot of TextEditingController and yea I'm calling dispose()
for each TextEditingController and also for all BLoCs I'm using.
Now when The user submits the data and I get a reply from the API that the data was stored successfully I show a success dialog:
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Succès'),
content: Text(message),
actions: [
FlatButton(
child: Text('Sortie'),
textColor: Colors.white,
color: kColorGreen,
onPressed: () {
Navigator.of(context).pop();
pageController.jumpToPage(2);
// Tried calling dispose here !!
// dispose();
},
),
],
);
},
);
OnPressed: I take the user to another page. And it works BUT when I navigate back to the form page all the form fields are still filled with the old data and the dispose method never gets called !!
I tried calling the dispose method by myself before navigating to another page but no luck !!
So my question is: How can I dispose of all the TextEditingController and the BLoCs present on the form page when navigating out of it?