Flutter / Dart:在这种情况下如何传递数据?

问题描述 投票:0回答:1

我有一个数据类-业务我有一个业务清单-商店

我想实现商店的GridView ...但是,我想使用我创建的名为“名片”的对象的格式

我不知道如何从商店清单中获取数据并将其显示在Gridview中正在调用的“名片”上]

浏览了许多utube vid和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号码名片。我相信我应该能够访问商家的商店列表以及该列表中每个商家的名称。

[我有一个数据类-业务,我有一个业务列表-我想实现商店的GridView ...但是,我想使用我创建的称为“我是名片”的对象的格式...] >

flutter dart data-modeling
1个回答
0
投票

找到了!又花了我一些尝试!

children: stores.map(
        (data) => businessCard(
          bizName: data.name,
© www.soinside.com 2019 - 2024. All rights reserved.