I am looking for a way to dispose some final things before my application closes. I want this to happen on web close, on native window close and on mobile close.
I thought I’d do it like this, but the flutter engines takes my widgets and ends the main function.
void main() {
try {
runApp(MyApp());
}
finally {
customDisposeFunction(); // TODO: Oh no, this function is called right away!
}
}
class MyApp extends StatelessWidget {
}
I have also tried to use flutter_window_close, but that does not dispose when I press the stop button in visual studio code.
I have also tried to watch via ProcessSignal, but that is not cross-platform at all.
I have also tried to make the app a StatefulWidget
, but dispose
in the State
is not called (on windows) when closing down the window.
Are there some good ways to handle this cross-platform?
2
Answers
Yes, because finally will get a hit directly after you write it this way.
Instead you should try to write it in dispose method of your main class (you have to make it Stateful though)
You can make your
MyApp
aStatefulWidget
and override itsdispose()
method.