Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to CENTER IconButton in CircleAvatar with Stack Widget

So here’s the situation. I want to build a Spotify-like button where the circular avatar is shown and on top of that, an icon button is been placed. I want to make the icon as much bigger to cover the whole avatar as possible but have failed after trying several answers already from this platform.

So, here’s what I want. Center the IconButton in the avatar covering the whole size of the Circular Avatar. I’m attaching some screenshots as well as code. Have a look at it.

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HERE’s THE CODE

import ‘package:flutter/material.dart’;

class AddArtistWidget extends StatelessWidget {
const AddArtistWidget({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: [
const CircleAvatar(
backgroundColor: Colors.black26,
radius: 70,
),
IconButton(
padding: EdgeInsets.zero,
onPressed: () {},
icon: const Icon(
Icons.add,
size: 100,
color: Colors.white,
),
),
],
);
}
}

HERE’s THE OUTPUT OF MY CODE

AND THAT’s WHAT I WANT TO MAKE

Thanks again!

>Solution :

     Stack( alignment: Alignment.topCenter, 
children: [ const CircleAvatar( backgroundColor: Colors.black26, radius: 70, ), 
IconButton( padding: EdgeInsets.zero, onPressed: () {},
 icon: const Icon( Icons.add, size: 100,
 color: Colors.white, ), ), ], );

replace this with

 CircleAvatar(
                backgroundColor: Colors.black26,
                radius: 70,
                child: GestureDetector(
                  onTap: () {},
                  child: const Icon(
                    Icons.add,
                    size: 100,
                    color: Colors.white,
                  ),
                ),
              ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading