How can i add the images stacked over one another - flutter

I want to add a different persons image as attached(The images inside circle avatar stacked over one another).How to achieve this.
I tried the following code but didn't get the result as expected
Padding(
padding: EdgeInsets.only(top: 7),
child: Stack(
children: <Widget>[
Positioned(
left: 0,
child: CircleAvatar(
radius: radius,
// backgroundColor: Colors.red,
backgroundImage: AssetImage(AssetImages.CHALLENGEPERSON1),
backgroundColor: Colors
.transparent, // Provide your custom image // Provide your custom image
),
),
Positioned(
left: 12,
child: CircleAvatar(
radius: radius,
// backgroundColor: Colors.red,
backgroundImage: AssetImage(
AssetImages.CHALLENGEPERSON1), // Provide your custom image
backgroundColor:
Colors.transparent, // Provide your custom image \
),
),
Positioned(
left: 28,
child: CircleAvatar(
radius: radius,
// backgroundColor: Colors.red,
backgroundImage: AssetImage(AssetImages.CHALLENGEPERSON1),
backgroundColor: Colors.transparent, // Provide your custom image
),
),
Positioned(
left: 35,
child: CircleAvatar(
radius: radius - 5,
// backgroundColor: Colors.red,
backgroundImage: AssetImage(AssetImages.ADDITIONAL),
backgroundColor:
Colors.transparent, // Provide your custom image
),
)
],
),

you can create this UI like this
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
const Home({super.key});
#override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
List imagesList = [//your images list];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int i = 0; i < imagesList.length; i++)
Container(
margin: EdgeInsets.symmetric(vertical: 0),
child: Align(
widthFactor: 0.5,
child: CircleAvatar(
radius: 50,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(
imagesList[i],
),
),
)),
)
],
),
SizedBox(
width: 20,
),
CircleAvatar(
backgroundColor: Colors.grey.shade200,
radius: 40,
child: Center(child: Icon(Icons.add)),
),
],
),
),
),
);
}
}

Try below code I am try your provided Image, change my images with your image
Container(
padding: const EdgeInsets.all(8.0),
height: 200.0,
width: 500.0,
child: Stack(
children: <Widget>[
Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
border: Border.all(),
image: DecorationImage(
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png',
),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
),
Positioned(
left: 40.0,
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
border: Border.all(),
image: DecorationImage(
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png',
),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
),
),
Positioned(
left: 80.0,
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
border: Border.all(),
image: DecorationImage(
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png',
),
fit: BoxFit.fill,
),
shape: BoxShape.circle,
),
),
),
Positioned(
left: 120.0,
child: Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
border: Border.all(),
shape: BoxShape.circle,
),
child: Icon(Icons.add,size: 40,),
),
),
],
),
),
Result->

Related

how Insert the text in widget Flutter?

