Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 我试图从省道图中获取一个键和一个对应的值,但我';不管我怎么努力,我都失败了_Flutter_Dart_Hashmap - Fatal编程技术网

Flutter 我试图从省道图中获取一个键和一个对应的值,但我';不管我怎么努力,我都失败了

Flutter 我试图从省道图中获取一个键和一个对应的值,但我';不管我怎么努力,我都失败了,flutter,dart,hashmap,Flutter,Dart,Hashmap,这是数据;这是一个列表,其中一个项目(信贷供应商)是一个k,v对的地图。我想把每个键和每个值放在它们自己的文本小部件中。代码如下 List<Blog> blogs = [ Blog( title: "She changed religion to marry the man of her dreams- Hamidah and Efraim’s classy Kwanjula ", descrip

这是数据;这是一个列表,其中一个项目(信贷供应商)是一个k,v对的地图。我想把每个键和每个值放在它们自己的文本小部件中。代码如下

List<Blog> blogs = [
      Blog(
        title:
            "She changed religion to marry the man of her dreams- Hamidah and Efraim’s classy Kwanjula ",
        description:
            "Right after their arrival, Efraim and a select few of his entourage went right into "
            "Hamidah’s parents’ house for the basic session of kwanula: to be accepted and born into this home. \n",
        author: "James Arthur",
        date: "09 Jan 20",
        views: 3899,
        comments: 23,
        imagePath: "assets/images/intro.jpg",
        creditVendors: [
          {'Decorator': 'Parties & Events'},
          {'Photography': 'Paramount Images'},
          {'Food': 'Spectrum Restaurant'},
          {'Juice': 'Dalausi Juice'},
          {'Bridal': 'Sheena Collections'},
        ],
      ),
Blog(),
Blog(),
     
];

可以通过贴图的值或键在其上迭代。这是不必要的,因为您的
creditVendors
本身就是一个数组。 然后,您可以使用
ListView
widget从地图的值创建您自己选择的小部件

示例代码

List<dynamic> creditVendors = [
  {'Decorator': 'Parties & Events'},
  {'Photography': 'Paramount Images'},
  {'Food': 'Spectrum Restaurant'},
  {'Juice': 'Dalausi Juice'},
  {'Bridal': 'Sheena Collections'},
];


ListView.builder(
  itemCount: creditVendors.length,
  itemBuilder: (ctx, int index) {
    return ListTile(
*emphasized text*             title: Text(
              '${creditVendors[index].keys.first} - ${creditVendors[index].values.first}'));
   }),

我希望您知道,博客列表只有一个类型为
blog

所以我只做了一个元素。如果你有更多的只需迭代rest,一切都将是一样的

您应该执行以下操作: 然后: 将变量定义为映射,因为
creditVendors
中的内容属于
maps
creditVendors
又是一种
列表
数据类型

// this is just to collect the data inside creditVendors.
  Map decorator;
  Map photography;
  Map food;
  Map juice;
  Map bridal;

  decorator = a.creditVendors[0];
  photography = a.creditVendors[1];
  food = a.creditVendors[2];
  juice = a.creditVendors[3];
  bridal = a.creditVendors[4];
现在:

您可以通过以下方式访问每个地图数据:

Text(decorator['Decorator'],)
Text(photography['Photography'],)
Text(food['Food'],)
Text(juice['Juice'],)
Text(bridal['Bridal'],)


PS.CreditVendor是一个地图列表

你能分享博客类吗?很抱歉,我还没有,但现在我有了。谢谢,我试着给另一个班级的那个班级打电话,但这似乎不起作用。我必须将信用供应商声明为其他博客变量中的一个变量。假设我有100个博客,请允许我用我想调用值的代码编辑我的初始问题creditVendors@Ambrozekweronda您不必将creditVendor定义为另一个变量,我在这里是为了演示而做的。您可以这样称呼它
博客[0]。creditVendors
感谢您的帮助。所以我有一个主页,上面有一系列博客卡片。当你点击一张卡片时,它会把你带到那篇博客文章的页面。那么我可以这样做吗?widget.blog[index].creditVendors?请您帮助并编辑我代码的第二部分,让我看看它是什么样子的?感谢您花时间提供帮助。谢谢。
Blog a = blog[0]; //this will put the first element in a
// this is just to collect the data inside creditVendors.
  Map decorator;
  Map photography;
  Map food;
  Map juice;
  Map bridal;

  decorator = a.creditVendors[0];
  photography = a.creditVendors[1];
  food = a.creditVendors[2];
  juice = a.creditVendors[3];
  bridal = a.creditVendors[4];
Text(decorator['Decorator'],)
Text(photography['Photography'],)
Text(food['Food'],)
Text(juice['Juice'],)
Text(bridal['Bridal'],)