Need help in integrating array list into Flutter GridView

1,109

Use GridView.builder

      GridView.builder(
        itemCount: fbdata.length,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            childAspectRatio: 3 / 2,
            crossAxisSpacing: 10,
            mainAxisSpacing: 10),
        itemBuilder: (ctx, index) {
          return Column(
            children: <Widget>[
              Text(fbdata[index].name),
              Text(fbdata[index].imageUrl),
            ],
          );
        })
Share:
1,109
marcusaureliusbrutus
Author by

marcusaureliusbrutus

Updated on December 22, 2022

Comments

  • marcusaureliusbrutus
    marcusaureliusbrutus 5 months

    I used to use RecyclerView in AS but I have recently started learning Flutter.

    I've been searching around and I can't seem to find a cohesive document/reference/example to allow an array List to appear in GridView.

    List<Test> fbToJson(gdata) {
      var tojson = json.decode(gdata).cast<Map<String, dynamic>>();
      return tojson.map<Test>((json) => Test.fromJson(json)).toList();
    }
    class Test {
      String imageUrl;
      String name;
      Test({this.imageUrl,this.name});
      factory Test.fromJson(Map<String, dynamic> json) {
         return Test(
         imageUrl: json['imageUrl'] as String,
         name:  json['name'] as String
      );
    }
    }
    

    I was already able to pass the above list array to another activity class via Navigator.

    My confusion is since this is a list array, I need to iterate through it to show the listed values eg.

    for(var i in fbdata){
      var myname = i.name;
    }
    

    I can't find any doc/resource to help show how to integrate this to a gridview if I wish to show both name and urlimage.

    Thanks in advance.