skip to Main Content

I want to change the size of my CircleAvatar widget, but regardless of whether I use a SizedBox or the radius attribute, it does not change its size.

Widget build(BuildContext context) {
return SizedBox(
  width: widget.imageSize,
  height: widget.imageSize, // does not resize
  child: CircleAvatar(
    backgroundColor: Colors.black,
    radius: 5, // does not resize
    foregroundImage: _profilePicture != null
        ? Image.file(
            _profilePicture!,
            fit: BoxFit.cover,
          ).image
        : null,
    child: Text(_initials),
  ),
);
}

Am I missing something?
The widget is inside of my AppBar as the leading:

leading: Transform.translate(
      offset: const Offset(10.0,0.0), 
      child: const ProfileImage(imageSize: 5.0),
    ),

2

Answers


  1. If your CircleAvatar widget is in AppBar‘s leading then use toolbarHeight and leadingWidth.

    The leading widget’s width and height are constrained to be no bigger than leadingWidth and toolbarHeight respectively.

    appBar: AppBar(
      backgroundColor: Colors.blue,
      toolbarHeight: 50, //here
      leadingWidth: 50, //here
      leading: Padding(
        padding: EdgeInsets.all(8.0),
        child: CircleAvatar(
          backgroundColor: Colors.white,
        ),
      ),
    ),
    
    Login or Signup to reply.
  2. Put your SizedBox inside UnconstrainedBox.

    More info https://docs.flutter.dev/ui/layout/constraints#example-13

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search