When I read the doc in flutter, I have a question that should flutter root widget always be StatelessWidget?
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Code Sample for Navigator',
// MaterialApp contains our top-level Navigator
initialRoute: '/',
routes: {
'/': (BuildContext context) => HomePage(),
'/signup': (BuildContext context) => SignUpPage(),
},
);
}
}
- Because I think there's sometime need init function to call, and maybe not want the code of that write in
HomePage. For example: check token expire or not, and decide go toHomePageorLoginPage. - Then the best option: should I change the root Widget to StatefulWidget, and just include the logic above in its
initStatefunction ?