简体   繁体   中英

'Object' can't be assigned to the parameter type 'ImageProvider<Object>'

I get following error when using Circle Avatar:

The argument type 'Object' can't be assigned to the parameter type 'ImageProvider'

This is the code:

CircleAvatar(
   backgroundImage: snapshot.data['imageUrl'] == "" 
    ? AssetImage('assets/img.png')
    : NetworkImage(snapshot.data['imageUrl']));

代码和错误的图片

this is currently an open issue on GitHub with dart 2.12.

As a workaround you can cast the object

AssetImage('assets/img.png') as ImageProvider,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM