is it possible to use setState()
function on main.dart because it has not a statfulWidget . how could i use it or is there another solution or function that have the same functionality
CodePudding user response:
The best way is using a state manager. My main.dart Works with get, like this :
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context){
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
try {
return GetX<AppController>(
builder: (ac) => (
_buildWithTheme(context, ac)
)
);
} catch(_){}
}
Widget _buildWithTheme(BuildContext context, AppController state) {
return MaterialApp(
title: 'APP',
theme: makeAppTheme(),
darkTheme: makeAppTheme(),
debugShowCheckedModeBanner: false,
initialRoute: '/',
locale: setLocale(state),
);
}
CodePudding user response:
setState
can be used when changing the value:
int i = 0;
setState(() {
i = 1;
});
print(i);
Result:
I/flutter ( 2492): 1