How to assign a widget to placeholder in FadeInImage?

Viewed 779

Code:

FadeInImage(
  placeholder: MyOwnWidget(), // error
  image: NetworkImage(url),
)

I want to provide my own widget to placeholder, how can I do that, is there any workaround?

2 Answers

Seems like it isn't possible with FadeInImage and I'll have to use

Image.network(
  url,
  loadingBuilder: (_, child, progress) {
    if (progress == null) return child;
    return MyOwnWidget();
  },
)

You can do like this,

Stack(
          children: <Widget>[
            const Center(child: CircularProgressIndicator()),
            Center(
              child: FadeInImage.memoryNetwork(
                placeholder: kTransparentImage,
                image: 'https://picsum.photos/250?image=9',
              ),
            ),
          ],
        )

For transparent image use https://pub.dev/packages/transparent_image

Related