I am using FadeInImage Widget to show a Network Image in my App. As I want to use the placeholder property of FadeInImage, I can't use NetworkImage or Image.Network Widget.
Now I want to make FadeInImage circular so I tried to use following options.
FadeInImage inside Container to make it circular but the DecorationImage property does not allow FadeInImage
CircleAvatar but backgroundImage property of CircleAvatar does not allow FadeInImage
cached_network_image library of flutter but was facing the same issueClipRRect to make it circular but still it does not workFollowing is my code
Container(
width: 50.0,
height: 50.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: FadeInImage(
placeholder: AssetImage("images/alex.jpg"),
image: NetworkImage(
"https://cdn1.thr.com/sites/default/files/imagecache/scale_crop_768_433/2018/02/gettyimages-862145286_copy_-_h_2018.jpg")),
),
);
Wrap FadeInImage widget with ClipOval then wrao ClipOval widget with AspectRatio:
AspectRatio(
aspectRatio: 1/1,
child: ClipOval(
child: FadeInImage.assetNetwork(
fit: BoxFit.cover,
placeholder: "Your-placeholder-path",
image: "Your-Image-Url"),
),
);
Set the width and height property of FadeInImage and it should work.
ClipOval(
child: CachedNetworkImage(
fit: BoxFit.cover,
width: 50,
height: 50,
placeholder: AssetImage("images/alex.jpg"),
imageUrl:"https://cdn1.thr.com/sites/default/files/imagecache/scale_crop_768_433/2018/02/gettyimages-862145286_copy_-_h_2018.jpg",
),
)

I created a custom widget for this:
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
class CircleCachedNetworkAvatar extends StatelessWidget {
final String url;
final double size;
CircleCachedNetworkAvatar({@required this.url, this.size = 50.0});
@override
Widget build(BuildContext context) {
return Container(
height: size,
width: size,
child: url != null
? ClipOval(
child: CachedNetworkImage(
fadeInDuration: const Duration(seconds: 0),
fadeOutDuration: const Duration(seconds: 0),
imageUrl: url,
placeholder: Container(
color: Colors.greenAccent, child: Icon(Icons.person)),
fit: BoxFit.cover,
),
)
: CircleAvatar(
backgroundColor: Colors.greenAccent,
child: Icon(Icons.person)));
}
}
What do you think about this code?
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