'Flutter : Hot reload / Hot restart showing white screen with debug banner?

In my flutter app , when I try to hot reload or hot restart , after process complete , the reloaded screen shows for a second and then went whole white

only the Debug banner in top right side showing

There is no errors in the console. It just says restarted application...

I need to stop and rerun the application !!!

Why ?

I am using auto route and river pod, fast_i18n for localization

I can't even figure out where is the problem and how explain ?

Sharing some code in gist

https://gist.github.com/RageshAntony/2288a47a8fdc24af1e570a0c7cb9ed08

Other project running without issues



Solution 1:[1]

Make sure you don't initiate your router inside of the build function.

@override
Widget build(BuildContext context) {
  //remove this from here
  //you can just declare as a top level variable
  final AppRouter router= AppRouter();



  return MaterialApp.router(
    routeInformationParser: router.defaultRouteParser(),
    routerDelegate: router.delegate(),
    theme: ThemeData(
      primarySwatch: primaryColor,
    ),
  );
}

Solution 2:[2]

Move your router from build method

Solution 3:[3]

I found that this problem may be caused by the fact that the related code of auto route in the project is not configured correctly, because I also use it, and the same problem occurs. There is no solution to this problem yet, but an odd solution has been found that at least makes development slightly faster.

Open "Flutter DevTools", click "Select Widget Mode", the interface will appear.

hhhhhhhh...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Simeon
Solution 2 Maksim Kardashin
Solution 3 Mr Qin