Flutter/Dart: 这种情况下如何传递数据?
Flutter/Dart: How do I pass data in this case?
我有一个数据Class - 业务
我有一份商家列表 - 商店
我想实现商店的 GridView...
但是,我想使用我创建的名为 Business Card
的对象的格式
我不知道如何从商店列表中获取数据
并将其显示在 Gridview
中调用的 "Business Card" 上
浏览了一些 utube vids 和 flutter 文档
filename: Business-data.dart
class Business {
String bizname, price, primarycategory, image;
bool userLiked;
double discount;
Business({this.bizname, this.price, this.discount, this.image, this.userLiked});
}
List<Business> stores = [
Business(
bizname: "Company",
image: "assets/images/company.png",
userLiked: true,
),
Business(
name: "Company",
image: "assets/images/company2.png",
userLiked: false,
),
Business(
name: "Company",
image: 'assets/images/company3.png',
userLiked: false,
),
Business(
name: "Company",
image: "assets/images/restaurant.png",
userLiked: true,
)
];
filename: Business Card.dart
import 'package:theboardwalk/homeScreen/Data/Business-data.dart';
Widget BusinessCard(BuildContext context,
{String bizName, Image bizLogo,double onLike, onTapped, bool isProductPage = false}) {
return
RaisedButton(
color: white,
elevation: 20,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return BusinessScreen();
},
),
);
},
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Center(child: Text(bizName)),
// Image.asset(
// image,
// //color: Colors.red,
// ),
],
),
);
}
filename: miniAppGrid.dart
import 'package:theboardwalk/homeScreen/Components/3 MiniAppGrid/3.1 Business Card.dart';
import 'package:theboardwalk/homeScreen/Data/Business.dart';
import '../../Data/Business.dart';
Widget MiniAppGrid(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height * .650,
width: MediaQuery.of(context).size.width * .96,
child: GridView.count(
// itemCount: stores.length,
crossAxisSpacing: MediaQuery.of(context).size.width * .035,
mainAxisSpacing: MediaQuery.of(context).size.height * .0175,
crossAxisCount: 2,
children: stores.map(
(data) => BusinessCard(
bizName: (Business.bizname),
bizLogo: image,
),
),
),
);
}
我希望根据我拥有的商店列表制作 X 份名片。我相信我应该能够访问商家的商店列表以及该列表中每个商家的名称。
找到了!我又试了几次!
children: stores.map(
(data) => businessCard(
bizName: data.name,
我有一个数据Class - 业务 我有一份商家列表 - 商店
我想实现商店的 GridView... 但是,我想使用我创建的名为 Business Card
的对象的格式我不知道如何从商店列表中获取数据 并将其显示在 Gridview
中调用的 "Business Card" 上浏览了一些 utube vids 和 flutter 文档
filename: Business-data.dart
class Business {
String bizname, price, primarycategory, image;
bool userLiked;
double discount;
Business({this.bizname, this.price, this.discount, this.image, this.userLiked});
}
List<Business> stores = [
Business(
bizname: "Company",
image: "assets/images/company.png",
userLiked: true,
),
Business(
name: "Company",
image: "assets/images/company2.png",
userLiked: false,
),
Business(
name: "Company",
image: 'assets/images/company3.png',
userLiked: false,
),
Business(
name: "Company",
image: "assets/images/restaurant.png",
userLiked: true,
)
];
filename: Business Card.dart
import 'package:theboardwalk/homeScreen/Data/Business-data.dart';
Widget BusinessCard(BuildContext context,
{String bizName, Image bizLogo,double onLike, onTapped, bool isProductPage = false}) {
return
RaisedButton(
color: white,
elevation: 20,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return BusinessScreen();
},
),
);
},
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Center(child: Text(bizName)),
// Image.asset(
// image,
// //color: Colors.red,
// ),
],
),
);
}
filename: miniAppGrid.dart
import 'package:theboardwalk/homeScreen/Components/3 MiniAppGrid/3.1 Business Card.dart';
import 'package:theboardwalk/homeScreen/Data/Business.dart';
import '../../Data/Business.dart';
Widget MiniAppGrid(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height * .650,
width: MediaQuery.of(context).size.width * .96,
child: GridView.count(
// itemCount: stores.length,
crossAxisSpacing: MediaQuery.of(context).size.width * .035,
mainAxisSpacing: MediaQuery.of(context).size.height * .0175,
crossAxisCount: 2,
children: stores.map(
(data) => BusinessCard(
bizName: (Business.bizname),
bizLogo: image,
),
),
),
);
}
我希望根据我拥有的商店列表制作 X 份名片。我相信我应该能够访问商家的商店列表以及该列表中每个商家的名称。
找到了!我又试了几次!
children: stores.map(
(data) => businessCard(
bizName: data.name,