Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make image fit circle avatar

Tags:

flutter

I am trying to display a users profile picture inside a circle avatar widget but only a small portion of it is displayed.

CircleAvatar(
  radius: 70,
  backgroundImage: AssetImage("Images/headshot_1.jpg"),
)

Image I am trying to display

Screenshot on emulator:

Update: I got it to work by wrapping the circle avatar in a row widget.

like image 528
Twix1983 Avatar asked Oct 18 '25 18:10

Twix1983


2 Answers

Wrap CircleAvatar widget with Center widget Example:

Center(child:CircleAvatar())
like image 53
Thào A Vảng Avatar answered Oct 21 '25 23:10

Thào A Vảng


I'd try using foregroundImage. As the official documentation states, this property works well in your use case: a profile picture.

Here's an example with the image you displayed in your question:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: CircleAvatar(
            foregroundImage: AssetImage(
              'myimage.png',
            ),
          ),
        ),
      ),
    );
  }
}

EDIT. Added the obtained UI. Here's what I obtain: Avatarized image

If your problem persists, the problem lies somewhere else in your context / widget tree.

like image 35
venir Avatar answered Oct 22 '25 01:10

venir