How should I do to add text inside a widget, so that in this way I can notify the user of my app that they can change their profile picture by pressing that camera button I want to insert the text "Change your profile picture here" into the widget _Foto?
my goal is that under the profile image there is a text so that the user knows that he can change his profile image by clicking on the button
Widget _Foto() {
return new GestureDetector(
onTap: () => imagePicker.showDialog(context),
child: new Center(
child: _image == null
? FutureBuilder<String>(
future: globals.SharedPreferencesHelper
.getDataAgentUserProfileImage(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new Stack(children: [
Container(
margin: EdgeInsets.only(top: 48),
height: 0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.0),
),
),
Align(
alignment: Alignment.topCenter,
child: SizedBox(
child: CircleAvatar(
radius: 40.0,
backgroundColor: Colors.white,
child: CircleAvatar(
child: Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 20.0,
child: Icon(
Icons.camera_alt,
size: 25.0,
color: Color(0xFF404040),
),
),
),
radius: 38.0,
backgroundImage: new NetworkImage(
systemProfilesUsersImagesRepository +
snapshot.data!),
),
),
)),
]);
} else if (snapshot.hasError) {
return Stack(
children: <Widget>[
new Center(
child: new CircleAvatar(
radius: 50.0,
backgroundColor: Colors.white,
),
),
new Center(
child: Container(
width: 100.0,
height: 100.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new AssetImage(
"images/userpic.png")))),
),
],
);
} else {
return Container(
width: 100.0,
height: 100.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image:
new AssetImage("images/userpic.png"))));
}
})
: new Container(
height: 100.0,
width: 100.0,
child: new CircleAvatar(
radius: 40.0,
backgroundColor: Colors.white,
child: CircleAvatar(
child: Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 20.0,
child: Icon(
Icons.camera_alt,
size: 23.0,
color: Color(0xFF404040),
),
),
),
radius: 38.0,
backgroundImage: FileImage(_image!),
),
),
)),
);
You can wrap the Center widget Column and include another Text child.
Widget _Foto() {
return GestureDetector(
onTap: () => imagePicker.showDialog(context),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: _image == null
? FutureBuilder<String>(
future: globals.SharedPreferencesHelper
.getDataAgentUserProfileImage(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Stack(children: [
Container(
margin: EdgeInsets.only(top: 48),
height: 0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.0),
),
),
Align(
alignment: Alignment.topCenter,
child: SizedBox(
child: CircleAvatar(
radius: 40.0,
backgroundColor: Colors.white,
child: CircleAvatar(
child: Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 20.0,
child: Icon(
Icons.camera_alt,
size: 25.0,
color: Color(0xFF404040),
),
),
),
radius: 38.0,
backgroundImage: NetworkImage(
systemProfilesUsersImagesRepository +
snapshot.data!),
),
),
)),
]);
} else if (snapshot.hasError) {
return Stack(
children: <Widget>[
Center(
child: CircleAvatar(
radius: 50.0,
backgroundColor: Colors.white,
),
),
Center(
child: Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
"images/userpic.png")))),
),
],
);
} else {
return Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image:
AssetImage("images/userpic.png"))));
}
})
: Container(
height: 100.0,
width: 100.0,
child: CircleAvatar(
radius: 40.0,
backgroundColor: Colors.white,
child: CircleAvatar(
child: Align(
alignment: Alignment.bottomRight,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 20.0,
child: Icon(
Icons.camera_alt,
size: 23.0,
color: Color(0xFF404040),
),
),
),
radius: 38.0,
backgroundImage: FileImage(_image!),
),
),
)),
Text("Change your profile picture here")
],
),
);
}
You can add a column and display it
CircleAvatar(
child: Column(
mainAxisSize: MainAxisSize.min,
children : [
Icon(Icons.camera),
Flexible(
child: Text("click here to change the profile pic")
),
]
)
)

Flutter how to create circular border around icon and align an image top of the circular border

