I have a function in the simple class (not stateful or stateless) but that function is called in the first Screen of the stateful widget, inside the function I have used Navigator.push
to go to the second screen of the stateful widget.
Funtion Code
containerAdder(initialI) {
List<Widget> listViewContainer = List();
for (var j = 0; j < mainListAllPlantDetailsList1.length; j++) {
if (tabsText[initialI] == mainListAllPlantDetailsList1[j].ca) {
listViewContainer.add(
FlatButton(
onPressed: () {
Navigator.push(
context, **(MENTIONED ERROR GIVES OVERHERE )**
MaterialPageRoute(builder: (context) => ParticularPlant2()),
);
},
child: Container(
height: 320,
width: 200,
child: Stack(
children: [
Positioned(
bottom: 10,
child: Container(
padding: EdgeInsets.fromLTRB(25, 50, 20, 20),
height: 150,
width: 180,
decoration: BoxDecoration(
color: Colors.lightGreen,
borderRadius: BorderRadiusDirectional.only(
bottomEnd: Radius.circular(70),
topEnd: Radius.circular(70),
topStart: Radius.circular(70),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(mainListAllPlantDetailsList1[j].ca),
Text(mainListAllPlantDetailsList1[j].pN),
Text(mainListAllPlantDetailsList1[j].pr.toString()),
],
),
),
)
],
)),
),
);
} else {
continue;
}
}
return listViewContainer;
}
There are two other stateful widgets on two other screens whereas in first screen I have called this function.
Help me to understand why does the mentioned error occurs and how to fix it?
Lets pass the context to your function to make it work:
containerAdder(initialI, BuildContext context) {
// Your all of the codes
}
Now, call the containerAdder like:
objectName.containerAdder(intialI, context);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.