我试图使用CachedNetworkImage与CircleAvatar,但无法。我得到下面的错误
SuchMethodError (NoSuchMethodError: No constructor '' declared in class 'null'.
Receiver: null
Tried calling: new ())
下面是我的代码相同。
Widget build(BuildContext context) {
if (initials.length == 1) {
initials = initials + ' ';
}
return CachedNetworkImage(
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => new Icon(Icons.error),
fit: BoxFit.contain,
imageUrl: user.profilePic ?? '',
imageBuilder: (context, imageProvider) {
// you can access to imageProvider
return CircleAvatar(
radius: radius,
child: (initials != null)
? Center(
child: Text(initials,
style: TextStyle(
color: Colors.white,
fontSize: radius * 2 / initials.length - 10,
)),
)
: null,
foregroundImage: imageProvider,
backgroundColor:
backgroundColor ?? UtilityFunctions.getRandomColor());
},
);
}
1条答案
按热度按时间uplii1fm1#
尝试使用SizedBox.shrink()代替null