Please help. I have categoryListItems function to build list view.
ListView categoryListItems() {
return ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.all(0),
itemCount: this.count,
itemBuilder: (BuildContext context, int index) {
return ListTile(
dense: true,
title: Text(
this.cats[index].title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
onTap: () => openAddCategoryDialog(this.cats[index]),
);
},
);
}
Also I have openAddCategoryDialog function with give argument for onTap method
void openAddCategoryDialog(Category cat) async {
Category save = await Navigator.of(context).push(
new MaterialPageRoute<Category>(
builder: (BuildContext context) {
return new AddCategoryScreen(cat);
},
fullscreenDialog: true,
),
);
if (save != null) {
setState(() {
getData();
});
}
}
Once debugging I get below error. The following _TypeError was thrown building LayoutScreen(dirty, state: _LayoutScreenState#35628): type '(Category) => void' is not a subtype of type '(() => void)?
Categoryas a required positional argument, and you pass that function where a (optional) function that takes no argument is expected. However, I don't see that in the code you've shown. Are you sure that the error comes from this code and not from somewhere else? - jamesdlin