shadow spread is obstruct by SingleChildScrollView boundary in flutter(images attached) - flutter

I'm new to flutter, I'm trying to create a container, inside SingleChildScrollView. when i create shadow of containers, it is a straight line which is due to the boundary of SingleChildScrollView.
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.only(top: 35, left: 5, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(3),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(colors: [
Colors.deepOrange,
Colors.orange,
], transform: GradientRotation(120)),
),
),
),
Padding(
padding: EdgeInsets.only(bottom: 20),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(colors: [
Colors.deepOrange,
Colors.orange,
], transform: GradientRotation(120)),
boxShadow: [
BoxShadow(color: Colors.orange.shade200,offset: Offset(10,5),spreadRadius: 1,blurRadius: 100)
]
),
),
),
Padding(
padding: EdgeInsets.all(3),
child: Container(
height: 170,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: const LinearGradient(
colors: [
Colors.deepOrange,
Colors.orange,
],
transform: GradientRotation(120),
),
),
),
)
],
),
)
i have applied shadow to the second padding. here is the image and i circled the part which doest fit in the UI
image of problem

Add clipBehavior: Clip.none to the SingleChildScrollView. The default is Clip Clip clipBehavior = Clip.hardEdge.
SingleChildScrollView(
clipBehavior: Clip.none,
scrollDirection: Axis.horizontal,
padding: EdgeInsets.only(top: 35, left: 5, bottom: 10),
child: Row(),
);

Related

How can I use a method like z-index method in css in flutter?

Stack(
children: [
Positioned(
left: (MediaQuery.of(context).size.width / 3),
child: Row(
children: [
Container(
margin: const EdgeInsets.only(top: 25),
child: const Text(
'Premium',
),
),
],
),
),
Container(
margin:
const EdgeInsets.symmetric(horizontal: 30, vertical: 50),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
),
)
],
)
As seen in the image, the premium text remains behind the container. I want to show this on the container.
Flutter widget tree work as flow, so the order of your widget is important, so you need to change your stack child to get what you want:
Stack(
children: [
Container(
margin:
const EdgeInsets.symmetric(horizontal: 30, vertical: 50),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
),
)
Positioned(
left: (MediaQuery.of(context).size.width / 3),
child: Row(
children: [
Container(
margin: const EdgeInsets.only(top: 25),
child: const Text(
'Premium',
),
),
],
),
),
],
)

Select multiple choice flutter

What is this and how can I build this in flutter? I don't know how to create it and I can't design these buttons.
This is the design which I want to create
I'm guessing you do not know how to create those buttons, this is a scuffed code but it should give you an idea of how to create it.
Container(
width: 220.0,
height: 65.0,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.white, Color.fromARGB(255, 177, 177, 177)]),
borderRadius: BorderRadius.circular(35),
),
alignment: Alignment.center, // where to position the child
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 2, sigmaY: 2),
child: Container(
width: 200.0,
height: 50.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
color: Color.fromARGB(255, 226, 219, 219)),
child: Row(
children: [
Expanded(
flex: 2,
child: Container(
margin: EdgeInsets.symmetric(
vertical: 7, horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Color.fromARGB(255, 78, 151, 185)),
)),
Expanded(
flex: 5,
child: Container(
padding: EdgeInsets.symmetric(vertical: 7),
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: Text("title")),
Expanded(child: Text("subtitle"))
],
),
),
)
],
),
),
),
),
should result in something like this
adjust colors/dimensions/radius and text accordingly. You can turn it into a button with a gestureDetector Wrap it with a statefulWidget and assign a pressed parameter to it to control how it behaves when clicked and what to change. Please be mindful of the dimensions when creating it, use media sized query to not over flow

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->

How to add text in a section of a container in flutter?

The result I want to have
My current result
I was trying to add a title section for my categories but the result was not what I expected.
I'm looking to add a title section below each illustration in my categories.
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
)
You can use a Column widget to align its contents vertically, in your example you can use it as follow (I have used some online images and colors you can edit it as per your requirement)-
Column(
children: [
SizedBox(height: 50.0),
Container(
height: 100.0,
width: 100.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.orange[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Image.network(
'https://img.icons8.com/cotton/online-shop-2--v2.png',
),
),
SizedBox(height: 10.0),
Text("Title Here")
],
),
It will arrange the contents as follows -
You can read more about Column widget here
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)
You can wrap it with Column widget so you can add a Text widget under your container.
child: Column(
children: [
Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
),
Text("Your text",style: TextStyle(color: Colors.black) ),
],
),
You try put image in decoration instead of child and add text in child container as below.
Container(
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage(*imageUrl*)),
borderRadius: BorderRadius.all(Radius.circular(6.0)),
),
child: Text(*title*))
As I saw from the answers above you are facing an overflow problem when you are implementing these lines of code:
child: Container(
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)
So add these two variables under your Widget build:
Widget build(BuildContext context) {
double width,height;
width = MediaQuery.of(context).size.width;//This means that width== the width of the device running the app in double
height = MediaQuery.of(context).size.height;//Same thing with the height
So now that you have the values of the device width and height you can experiment with their proportions:
child: Container(
height: height*x,//for example if you want it to take place in 1/4 of the screen x=0.25
width: width*x,//same thing here
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50],
borderRadius: BorderRadius.circular(20.0),
),
child: Column(
children: [
SvgPicture.asset(
'assets/images/svg/megacategory/art__grocery.svg',
),
Text('Abarrotes')
)

Flutter - How to achieve Row with same height as parent Container

I have to create a widget with the following design
I have a basic layout created for the same below. The below code is inside a Column.
Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
/*******Outer Container********/
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.grey, width: 0.5),
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(8),
child: Row(
children: <Widget>[
Text("1981-June-01"),
SizedBox(width: 8),
Icon(Icons.calendar_today),
],
),
),
SizedBox(width: 8),
/*******Inner Container********/
Container(
padding: EdgeInsets.all(8),
child: Text("38Yrs"),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.grey, width: 0.5),
),
),
],
),
)
],
),
The result i get is the following
There is still some unwanted padding between the parent container and the bounds of the Row that contains the two containers. I tried using IntrinsicHeight Widget but the UI stayed the same. I wrapped the outer container and the Row inside it with IntrinsicHeight Widget. One at a time and on both at the same time as well. But no change.
What i want to do is to remove that extra padding between the outer container and the inner container, and make the inner container border/height same as the Outer container. Am i missing something?
Any help is appreciated.
This is the output image:
Row(
children: <Widget>[
/*******Outer Container********/
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.grey, width: 0.5),
),
child: Row(
children: <Widget>[
Container(
//padding: EdgeInsets.all(8),
child: Row(
children: <Widget>[
Text(" 1981-June-01"),
SizedBox(width: 8),
Icon(Icons.calendar_today, size: 15),
],
),
),
SizedBox(width: 8),
/*******Inner Container********/
Container(
padding: EdgeInsets.all(8),
child: Text("38Yrs"),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.only(
topRight: Radius.circular(8),
bottomRight: Radius.circular(8)),
// border: Border.fromBorderSide(BorderSide.none),
),
),
],
),
)
],
),
As specified by #pskink in the comments under the question, a more simplified answer would be to replace the Row with the following code(copied from the comment under the question by #pskink)
Material(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: BorderSide(color: Color(0xFFDDDDDD), width: 1)),
clipBehavior: Clip.antiAlias,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(width: 8),
Text("1981-June-01", style: dateTextStyle),
SizedBox(width: 8),
Image.asset(
"assets/images/widgetImages/calendar.png",
width: 15,
height: 15,
),
SizedBox(width: 8),
Container(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
child: Text(
"38Yrs",
style: dateTextStyle,
),
color: Color(0xFFEEEEEE),
),
],
),
),
This code is simpler in terms of number of widgets in the widget tree.