circle in container Flutter - flutter

I have a flutter app,
and I need to make a circle in a container in flutter.
I try to create a container and put an image inside it but the circle is to small,
here is my code:
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("ipage.jpeg),
fit: BoxFit.fitWidth,
),
),
child: Align(
alignment: Alignment.bottomCenter,
child: CircleAvatar(backgroundColor: Colors.transparent,
child: Image.network('https://image.flaticon.com/icons/png/512/147/147144.png' , height:150,),
),
),
),
Please help me how can I do that in flutter

according to your demand you need to use Stack here.
This can archive this way
import 'package:flutter/material.dart';
class FFTBuild extends StatelessWidget {
const FFTBuild({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
final mainBoxheight = MediaQuery.of(context).size.height / 1.9;
return Container(
height: mainBoxheight,
color: Colors.cyanAccent,
child: Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: Image.asset(
"assets/image.jpg",
height: mainBoxheight * .85,
width: double.infinity,
fit: BoxFit.cover,
),
),
Align(
alignment: Alignment.bottomCenter,
child: Image.network(
'https://image.flaticon.com/icons/png/512/147/147144.png',
fit: BoxFit.cover,
width: 150,
height: 150,
),
),
],
),
);
}
}
But I prefer LayoutBuilder instead of using MediaQuery
class FFTBuild extends StatelessWidget {
const FFTBuild({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
// final mainBoxheight = MediaQuery.of(context).size.height / 1.9;
return LayoutBuilder(
builder: (context, constraints) => Container(
height: constraints.maxHeight * .4,
///I added `Container Color`to clarify the thing,
// color: Colors.cyanAccent,
child: Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: Image.asset(
"assets/image.jpg",
height: constraints.maxHeight * .3,
width: constraints.maxWidth,
fit: BoxFit.cover,
),
),
Align(
alignment: Alignment.bottomCenter,
child: Image.network(
'https://image.flaticon.com/icons/png/512/147/147144.png',
fit: BoxFit.cover,
width: 150,
height: 150,
),
),
],
),
),
);
}
}
you may need to set tweak the value according to your desire. let me know if you need more on it.

Simply add radius to the circle avatar and modify circle avatar a bit
Container(
height: MediaQuery.of(context).size.height / 1.9,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("${ImagePath.profileCover}"),
fit: BoxFit.fitWidth,
),
),
child: Align(
alignment: Alignment.bottomCenter,
child: CircleAvatar(
radius: 100,//increase or decrease this for the size of your image
backgroundImage: NetworkImage('https://image.flaticon.com/icons/png/512/147/147144.png'),
),
),
),

Related

insert 2 images together

I am trying to make this design from figma ui design and need to make the 2 pic inside each other but when i do it there is a space between them also the shaded part in the right pic how can i make it
but it did not work so It comes in this shape
import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Row(
children: [
Expanded(
child: Container(
width: 235,
height: 235,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/back1.png',
),
fit: BoxFit.cover,
),
),
),
),
Expanded(
child: Container(
width: 279,
height: 279,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/back1.png',
),
fit: BoxFit.cover,
),
),
),
),
],
),
],
),
);
}
}
So what widget or things to add to make the 2 pic mixed
Use Stack and Positioned ,try this:
Stack(
children: [
Positioned(
top: 0,
right: 0,
child: Image.asset(
'assets/images/back1.png',
fit: BoxFit.cover,
width: 235,
height: 235,
),
),
Positioned(
top: 0,
left: 0,
child: Image.asset(
'assets/images/back1.png',
fit: BoxFit.cover,
width: 279,
height: 279,
),
),
],
),
use Row Widget and size the first image to have half screen using MediaQuery
then wrap the Row it's self to stack and add other one over the stack and position it wherever you want !
I think the best way is to export the two images together in Figma, forming a single image. You can do this by selecting both images > Group > Export. So you don't need almost any code to put them together. I know that's not the point, but it's a creative and valid solution for your case. I hope it helps.

How to resize the width of the image in flutter?

Hello! The width of the image is same as the width of the phone screen. What's the problem and how can I reduce the size of the width? Thank you!
class _SignupProfileImageState extends State<SignupProfileImage> {
bool isUploadImage = false;
var selectedImage;
#override
Widget build(BuildContext context) {
return Positioned(
top: 140,
right: 0,
left: 0,
child: SizedBox(
height: 100,
width: 100,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Container(
width: 50,
child: ClipOval(
child: Image.asset(
'assets/face.jpg',
height: 50.0,
width: 50.0,
fit: BoxFit.fill
],
),
)
);
}
}
You can use CircleAvatar instead of ClipOval like below and it will be a better choice.
CircleAvatar class you can check
Container(
width: 50,
child: CircleAvatar(
backgroundColor: Colors.transparent,
radius: 90.0,
child: Image.asset(
"assets/face.jpg",
height: 50.0,
width: 50.0,
fit: BoxFit.fill
),
)
)
You can use the code below:
class SignupProfileImage extends StatefulWidget {
const SignupProfileImage({Key? key}) : super(key: key);
#override
State<SignupProfileImage> createState() => _SignupProfileImageState();
}
class _SignupProfileImageState extends State<SignupProfileImage> {
bool isUploadImage = false;
#override
Widget build(BuildContext context) => Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 100,
width: 100,
child: ClipOval(
child: Image.asset(
'assets/face.png',
fit: BoxFit.fill,
),
),
),
],
);
}
You can also access the complete source code through GitHub.
If you have further questions, please don't hesitate to write in the comments.
Wrap your SizeBox with Center. It will show your Image in Center
return Positioned(
top: 140,
right: 0,
left: 0,
child: Center( //TODO: Wrap SizedBox with Center
child: SizedBox(
height: 100,
width: 100,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Container(
width: 50,
child: ClipOval(
child: Image.asset(
'assets/face.jpg',
height: 50.0,
width: 50.0,
fit: BoxFit.fill
],
),
),
)
);

How to make Transparent Circle inside colored rectangle

I am new in flutter. I want to make the transparent Circle in side the semi transparent rectangle. Look like below,
I have not idea about that. So please help me to make this type of widget in flutter.
Using ColorFiltered and Stack you can achieve this.
(I took the answer mentioned in the comment and edited to your needs)
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
Image.network(
'https://lh3.googleusercontent.com/proxy/_wrP_GRGOkGw0FLMiR3qeMzlyC-qN8Dd4sND89_xxLZMDIZh204g8PCccS-o9WaL1RKyiVOLGVS9QpodSkMMhOh8kbNh1CY492197-im-4vlFRRdsVqT2g4QbRlNgljDIg',
fit: BoxFit.cover,
), //Give your Image here
ColorFiltered(
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.5),
BlendMode.srcOut,
), // This one will create the magic
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: Colors.black,
backgroundBlendMode: BlendMode.dstOut,
), // This one will handle background + difference out
),
Align(
alignment: Alignment.center,
child: Container(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(
MediaQuery.of(context).size.width / 2,
),
),
),
),
],
),
),
],
),
);
}

Flutter Position Grid Elements

I need to push or rather position some elements inside my Widget, the main idea is to place them at the bottom of the view
The idea is to position the elements of the blue box in the other blue box
class Principal extends StatelessWidget {
#override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
final List<String> _listItem = [
'assets/foto.jpg',
'assets/foto2.jpg',
'assets/foto3.png',
'assets/foto4.jpg',
];
return Stack(
children: <Widget>[
Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
_containerImg(context,screenWidth,screenHeight),
_table(_listItem),
],
),
),
),
],
);
}
Widget _containerImg(BuildContext context,ScreenWidth,ScreenHeight){
return Container(
height: ScreenHeight,
width: ScreenWidth,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/480359.jpg'),
fit: BoxFit.cover,
),
),
);
}
Widget _table(List<String> _listItem){
return GridView.count(crossAxisCount: 4,
padding: EdgeInsets.all(5.0),
crossAxisSpacing: 1.0,
mainAxisSpacing: 1.0,
children: _listItem.map((item) => Card(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
image: DecorationImage(
image: AssetImage(item),
fit: BoxFit.cover,
),
),
),
),
).toList()
);
}
}
I leave samples of the code, I tried to place a SizedBox, and an expanded one in the middle of the Widget, but it didn't work
class Principal extends StatelessWidget {
#override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
final List<String> _listItem = [
'https://images.unsplash.com/photo-1535498730771-e735b998cd64?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80',
'https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
'https://images.unsplash.com/photo-1494548162494-384bba4ab999?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80',
'https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80',
];
return Scaffold(
body: SafeArea(
child: _containerImg(context, screenWidth, screenHeight, _listItem),
),
);
}
Widget _containerImg(
BuildContext context, ScreenWidth, ScreenHeight, List<String> listItem) {
return Container(
height: ScreenHeight,
width: ScreenWidth,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
"https://aegis-be.com.sg/wp-content/themes/aegis_theme/images/banner_2.jpg"),
fit: BoxFit.cover,
),
),
alignment: Alignment.bottomCenter,
child: _table(listItem),
);
}
Widget _table(List<String> _listItem) {
return Wrap(
verticalDirection: VerticalDirection.up,
children: _listItem
.map(
(item) => Card(
child: Container(
height: 80,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50.0),
image: DecorationImage(
image: NetworkImage(item),
fit: BoxFit.cover,
),
),
),
),
)
.toList());
}
}

how to overlay a circular image on the top of a card (half in the card and half outside the card)?

I'm new to flutter and recently I tried to design a page where I have to put an image on the top of a card with half of it on the card and half of it outside the card, I tried Stack but couldn't design what I wanted!
here is an example of what I'm trying to design.
here is the code that isn't giving the desired result like the image below:
class ContainerWithCircle extends StatelessWidget {
final double circleRadius = 100.0;
final double circleBorderWidth = 8.0;
#override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
width: circleRadius,
height: circleRadius,
decoration:
ShapeDecoration(shape: CircleBorder(), color: Colors.white),
child: Padding(
padding: EdgeInsets.all(circleBorderWidth),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg',
))),
),
),
),
Padding(
padding: EdgeInsets.only(top: circleRadius / 2.0),
child: Container(
// Some content
),
),
],
);
}
}
In order to create a layout like the one you specified, you can simply use a Stack and place the card with a padding to the top. Resources for you to look up: Stack, DecoratedBox & CircleBOrder. The following code shows an example implementation:
class ContainerWithCircle extends StatelessWidget {
final double circleRadius = 100.0;
final double circleBorderWidth = 8.0;
#override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: circleRadius / 2.0),
child: Container(
//replace this Container with your Card
color: Colors.white,
height: 200.0,
),
),
Container(
width: circleRadius,
height: circleRadius,
decoration:
ShapeDecoration(shape: CircleBorder(), color: Colors.white),
child: Padding(
padding: EdgeInsets.all(circleBorderWidth),
child: DecoratedBox(
decoration: ShapeDecoration(
shape: CircleBorder(),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://upload.wikimedia.org/wikipedia/commons/a/a0/Bill_Gates_2018.jpg',
))),
),
),
)
],
);
}
}