1

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.

1 Answer 1

3

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),
            ],
          );
        })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.