I have a UserType variable inside StatefulWidget widget, and what I am trying to do is to pass the value of this UserType variable into different Screen when The user Navigates between different BottomNavigationBarItem, I want to pass this UserType variable in to Upload page() Like below code, but I face the Error ,The instance member 'widget' can't be accessed in an initializer. Please help me?
the Value of UserType variable is alredy passed from othre page using HomePagecontroller(UserType:controllUserType)
User curentuser= _firebaseAuth.currentUser;
class HomePage extends StatefulWidget {
final String UserType;
const HomePage({Key key,@required this.UserType}):super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final List<Widget>_children =
[
TimeLinePage(),
SearchPage(), //search(),
UploadPage(UserSID: curentuser.uid, usertypes: widget.UserType),
NotificationsPage(),
ProfilePage(userProfileID: curentuser.uid),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: buildHomeScreen(),
);
}
Scaffold buildHomeScreen() {
return Scaffold(
backgroundColor: Colors.black,
body: _children[_CurrentIndex],
bottomNavigationBar: CupertinoTabBar(
currentIndex: _CurrentIndex,
backgroundColor: Colors.black,
onTap: onTabchangePage,
activeColor: Colors.green,
inactiveColor: Colors.white,
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('home'),),
BottomNavigationBarItem(icon: Icon(Icons.search)),
BottomNavigationBarItem(icon: Icon(Icons.photo_camera, size: 40,)),
BottomNavigationBarItem(icon: Icon(Icons.notifications)),
BottomNavigationBarItem(icon: Icon(Icons.person_add_alt_1_sharp)),
],
),
);
}
}
void onTabchangePage(int index) {
setState(() {
_CurrentIndex= index;
});[here is the image for the error][1]
}
}