I'm trying to access the value of the variable String UserType, and String userID; on _HomePageState, I want to pass the value of both UserType and userID Variable to ProfilePage() And UploadPage(),
The problem displayed is "The instance member'widget' can't be accessed in an initializer.
Try replacing the reference to the instance member with a different expression".
Here is MY StatefulWidget Class inside I declare Usertype and userID variable,i want to pass them to ProfilePage() And UploadPage(), inside _HomePageState,
class HomePage extends StatefulWidget {
String UserType;
String userID;
HomePage({Key key,@required this.UserType,@required this.userID}):super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _CurrentIndex=0;
String owneruerID= widget.userID;
dynamic uploadusertypes=widget.UserType;
final List<Widget>_children=[
TimeLinePage(),
SearchPage(), //search(),
UploadPage(UserSID:owneruerID,uploadusertypes:uploadusertypes),
NotificationsPage(),
ProfilePage(userProfileID:widget.userID),
];
@override
void initState(){
super.initState();
uploadusertypes= widget.UserType;
owneruerID= widget.userID;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: WillPopScope(
onWillPop: onwillpops,
child: 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;
});
}
}
i Correct the Bove but still the Error Exists
class HomePage extends StatefulWidget {
String UserType;
String userID;
HomePage({Key key,@required this.UserType,@required this.userID}):super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String owneruerID;
dynamic uploadusertypes;
final List<Widget>_children=[
UploadPage(UserSID:owneruerID,uploadusertypes:uploadusertypes),
ProfilePage(userProfileID:owneruerID),
];
void initState(){
super.initState();
uploadusertypes= widget.UserType;
owneruerID = widget.userID;
}
}