I am trying to use the below code to create a circular border around an image and align an icon on top of the circular border. What I am looking at is as the image below:
And my code is as below but it didn't work out perfectly:
Stack(
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: CircleAvatar(
radius: 70,
backgroundImage: AssetImage('assets/person_icon.png'),
backgroundColor: Colors.white,
//
)),
),
Positioned(
bottom: 100,
right: 50,
child: InkWell(
onTap: () {},
child: Container(
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(Icons.add_a_photo, color: colorBlue),
),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(
50,
),
),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(2, 4),
color: Colors.black.withOpacity(
0.3,
),
blurRadius: 3,
),
]),
),
)),
],
),
As you can above I am trying to use stack to lay each widget on top of each other but couldn't achieve that. I don't if anyone can help out where I missed it or give me a good idea of how to come about this.
Thanks in advance.
Default clipBehavior on Stack is hardEdge.
Use clipBehavior: Clip.none on Stack.
And to have circle shape
use customBorder: CircleBorder(), on InkWell.
use shape: BoxShape.circle instead of circular radius on container.
For better alignment use
Positioned(
top: -12,//half of icon size
left: 0,
right: 0,
Also better providing size on Stack like here.
/// fixing top widget size
SizedBox.square(
dimension: squareSize,
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
clipBehavior: Clip.hardEdge,
decoration: const ShapeDecoration(
shape: CircleBorder(),
),
child: Image.asset(
'assets/images/image01.png',
fit: BoxFit.cover,
),
),
),
),
///background circle, you also do it on image widget
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: 5, color: Colors.green),
),
),
Positioned(
top: -12, // half of icon size
left: 0,
right: 0,
child: InkWell(
onTap: () {},
customBorder: const CircleBorder(),
child: Container(
width: 24 + 12, //icon size+padding
height: 24 + 12,
alignment: Alignment.center,
decoration: const ShapeDecoration(
shape: CircleBorder(),
color: Colors.green,
),
child: Icon(
Icons.add_a_photo,
color: Colors.white,
),
),
),
),
],
),
)
Play with sizes and decoration
Just add to the Stack Widget the Property clipBehavior: Clip.none,.
The clipBehavior will befine how to handle the Clip of the Stack Widget. Standard is hardEdge and cuts your icon off.
So your finished working Code is
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: CircleAvatar(
radius: 70,
backgroundImage: AssetImage('assets/person_icon.png'),
backgroundColor: Colors.white,
//
),
),
),
Positioned(
bottom: 100,
right: 50,
child: InkWell(
onTap: () {},
child: Container(
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(Icons.add_a_photo, color: Colors.blue),
),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(
50,
),
),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(2, 4),
color: Colors.black.withOpacity(
0.3,
),
blurRadius: 3,
),
],
),
),
),
),
],
),
),
);
}
}
void main() {
runApp(
const MaterialApp(
home: MyApp(),
),
);
}
Try below code
Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 25),
child: Container(
padding: EdgeInsets.all(8),
height: 270,
width: 270,
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: ClipOval(
child: Container(
height: 250,
width: 250,
child: Image.network(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
fit: BoxFit.cover,
),
),
),
),
),
),
Positioned(
top: 0,
left: .0,
right: .0,
child: Center(
child: CircleAvatar(
backgroundColor: Colors.green,
radius: 30.0,
child: Icon(
Icons.check,
color: Colors.white,
size: 40,
),
),
),
)
],
),
Result Screen->
user this below code to achieve
Center(
child: Stack(
children: [
Container(
height: 200,
child: CircleAvatar(
radius: 75,
backgroundColor: Colors.green,
child: CircleAvatar(
radius: 70,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: const CircleAvatar(
radius: 60,
backgroundImage: NetworkImage("https://helostatus.com/wp-content/uploads/2021/09/pic-for-WhatsApp-HD.jpg"),
backgroundColor: Colors.white,
//
)),
),
),
),
Positioned(
left: 16,
right: 16,
top: 8,
child: InkWell(
onTap: () {},
child: const CircleAvatar(
backgroundColor: Colors.green,
radius: 16,
child: Icon(
Icons.check,
color: Colors.white,
),
)),
),
],
),
)[enter image description here][1]
Thanks all for the contribution but here is what works perfectly for what I'm looking at. I added clipBehavior and set Clip to noneclipBehavior: Clip.none, added ClipOval in a Container and set it margin and padding respectively to give the space between the green circular border and the profile image. I also, added another Container inside my ClipOval so as to add my image as a child to it. Find below my final code:
Center(
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 60,
backgroundColor: colorGreen,
child:Container(
padding: EdgeInsets.all(4),
margin: EdgeInsets.all(3),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: ClipOval(
child: Container(
height: 250,
width: 250,
child: Image.network(
'my image link',
fit: BoxFit.cover,
),
),
)
)),
Positioned(
bottom: 100,
right: 45,
child: InkWell(
onTap: () {},
child: Center(
child: CircleAvatar(
backgroundColor: colorGreen,
radius: 15.0,
child: Icon(
Icons.check,
color: Colors.white,
size: 25,
),
),
),
),
),
],
),
),

how to position an image on top of another "card"?

This is my first time here
I face a little problem which is the image that I wanted to put on top of the card do not work properly, the rest of it didn't display
I used (stack & positioned)
What should I do ??
Note : I'm beginner 👀
this is the code :
SizedBox(
width: 500,
height: 100,
child: Container(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Card(
color: Colors.grey.shade400,
child: Stack(children: [
Positioned(
bottom: 40,
left: 150,
child: CircleAvatar(
child: ClipOval(
child: Image.asset(
"assets/images/guy.jpg",
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
backgroundColor: Colors.transparent,
radius: 50,
),
),
]),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 10),
),
)),
and this is the the output :
enter image description here
and i wanted to be like this : enter image description here
if you want like that, then you need to put SizedBox and add size (height and or width) on it it acts as invicible widget to put space on it.
Stack
--Positioned (top 0)
----Column
------SizedBox (add height here around 50x50 px)
------Image (100x100 px)
--Card
Try below code hope its helpful to you. refer for thar Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10),
child: Container(
height: 320,
width: 420,
margin: EdgeInsets.all(16.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Your Other Widgets',
),
],
),
),
),
),
),
Container(
width: 50,
height: 50,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(1),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/1.png',
),
),
),
),
),
)
],
),
Your Result screen->

