79456241

Date: 2025-02-21 02:32:08
Score: 1
Natty:
Report link

Normally, main() is called only once and serves as the entry point, it initializes Flutter and starts the app. Once the app starts, main() is not called again unless explicitly restarted.

main() can be called multiple times in 3 cases

1- In Flutter debug mode(during development), when you do a Hot Restart (NOT IN DESKTOP DEV), the app fully restarts and calls main() again.

2- One can explicitly call main() inside the app, I do not recommend for security..multiple instances of the app running in memory..

3- After a Crash

Solutions:

1- for desktop apps try to restarted manually to recall the main().

2- call runApp() multiple times without restarting main(), but it will replace the widget tree

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Amine Kaddar