How to add an icon over a CircleAvatar flutter - flutter

I wanna know how to add an icon like online icon over a CircleAvatar.
I've wrote this code but dont know what to do...
...
CircleAvatar(
backgroundColor: Color(0xff00A3FF),
radius: 35.0,
backgroundImage:
AssetImage("assets/photos/photo-1.jpg"),
),
SizedBox(height: 7.0),
Text(
"Michael",
style: TextStyle(color: Colors.white,: FontWeight.w700),
)
...

What you need here is a Stack widget. Stack widgets allow you to place widgets on top of widgets (meaning order is crucial).
Here I modified your CircleAvatar to add a little green "online" indicator. Make sure to adjust the size and such to fit your needs.
Stack(
children: [
CircleAvatar(
backgroundColor: Color(0xff00A3FF),
backgroundImage: AssetImage("assets/photos/photo-1.jpg"),
radius: 35.0,
),
Positioned(
right: 0,
bottom: 0,
child: Container(
padding: EdgeInsets.all(7.5),
decoration: BoxDecoration(
border: Border.all(
width: 2,
color: Colors.white
),
borderRadius: BorderRadius.circular(90.0),
color: Colors.green
)
)
)
]
)

You don't need a circleAvatar in a circleAvatar.
just use backgroundImage property of the CircleAvatar. like this;
NetworkImage(userAvatarUrl)
more on that:https://api.flutter.dev/flutter/material/CircleAvatar-class.html

You can achieve what you want with nested circle avatars like this:
CircleAvatar(
radius: 58,
backgroundImage: AssetImage("assets/photos/photo-1.jpg"),
child: Stack(
children: [
Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 16,
backgroundColor: Colors.green
)
)
)
]
)
);
The result is like this:
If you want to add an icon, you can do like this
CircleAvatar(
radius: 58,
backgroundImage: AssetImage("assets/photos/photo-1.jpg"),
child: Stack(
children: [
Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
radius: 18,
backgroundColor: Colors.white,
child: Icon(Icons.camera) // change this children
)
)
]
)
);
and the result will be:

Related

How to add shadow just to an image in Card in Circle Avatar in flutter?

I am new to flutter and I want to add shadow to an image in Card (shadow just to an image not the text), how can I do that? Below is the snippet of my code, please let me know how can I do that, thank you.
child: Container(
height: 70,
child: Card(
child: ListTile(
onTap: () {},
title: Text(eventList[index].event_name),
leading: CircleAvatar(
backgroundImage: NetworkImage(eventList[index].imageURL),
),
),
),
),
you can wrap the CircleAvatar with another Container and specify the boxShadow property in its decoration, or for more accuracy, just use a DecoratedBox like this:
Container(
height: 70,
child: Card(
child: ListTile(
onTap: () {},
title: Text("eventList[index].event_name"),
leading: DecoratedBox(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black.withOpacity(.2),
blurRadius: 5,
offset: const Offset(0, 10),
)
]),
child: CircleAvatar(
backgroundImage: NetworkImage("eventList[index].imageURL"),
),
),
),
),
);
You can simply use a Widget called PhysicalModel where it can easily show shadows. You can play with the properties such as color and elevation for your desired shadow effect.
https://api.flutter.dev/flutter/widgets/PhysicalModel-class.html
leading: PhysicalModel(
color: Colors.grey.withOpacity(0.8),
shape: BoxShape.circle,
elevation: 10.0,
child: const CircleAvatar(
backgroundImage: NetworkImage(
'https://i1.sndcdn.com/artworks-000486414654-mt7qdt-t500x500.jpg'),
),
),

Flutter Circular Avatar background color while loading

