icon above center showModalBottom Flutter - flutter

How do I make the icon in showModalBottom above the middle, like the picture above, I made it using a container and set the position to positioned but it was cut off when I set the top to negative, like the following picture

Instead of using Positioned you can actually use Transform.translate to shift the Container. Consider that you use half the height of the container as y-Offset and multiply it with -1.
Example:
Transform.translate(
offset: const Offset(0,-50), // <- use half the height of the container
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.white,
border: Border.all(
color: const Color.fromRGBO(251, 202, 191, 1),
width: 4
)
),
width: 100,
height: 100, // Container has height 100
),
)

Related

Create a Container witch shape is like image(see attached image)

see below image
I want create a container(or other widget) with custom shape that like same as image.
I don't want create content in that, just shape of that.
This isn't BorderRadius, because those sides is curved.(I want create this sides like that image).
I prefer that implemented without CustomPaint.
Thank you
It totally border radius bro just try The width & height
Align(
child: Container(
height: 50,
width: 100,
margin: EdgeInsets.only(top: 40, left: 40, right: 40),
decoration: new BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.black, width: 0.0),
borderRadius: new BorderRadius.all(Radius.elliptical(100, 50)),
),
child: Text(' '),
),
),

Stack and Container having different elevations in Flutter UI

In the bottom section, there is a border displayed between two container widgets,
For the above Container, I have used a Stack having two containers as children, one having black bg and the other having white, Below the stack I have displayed another container having black bg and a rounded corner on another end, The code is given below, I want to blend that two container so that they appear to be one single container.
Expanded(
child: Stack(children: [
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(37, 37, 37, 1),
),
),
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(255, 255, 255, 1),
borderRadius: BorderRadiusDirectional.only(
bottomStart: Radius.circular(100)),
)),
]),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Color.fromRGBO(37, 37, 37, 1),
borderRadius:
BorderRadiusDirectional.only(topEnd: Radius.circular(100)),
),
),
),
I think that the grey row isn't elevation. It's because of the border of the white container. Please remove the color or put it transparent and test again.

Flutter: Smooth rounded corners

I would like to know how to make a smooth rounded corner in Flutter. I found a similar link to iOS approach - smooth rounded corners in swift but it did not help me find a solution to Flutter approach. I thought ContinuousRectangleBorder is the way, but it is not the shape I am looking for. I think some kind of clipper should work.
I published a dedicated package that might help you : figma_squircle.
Container(
height: 100,
width: 100,
decoration: ShapeDecoration(
color: Colors.red.withOpacity(0.75),
shape: SmoothRectangleBorder(
borderRadius: SmoothBorderRadius(
cornerRadius: 10,
cornerSmoothing: 0.5,
),
),
),
)
You can try the following code
ClipRRect(
borderRadius:
BorderRadius.circular(15.0),
child: // Your widget that needs to be rounded.
)
For more information, you can check this reference video
There is no natural way to do this with Flutter. If you really want to accomplish this, use the technique used in your article where you overlay the square with a circle with a Stack widget. This looks like the following:
Stack(children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.amber,
)),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.all(Radius.circular(16)),
),
),
]),
This will create a square that looks like:
You might need to mess around with the height and width of the square and the circle but you get the idea.

How to remove elevation shadow from one side without removing elevation itself in flutter from Card or Material widget?

How can I remove top-side elevation shadow inside Card or Material widget.
I used Material widget to container and given a value for elevation. it reflects to my container in all side. But i want only left, bottom and right side elevation shadow. how can i get it or remove top side elevation shadow.
Example from Material or Card Widget will be useful.
Material(
elevation: 3,
child: Container(
height: 100,
width: 300,
),
)
For that, you just have to bring the shadow a little bit down by increasing the y-axis of the offset property just like this:
Container(
height: 100.0,
width: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
boxShadow: [
BoxShadow(
spreadRadius: 2,
blurRadius: 3,
offset: Offset(0, 6),
color: Colors.black38
)
]
),
),
Here's the output:

Set Container height equal to width in Flutter

I am learning Flutter development. I want to display some rounded square shaped containers with short text in a row. However, the possible shapes are either a circle or rectangle. So I decided to set the width and height of the rectangle so that they would be equal.
The following is the code I used to create the Container
Container(
width: double.maxFinite,
height:
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: ThemeProvider.themeOf(context).data.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Text(keyText),
),
When I set the shape in Box decoration alone, the Container resized to the size of the text. When I set the width property of the Container, I was able to divide the available width of the screen among the containers, which ensures flexibility of size if the screen was smaller or bigger, instead of hard coding it. Now I want to make the height the exact same size that the width turns out to be, thus obtaining a square container. Any idea how I could do that?
EDIT: I tried the following code and this is how the containers are looking like in both cases:
Container(
alignment: Alignment.center,
width: double.maxFinite,
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: ThemeProvider.themeOf(context).data.primaryColor,
borderRadius: BorderRadius.circular(10),
),
Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: ThemeProvider.themeOf(context).data.primaryColor,
borderRadius: BorderRadius.circular(10),
),
After using MediaQuery.of(context).size.width for height property or both
Here is a solution without using MediaQuery:
AspectRatio(
aspectRatio: 1,
child: Container(
width: double.infinity,
child: Text(),
),
)
Use MediaQuery. MediaQuery.of(context).size.width gives you the Screen width size value.
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: ThemeProvider.themeOf(context).data.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Text(keyText),
)
check this quick example that I made just for you!
// This function is just an example
List<Widget> buildContainers(BuildContext context, int containerCount) {
// Here you get the width of all your containers
final containerWidth = MediaQuery.of(context).size.width / containerCount;
// Make height = width for squares!
final containerHeight = containerWidth;
// We will gather all containers in this list
List containerList = <Container>[];
for (var i = 0; i < containerCount; i++) {
containerList.add(
Container(
// Use the predefined width and height here!
width: containerWidth,
height: containerHeight,
// Random color to differentiate each container
// You could replace this with your child widget
color: Color(
Random().nextInt(0xFFFFFFFF),
),
),
);
}
return containerList;
}
#override
Widget build(BuildContext context) {
return Container(
child: Row(
children: [
// If you are wondering what are these dots (...)
// they are called "spread operators" and you can find more about them here:
// https://dart.dev/guides/language/language-tour#spread-operator
...buildContainers(context, 7),
],
),
);
}
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: ThemeProvider.themeOf(context).data.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Text(keyText),
),