我正在尝试将标题传递到下一页。请记住,第一页和第二页位于两个不同的 dart 文件中
第一页:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Museo(title: newMuseo[index]['title'])
)
);
第二页:
class Museo extends StatelessWidget {
final String title;
Museo({Key key, @required this.title}) : super(key: key);
Widget build(BuildContext context){
...
}
}
它可以工作,但 Android Studio 一直告诉我:
The named parameter 'title' isn't defined.
我试图删除标题:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Museo(newMuseo[index]['title'])
)
);
但它不再起作用了。
lib/Home.dart:110:70: Error: Too many positional arguments: 0 allowed, but 1 found.
Try removing the extra positional arguments.
builder: (context) => Museo(newMuseo[index]['title'])
^
lib/Museo.dart:294:3: Context: Found this candidate, but the arguments don't match.
Museo({Key key, @required this.title}) : super(key: key);
^^^^^
我遵循了本指南: https ://flutter.dev/docs/cookbook/navigation/passing-data