【发布时间】:2019-09-11 01:46:48
【问题描述】:
是否可以将列表从 dart 文件移动到自己的 dart 文件中,然后导入列表?
我只显示了四个主要的墨水池按钮。除此之外,我无法克服 ancenstortype 错误。我相信小部件没有正确传递。
List<BuyItem> buyItemList = [
BuyItem('Add a pack of 10 for \$2.99', 'assets/scantron.png'),
BuyItem('Add a pack of 5 for \$1.99', 'assets/pens.png'),
BuyItem('Add one for \$1.49', 'assets/notebook.png'),
BuyItem('Add one for \$3.49', 'assets/calculator.png'),
BuyItem('Add one for \$0.99', 'assets/cliff bar.png'),
BuyItem('Add one for \$1.25', 'assets/apple.png'),
.
.
.
Product('Notebook', 'assets/notebook.png', () {
Navigator.of(context).push(ItemsBuyPage([buyItemList[2]]));
}),
Product('Calculator', 'assets/calculator.png', () {
Navigator.of(context).push(ItemsBuyPage([buyItemList[3]]));
}),
];
List<Product> foodList = [
Product('Cliff Bar', 'assets/cliff bar.png', () {
Navigator.of(context).push(ItemsBuyPage([buyItemList[4]]));
}),
Produ
Product('Coffee', 'assets/coffee.png', () {
Navigator.of(context).push(ItemsBuyPage([buyItemList[15]]));
}),
];
List<MainButtons> buttonList = [
.
.
.
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => BrowsePage(buttonList)));
//}
}
按下四个主要按钮之一后,我应该能够转到导航到的屏幕。
新代码
List<MainButtons> buttonList = [
MainButtons(
Icons.domain,
'Class Supplies',
'Page(suppliesList)',
),
MainButtons(
Icons.local_dining,
'Food and Snacks',
'Page(foodList)'
),
MainButtons(
Icons.hot_tub,
'Personal Supplies',
'Page(toiletriesList)'
,
),
MainButtons(
Icons.local_cafe,
'Drinks',
'Page(drinksList)',
),
];
错误:参数类型“String”不能分配给参数类型“Route”。
MainButtons(this.image, this.name, this.onTap);
final IconData image;
final String name;
final String onTap;
.
.
.
onTap: () {
Navigator.of(context).push(onTap);
},
【问题讨论】: