I want to create something like this:
But I don’t know how to create a rounded label(green) that matches the card.
SizedBox(
width: 200,
height: 200,
child: Card(
elevation: 12,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Stack(
children: <Widget>[
Align(
child: Image.asset(
"your_image",
width: 150,
height: 100,
fit: BoxFit.cover,
),
),
Positioned(
top: 0,
child: Container(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 6),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
bottomRight: Radius.circular(8),
) // green shaped
),
child: Text("CHOCOLATE"),
),
)
],
),
),
)
Use Stack widget, and add your card inside it.
Now use below code to add your green view
Positioned(
left: 0.0,
top: 0.0,
child: Container(
color: Colors.green,
height: 150.0,
width: 150.0,
),
)
Now use below pattern for rounded corner of green widget.
Reference from here and here
Related
I want to design like this..
My output
I tried to resize the red box of the send picture like the first picture but I couldn't. How to solve it?
If cannot do like this please give your suggestions.
code
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
shadowColor: Colors.white,
color: HexColor('#FFFBFB').withOpacity(0.5),
child: SizedBox(
height: height * 0.35,
width: width * 0.94,
child: Padding(
padding: const EdgeInsets.only(
top: 0, bottom: 0, right: 0, left: 0),
child: Column(
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2.0),
),
shadowColor: Colors.red,
color: HexColor('##D70040').withOpacity(0.9),
child: SizedBox(
height: height * 0.05,
width: (MediaQuery.of(context).size.width),
)),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(
top: 5, right: 10, left: 10),
child: Column(
children: <Widget>[],
),
),
),
),
],
),
),
),
),
Here is something I managed to achieve:
Using this code:
Column(
children: [
Material(
child: SizedBox(
width: 200,
height: 30,
),
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2).copyWith(
topLeft: Radius.circular(12),
topRight: Radius.circular(12)
)
),
),
Material(
child: SizedBox(
width: 200,
height: 80,
),
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2).copyWith(
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12)
)
),
)
],
),
Hope this helps. Of course you'd need to adjust colors and sizes to the ones you need in your project.
I dont know why you are using nested card but i think container is better solution:
Container(
width: 400,
height: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white.withOpacity(0.6),
),
child: Column(
children: [
Container(
width: double.infinity,
height: 60,
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
)
],
),
),
result be like:
You can play with values to get what you need
I generated dynamic color from images and make it background color.
I want soft edges of background image and color. How do I implement it?
Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
border: Border.all(
width: 0.5,
),
borderRadius: BorderRadius.all(
Radius.circular(24),
),
),
child: Stack(
children: [
Positioned.fill(child: ProductImageWidget()),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ProductNameWidget(),
)
],
),
);
Use ClipRRect
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
"src",
height: 150.0,
width: 100.0,
),
)
wrap your ProductImageWidget() with ClipRReact. Where there is a property called borderRadius.
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: ProductImageWidget(),
)
Or you can use this widget in the inner code of ProductImageWidget() as a parent widget
You will need a ClipRRect and a BackDropFilter to get the effect that you want. By the way this effect is called frosted glass, you can find many info about it. Let me show you an example (I not tested it :) ).
ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
child: Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
border: Border.all(
width: 0.5,
),
borderRadius: BorderRadius.all(
Radius.circular(24),
),
),
child: Stack(
children: [
Positioned.fill(child: ProductImageWidget()),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ProductNameWidget(),
)
],
),
);
),
),
SizedBox(
width: ScreenUtil().setWidth(197),
height: ScreenUtil().setHeight(117),
child: ClipRRect(
borderRadius: BorderRadius.circular(ScreenUtil().radius(30)),
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
Image.asset(
"assets/images/image2.png",
fit: BoxFit.cover,
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
Why doesn't it go over the edges?Flutter inspector see outside but emulator same problem what can I do pls help what should i do.I tried everything
you are almost there but I think you miss the cliprect concept, when you used outside of stack it's clipping widget, you just put it inside stack.
Center(
child: SizedBox(
width: 197,
height: 117,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.asset(
"assets/images/test.jpg",
fit: BoxFit.cover,
),
),
Positioned(
right: -15,
top: -15,
child: Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(15),
),
),
),
Positioned(
bottom: 10,
left: 12,
child: Text("naber lan"),
)
],
),
),
)
output:
I am trying to make a shopping card layout How can I make grey container rounded from top-right and top left.This what I have done so far .What I am i doing wrong Any help will be appreciated
Scrrenshot
Container(
width: ScreenUtil().screenWidth,
height: ScreenUtil().screenHeight,
color: Colors.black12,
child: Stack(
children: [
Container(
width: 500,
height: 400,
decoration: BoxDecoration(
color:Colors.red,
image: DecorationImage(
image: AssetImage("assets/images/x.jpg"),
fit: BoxFit.cover),
),
),
Positioned(
top: 300,
left: 50,
right: 50,
child: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
padding: EdgeInsets.symmetric(horizontal: 130),
width: 400,
child: Column(
children: [],
),
),
),
],
),
),
Seems like you forgot to give a height to the second container. Border radius is working fine when you give the container a height.
I am using a Stack to recreate this effect :
But for some reason, using the Ink widget to be able to get the gradient effect, this is what I have :
This is my code :
Stack(
children: [
SizedBox(
height: 100.0,
width: 100.0,
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: CachedNetworkImage(
imageUrl:
'https://images.unsplash.com/photo-1570296767266-60ccc88974a5',
fit: BoxFit.cover,
placeholder: (context, url) => MC_Shimmer(),
),
),
),
Positioned(
right: -5.0,
bottom: -5.0,
child: SizedBox(
height: 30.0,
width: 30.0,
child: Ink(
decoration: BoxDecoration(
gradient: gradient,
borderRadius:
BorderRadius.all(Radius.circular(5.0)),
),
child: Icon(
OMIcons.cameraAlt,
color: Colors.white,
size: 15.0,
),
),
),
)
],
),
you can use Container instead of Ink and able to use gradient effect.
Positioned(
right: -5.0,
bottom: -5.0,
child: SizedBox(
height: 30.0,
width: 30.0,
child: Container(
decoration: BoxDecoration(
gradient: gradient,
borderRadius:
BorderRadius.all(Radius.circular(5.0)),
),
child: Icon(
OMIcons.cameraAlt,
color: Colors.white,
size: 15.0,
),
),
),
)
I tried this in dart pad it worked alright.
Positioned(
right: -5.0,
bottom: -5.0,
child: SizedBox(
height: 30.0,
width: 30.0,
child: Material(
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.pink, Colors.yellow]),
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: Icon(
Icons.camera,
color: Colors.white,
size: 15.0,
),
),
),
),
)