I want to use FadeInImage
with an icon as a placeholder.
FadeInImage
has few constructors.
In a default constructor it takes ImageProvider
as a placeholder, and in FadeInImage.MemoryNetwork(
it takes Uint8List
as a memory placeholder.
The third constructor creates AssetImage, but I doubt that is useful here.
Is there any way to convert an Icon to one of those data types?
Example signature:
FadeInImage(placeholder: iconPlaceholder, image: NetworkImage("url"))
To set the image to be displayed as the icon, you need to pass an ImageProvider instance. For that purpose, you need to create an instance of any class that's a descendant of ImageProvider such as AssetImage , NetworkImage , MemoryImage , and ResizeImage . The below example uses AssetImage to load the image.
A graphical icon widget drawn with a glyph from a font described in an IconData such as material's predefined IconDatas in Icons. Icons are not interactive. For an interactive icon, consider material's IconButton. There must be an ambient Directionality widget when using Icon.
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',
),
),
],
),
For kTransparentImage
, see this.
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,
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With