How to pass a <Gridtile> list to Staggeredgridview?

Asked

Viewed 17 times

0

I’m returning a list of images to put on a Staggeredgridview. The problem is that I am unable to find a way to pass the list within Networkimage(). How could I do this?

List<GridTile> gridTilesList = [];
      postsList.forEach((eachPost) {
        gridTilesList.add(GridTile(child: PostTile(eachPost)));
      });
      return StaggeredGridView.countBuilder(
        physics: BouncingScrollPhysics(),
        padding: const EdgeInsets.all(8.0),
        shrinkWrap: true,
        crossAxisCount: 4,
        itemCount: countPost, //staticData.length,
        itemBuilder: (context, index) {
          return Card(
              child: InkWell(
                  child: Hero(
                    tag: index,
                    child: new Image(
                      width: MediaQuery.of(context).size.width,
                      image: NetworkImage(gridTilesList[index]
                          .toString()),
                      fit: BoxFit.cover,
                    ),
                  ),
                  onTap: () {
                    //
                  }));
        },
        staggeredTileBuilder: (index) =>
            StaggeredTile.count(2, index.isEven ? 2 : 3),
        mainAxisSpacing: 8.0,
        crossAxisSpacing: 8.0,
      );

This error is appearing:

EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following Argumenterror was thrown resolving an image codec: Invalid argument(s): No host specified in URI file://Gridtile

Obs: With Gridview working normally:

List<GridTile> gridTilesList = [];
      postsList.forEach((eachPost) {
        gridTilesList.add(GridTile(child: PostTile(eachPost)));
      });
      return GridView.count(
        crossAxisCount: 2,
        padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
        childAspectRatio: 1.0,
        mainAxisSpacing: 10,
        crossAxisSpacing: 1.5,
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        children: gridTilesList,
      );
  • Its variable gridTilesList is a Gridtiles list. What the Networkimage constructor needs is a string that tells an image path. For example, "site.com/abc.jpg". From the moment you put a string that doesn’t represent that, it can’t find an image. I don’t understand which image you want to put on Networkimage.

  • I get it, so maybe it’s not the Networkimage I should use. The list of Gridtiles is returning every image that is in my Image, the idea is to do in Staggeredgridview the same thing I did in Gridview.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.