我在尝试构建交错网格视图并将变量传递给 Material 类时出现错误
Undefined name 'viewModel'
:
Material Items(String heading) {
return Material(
child: InkWell(
onTap: () {
if (heading ==
('Text')) {
showMainDialog(context, viewModel); <- The error is here: Undefined name 'viewModel'
}
},
));
}
@override
Widget build(BuildContext context) {
body: SingleChildScrollView(child: loadMainPage(viewModel)),
}
Widget loadMainPage(ViewModel viewModel) {
return StaggeredGridView.count(
children: <Widget>[
Items(
('Text')
),
],
staggeredTiles: [
StaggeredTile.extent(1, 150.0),
],
);
}
showMainDialog(BuildContext context, ViewModel viewModel) {
Dialog simpleDialog = Dialog(
...
showDialog(
context: context, builder: (BuildContext context) => simpleDialog);
}
}