Here in my code mapResponse is a variable which can be null, so I want to check and if the mapResponse is null I want the page to navigate to different page in bottom navigation, below given is the code, but it throws the error saying "The instance member 'mapResponse' can't be accessed in an initializer."
Map? mapResponse
final screens = [
const LandingPage(),
const ComingSoon(),
const ComingSoon(),
mapResponse==null?const ProfileDashBoard():const Home()
];
CodePudding user response:
check this out:
Map? mapResponse
List screens = [];
initState((){
screens =[
const LandingPage(),
const ComingSoon(),
const ComingSoon(),
mapResponse==null?const ProfileDashBoard():const Home()
];
});
CodePudding user response:
You nee do it in initState
like this:
Map? mapResponse;
List screens = [];
@override
void initState() {
super.initState();
screens = [
const LandingPage(),
const ComingSoon(),
const ComingSoon(),
mapResponse == null ? const ProfileDashBoard() : const Home(),
];
}
CodePudding user response:
You can use late
late final screens = [
More about late keyword with declaration