Home > database >  How can i assign local image to avatar source using flutter avatar package
How can i assign local image to avatar source using flutter avatar package

Time:03-30

I'm trying to make flutter app that contain list of persons. Then foreach person i'm expected draw avatar using 'flutter avatars package'. I have a local list of image in my app then a want display them in avatar component.

child: Avatar(
   name: '${person.firstname} ${person.lastname}',
   shape: AvatarShape.circle(20),
   sources: [
      /*I don't know how add local image element to source*/                
   ],
)

CodePudding user response:

You have to add the imaged to pubspec.yaml under

assets:
 assets/image.jpg

and then go to the doc for the packaged and it will show you have to add a local image like so if its from the right package

child: Avatar(
   name: '${person.firstname} ${person.lastname}',
   shape: AvatarShape.circle(20),
   sources: [
     GenericSource(image: AsssetImage('assets/image.jpg')              
   ],
)
  • Related