How to add icon below CircularAvatar in Flutter? - 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)
],
),
);
}

Related

Image is not fitted when used in leading of ListTile

The asset image is 200x200px, but when it used in leading of ListTile it's not fitted as axpected.
The rendered image looks this way. How to display it proportioanlly 90x90 as it's defined in Image height and width properties?
Card(
key: ValueKey(favorites[index]),
margin: EdgeInsets.all(20),
child: ListTile(
leading: kNoImage,
title: Text(favorites[index]),
subtitle: Text(favorites[index]),
trailing: IconButton(
icon: Icon(Icons.close),
onPressed: () {
debugPrint('entry deleted');
},
),
),
);
const kNoImage = Image(
image: AssetImage('assets/no-user-image.png'),
height: 90,
width: 90,
fit: BoxFit.cover,
);
Change the value of fit to something like BoxFit.scaleDown or BoxFit.contain to get the desired result. See the BoxFit docs to see what these values mean.
The max height for leading widget for your case is ≈56px.
So, if you want to explicitly want to keep it 90, I'd suggest you to make your own ListTile with Row() and Column() which is pretty easy.
This is what I found in ListTile(),
final Offset baseDensity = visualDensity.baseSizeAdjustment;
if (isOneLine)
return (isDense ? 48.0 : 56.0) + baseDensity.dy;
if (isTwoLine)
return (isDense ? 64.0 : 72.0) + baseDensity.dy;
return (isDense ? 76.0 : 88.0) + baseDensity.dy;
I prefer not to use ListTile because of it default behavior. Therefor, I prefer
on dartPad or on Gist
Custom ListTile
Card(
elevation: 8,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(defaultBorderRadiusCircular),
),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SizedBox(
width: 90.0,
height: 90.0,
child: ClipRRect(
borderRadius:
BorderRadius.circular(defaultBorderRadiusCircular),
child: Image.asset(
'imagePath',
width: 90,
height: 90,
fit: BoxFit.cover,
),
),
),
const SizedBox(
width: 24,
),
Column(
children: [
const Text(
'Danau Beretan',
),
const Text(
'Indonesia',
),
],
),
],
),
Row(
children: [
Icon(Icons.star_half_outlined),
Text("4.5"),
],
)
],
),
),
),

How to add an icon over a CircleAvatar 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:

How to align a widget between Listtile´s leading and trailing? - Flutter

I would like to set the width of the progress bar equal to the width between Listtile´s leading and trailing
but till now, I only can fit it to the entire width of the card.
Do I need padding or something?
This is my code (and screenshot of my view):
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[ ListTile(
leading: CircleAvatar(
backgroundImage: AssetImage("assets/vegetables/" + activity.cropImgUrl),
backgroundColor: Colors.white,
),
title: Text(activity.name),
subtitle: Text(howmanydaysleft(activity.daysLeft),
),
trailing: Icon(Icons.chevron_left),
isThreeLine: false,
),
ConstrainedBox(
constraints: const BoxConstraints(minWidth: double.infinity),
child: LinearPercentIndicator(
animation: true,
lineHeight: 15.0,
animationDuration: 500,
percent: completed / 100.0,
center: Text(completed.toString() + "%"),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: colorGreenPrimary,
),
),
SizedBox(height: 10.0),
],
),
),
Screenshot
The title property of the ListTile basically does what you need. Wrap your text in a column and add the progress indicator after your text.
This should do the trick:
Card(
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage("assets/vegetables/" + activity.cropImgUrl),
backgroundColor: Colors.white,
),
title: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(activity.name),
LinearPercentIndicator(
animation: true,
lineHeight: 15.0,
animationDuration: 500,
percent: completed / 100.0,
center: Text(completed.toString() + "%"),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: colorGreenPrimary,
),
],
),
subtitle: Text(
howmanydaysleft(activity.daysLeft),
),
trailing: Icon(Icons.chevron_left),
isThreeLine: false,
),
);

How to overlap two circles?

