How to make an image provider from an Icon in flutter for FadeInImage widget?

前端 未结 2 582
长情又很酷
长情又很酷 2020-12-16 12:58

I want to use FadeInImage with an icon as a placeholder.

FadeInImage has few constructors.

In a default constructor it takes

相关标签:
2条回答
  • 2020-12-16 13:15

    Icons are really just text from a font, so its tricky to make that into an image. The trick in the cookbook should work. Use a Stack with the Icon behind and a transparent placeholder.

        body: Stack(
          children: <Widget>[
            Center(child: Icon(Icons.something)),
            Center(
              child: FadeInImage.memoryNetwork(
                placeholder: kTransparentImage,
                image:
                    'https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true',
              ),
            ),
          ],
        ),
    
    0 讨论(0)
  • 2020-12-16 13:33

    There is also a package that can take Widget as a placeholder

    https://pub.dartlang.org/packages/cached_network_image

      ClipOval(
        child: CachedNetworkImage(
      placeholder: new Container(
        height: height,
        width: height,
        child: Icon(Icons.accessibility),
        color: kGrey400,
      ),
      imageUrl: photoUrl,
      height: height,
      fit: BoxFit.cover,
    ));
    
    0 讨论(0)
提交回复
热议问题