I used two circular avatar (the first one with a white background just a little bigger to create a white border).
Also the second one have the background property set to white.
However before the image is loaded I see a blue background. As you can see form the code there are no one blu widget on the back...
I wold like to have a black or white background while the widget is loading the picture.
return Scaffold(
backgroundColor: Colors.white,
body: Container(
padding: const EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: appColor,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: 0,
height: 20,
),
const Center(
child: Text(
'WhyBye ',
style: TextStyle(
color: Colors.white,
fontFamily: 'Savor',
fontSize: 40,
),
),
),
const SizedBox(
width: 0,
height: 10,
),
Stack(
//& Stack contenente l'immagine del profilo.
children: [
_image != null
? CircleAvatar(
radius: 100,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 96,
backgroundImage: MemoryImage(_image!),
))
: CircleAvatar(
radius: 100,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 96,
backgroundImage: Variables.userPicUrl.isNotEmpty
? NetworkImage(Variables.userPicUrl)
: null,
)),
Positioned(
//& All'interno del precedente Stack, posizionamento dei pulsanti immagine dalla galleria/fotocamera.
bottom: -10,
left: 15,
child: IconButton(
onPressed: () {
selectImage(ImageSource.gallery);
},
icon: const Icon(Icons.photo_library_rounded),
color: Colors.white,
iconSize: 32,
),
),
Positioned(
bottom: -10,
left: 135,
child: IconButton(
onPressed: () {
selectImage(ImageSource.camera);
},
icon: const Icon(Icons.add_a_photo),
color: Colors.white,
iconSize: 32,
),
),
Following the documentation of CircleAvatar:
If a backgroundColor is not specified, the theme's ThemeData.primaryColorLight is used with dark foreground colors, and ThemeData.primaryColorDark with light foreground colors.
I think you're using the default theme (which uses blue as primary color). Try to explicitly define s transparent color to the inner circle so while it's loading you only see the color of the outer circle
I think you need to add
Blockquote
foregroundImage
ImageProvider?
The foreground image of the circle. [...]
you could decide to use a dark image

How to add icon below CircularAvatar in Flutter?

How can achieve that plus icon as same as the image above.
I tried but am not able.
My code till now i am stucked here! have no idea how to add plus there!
Widget _circleCard(image, name) {
double radius = 32;
return Padding(
padding: const EdgeInsets.only(left: 5, right: 5),
child: Column(
children: [
CircleAvatar(
radius: radius + 4,
backgroundColor: Colors.deepOrange,
child: CircleAvatar(
radius: radius + 2,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: radius,
backgroundImage: AssetImage('assets/$image'),
),
),
),
Text(name)
],
),
);
}
plss help beginner me!
Thanks
Use Stack widget:
Widget _circleCard(image, name) {
double radius = 32;
return Padding(
padding: const EdgeInsets.only(left: 5, right: 5),
child: Column(
children: [
Stack(
children: [
CircleAvatar(
radius: radius + 4,
backgroundColor: Colors.deepOrange,
child: CircleAvatar(
radius: radius + 2,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: radius,
backgroundImage: AssetImage('assets/$image'),
),
),
),
Positioned(
right: 0.0,
bottom: 0.0,
child: Icon(Icons.add),
),
],
),
Text(name)
],
),
);
}

Black screen with circle in the middle

Hi I am trying to create a screen that is completely black, except of a circle in the middle.
I wrote some code that creates the black screen:
Stack(
...
Positioned.fill(
child: Container(
color: Colors.grey.withOpacity(0.5),
)
)
)
But the problem that I am facing is that I don't know how to punch a round hole into the screen so that so that it shows what is behind it in the stack.
Thanks in advance for your answers!
Use CircleAvatar to draw Circles!
Change the radius: property to your desired size, a lot easier than Containers(), or FloatingActionButtons()
Container(
color: Colors.black,
Center(
child: CircleAvatar(
backgroundColor: Colors.red,
radius: 20,
),
),
)
Hope this helps!
This should work for you.
Container(
color: Colors.black,
alignment: Alignment.center,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Text("BackGround Text", style: TextStyle(color: Colors.purple),),
CircleAvatar(
backgroundColor: Colors.white.withOpacity(0.3),
radius: 100,
),
],
)));

How to display a circle avatar image in flutter?

When using the folloing code I would expect a circle avatar image but getting an oval. I tried different parameters like width and height on the Container but that didn't help.
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: new Icon(Icons.star_border, color: Colors.black),
onPressed: () => {},
),
actions: <Widget>[
Container(
//height: 25.0,
// width: 25.0,
child: CircleAvatar(
backgroundImage: NetworkImage('https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c'),
)
/*
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
'https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c')),
),*/
),
],
You are receiving an oval shape because you are using the CircleAvatar widget in Appbar widget which has limited height.
Try adding a parameter radius inside CircleAvatar Widget
it will return the circle shape you want for the image.
try changing radius size value, according to your need.
CircleAvatar(
backgroundImage: NetworkImage('https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c'),
radius: 15.0
)
I've had this issue in the past and have found that wrapping the AvatarCircle in a container with 58 width fixes the Circle radius ratio issue, making it a proper circle shape. One pixel more or less may fit your liking. Give this a try:
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: new Icon(Icons.star_border, color: Colors.black),
onPressed: () => {},
),
actions: <Widget>[
Container(
width: 58.0,
child: CircleAvatar(
backgroundImage: NetworkImage('https://lh3.googleusercontent.com/a-/AAuE7mChgTiAe-N8ibcM3fB_qvGdl2vQ9jvjYv0iOOjB=s96-c'),
)
),
],
i use this code and works with every image size...
CircleAvatar(
child: ClipOval(
child: Image.network(items.logo, fit: BoxFit.fill),
),
backgroundColor: Colors.transparent,
radius: 30,
)
Nothing works for me other than wrapping CircleAvatar with padding of 8.0.
Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
...
),
)