Can someone help me get this layout with the first circle over the second?
image
I have this function:
Widget overlapped() {
final overlap = 25;
final items = [
Container(
padding: EdgeInsets.only(right: 2),
decoration: new BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
child: CircleAvatar(
radius: 22,
backgroundImage: AssetImage('assets/example_logo.png'),
backgroundColor: Colors.black,
),
),
CircleAvatar(
radius: 22,
backgroundColor: Colors.white,
child: ClipOval(
child: Image.network(
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1200px-Google_%22G%22_Logo.svg.png",
errorBuilder: (context, exception, stackTrace) {
return Container(color: Colors.white);
},
height: 35,
))),
CircleAvatar(
child: Text('+2', style: TextStyle(color: Colors.white)),
backgroundColor: Theme.of(context).canvasColor),
];
List<Widget> stackLayers = List<Widget>.generate(items.length, (index) {
return Container(
padding: EdgeInsets.fromLTRB(index.toDouble() * overlap, 0, 0, 0),
child: items[index],
);
});
return Stack(children: stackLayers);
}
This function whenever I add an item to the array, it adds a widget on the right. But I want the first to be above the second, the second of the third, etc ...
you could use the Stack widget :
Stack(
children:<Widget>:[
Positioned(
right: 130.0,
child:Container(
shape: BoxShape.circle,
)
),
Positioned(
left: 130.0,
child:Container(
shape: BoxShape.circle,
)
),
]
)
Use Stack and Positioned together.
import 'package:flutter/material.dart';
class OverLap extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Overlap'),
),
body: Container(
padding: const EdgeInsets.all(8.0),
width: 500.0,
child: Stack(
children: <Widget>[
//Change according to your icon
Icon(
Icons.flaky,
size: 50.0,
color: Colors.red,
),
Positioned(
left: 20.0,
//Change according to your icon
child: Icon(
Icons.flaky,
size: 50.0,
color: Colors.blue,
),
),
],
),
),
);
}
}

Overflow hidden for CircleAvatar wiget (Flutter)

I need to put icon into CircleAvatar Widget to allow user upload his image.
Something like this:
This is my code:
child: CircleAvatar(
child: Stack(
children: <Widget>[
Positioned(
bottom: 0,
right: 0,
left: 0,
height: 33,
child: Container(
height: 20,
width: 30,
color: Color.fromRGBO(0, 0, 0, .74),
child: Center(
child:
Icon(Icons.photo_camera, color: Colors.grey),
),
),
)
],
),
radius: 68.0,
backgroundImage:
NetworkImage('https://via.placeholder.com/300'),
backgroundColor: Colors.transparent,
)
But I have this result:
Internal box with camera icon overflow from parent widget (CircleAvatar);
What you want can be simply done with - ClipOval
Your Code:
body: Center(
child: CircleAvatar(
child: ClipOval(
child: Stack(
children: <Widget>[
Image.network('https://via.placeholder.com/300'),
Positioned(
bottom: 0,
right: 0,
left: 0,
height: 33,
child: GestureDetector(
onTap: (){
print('upload Clicked');
},
child: Container(
height: 20,
width: 30,
color: Color.fromRGBO(0, 0, 0, .74),
child: Center(
child: Icon(Icons.photo_camera, color: Colors.grey),
),
),
),
),
],
),
),
radius: 68.0,
// backgroundImage: NetworkImage('https://via.placeholder.com/300'),
backgroundColor: Colors.transparent,
),
),
Output:
You can create your Custom Clipper to give the circular bottom to your widget.
You need to use the ClipPath widget for it, pass your widget in your case Container containing your camera icon.
and in clipper pass your CustomClipper.
ClipPath
return ClipPath(
child: your_widget,
clipper: BottomWaveClipper(),
);
CustomCliper
class BottomCircleClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
//your path to draw circle
}
#override
bool shouldReclip(TriangleClipper oldClipper) => false;
}
Here are some links that will help you.
https://iirokrankka.com/2017/09/04/clipping-widgets-with-bezier-curves-in-flutter/
https://medium.com/flutter-community/clipping-in-flutter-e9eaa6b1721a