making the circular avatar show at the top of the screen

How can I make the circleavatar to be placed at the top of the container
you can use Stack for this. like:
...
return Stack(
children: [
Positioned.filled( child:
Scaffold(
appBar: ...
body: Column([
DecoratedBox(
...
)
]),
)),
Positioned(
top: 24,
child:
CircleAvatar( child:
CachedNetworkImage(
...
),
),
),
],
);
something like that.
Try below code hope its helpful to you.refer Stack class here
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 21),
child: Container(
height: 200,
width: double.infinity,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
color: Colors.white,
margin: EdgeInsets.all(
16,
),
),
),
),
Container(
width: 100,
height: 90,
decoration: ShapeDecoration(
shape: CircleBorder(),
color: Colors.transparent,
),
child: CircleAvatar(),
)
],
),
Your result screen->

Flutter Circle Image With Text and circle color?

Widget i want to make:
Widget I made:
This is my code:
Stack(
alignment: Alignment.center,
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
height: 70.0,
width: 70.0,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('https://www.themoviedb.org/t/p/original/wXSnajAZ5ppTKa8Z5zzWGOK85YH.jpg'),
fit: BoxFit.cover,
),
shape: BoxShape.circle,
border: Border.all(color: Colors.red, width: 4.0),
),
),
Container(
height: 70.0,
width: 70.0,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Colors.black87,
Colors.black45,
Colors.transparent,
],
stops: [0, 0.25, 1],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
shape: BoxShape.circle,
border: Border.all(color: Colors.red, width: 4.0),
),
),
Positioned(
left: 30,
right: -15,
bottom: -20,
child: SizedBox(
height: 35.0,
child: Text(
'12 Mart',
style: TextStyle(
color: Colors.white,
backgroundColor: Colors.red,
),
),
),
),
],
),
How do I make a circle around the text and edges under the round picture like the first Widget?
Here is a solution using a Stack and three nested CircleAvatars:
Minimal Working Example:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
final radius = MediaQuery.of(context).size.shortestSide * .4;
final borderWidth = radius / 12;
return Scaffold(
body: Center(
child: Badge(
radius: radius,
borderWidth: borderWidth,
imageUrl:
'https://upload.wikimedia.org/wikipedia/commons/e/ea/Retrato_del_Maestro_Yoda.jpg',
),
),
);
}
}
class Badge extends StatelessWidget {
final double radius;
final double borderWidth;
final String imageUrl;
const Badge({
Key key,
#required this.radius,
#required this.borderWidth,
#required this.imageUrl,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: [
Container(height: 2.1 * radius),
Positioned(
top: 0,
child: CircleAvatar(
radius: radius,
backgroundColor: Colors.indigo,
child: CircleAvatar(
radius: radius - borderWidth,
backgroundColor: Colors.black,
child: CircleAvatar(
radius: radius - 2 * borderWidth,
backgroundImage: NetworkImage(imageUrl),
),
),
),
),
Positioned(
bottom: 0,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 2 * borderWidth,
vertical: borderWidth,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderWidth),
color: Colors.indigo,
),
child: Text(
'12 Mart',
style: TextStyle(color: Colors.white, fontSize: 3 * borderWidth),
),
),
),
],
);
}
}
Here you go:
Stack(
alignment: Alignment.center,
children: [
SizedBox(height: 75), // This container is needed only to set the overall stack height
// for Text to be a bit below Circleavatar
Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
height: 70.0,
width: 70.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
color: Colors.red,
border: Border.all(width: 4, color: Colors.red),
),
child: CircleAvatar(
backgroundImage: NetworkImage(
'https://www.themoviedb.org/t/p/original/wXSnajAZ5ppTKa8Z5zzWGOK85YH.jpg'),
),
),
Positioned(
bottom: 0,
child: Container(
padding: EdgeInsets.all(3),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
color: Colors.red,
),
child: Text(
'12 Mart',
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
),
],
),
Result: