...
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CategoryPage(
snapshot.data[index]),
));
},
...
Using the above code i try to pass the service id and the service type to the category page ... class CategoryPage extends StatefulWidget { // final String serviceId; // final String service_type; final String categorydata;
CategoryPage(data, {key, this.categorydata}) : super(key: key);
// @override
// CategoryPage(categorydata) {
// this.serviceId = categorydata.serviceId;
// this.service_type = categorydata.serviceId;
// }
_CategoryPageState createState() =>
_CategoryPageState(categorydata.toString());
}
class _CategoryPageState extends State<CategoryPage> {
String id = "";
_CategoryPageState(String categorydata) {
this.id = categorydata.serviceId;
}
...
From the above code, I need to get the service id and service type and display the tile of the Category page with the service type parameter. Please help me on achieving this result
You have to pass the data like this using the
categorydata
parameter fromCategoryPage
constructor.Here you need to define a final variable inside your
StatefulWidget
class and initialize it from the constructor;Then you can access it from the
State
class methods usingwidget
keyword class, you don't need to pass it.