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
If your
CircleAvatar
widget is inAppBar
‘sleading
then usetoolbarHeight
andleadingWidth
.The
leading
widget’s width and height are constrained to be no bigger thanleadingWidth
andtoolbarHeight
respectively.Put your SizedBox inside UnconstrainedBox.
More info https://docs.flutter.dev/ui/layout/constraints#example-13