Material ui auto width Grid container - material-ui

How can I have a Grid container with auto width? I want to my grid fit it's content
https://codesandbox.io/s/material-demo-forked-78uld
I want to keep red box as minimum as possible

Ciao, you could set width: "fit-content" in container class in this way:
container: {
backgroundColor: "red",
width: "fit-content"
}
Here your codesandbox modified.

Related

Is flutter render infinity size?

I am new in flutter I can't understand that is infinity size render in flutter
If I use container with infinity width then it will render but in box constraints documentation infinity size can't render
This is because there is something constraining the widget, when you set as an example:
Container(
width: double.infinity,
),
it will try to take an infinity size, which usually will throw an error to you, but it's constrained so it takes the max possible width.
The Container widget is built on top of different multiples widgets such as ConstrainedBox, DecoratedBox, Align, LimitedBox... , the ConstrainedBox defaults to the BoxConstraints.expand(), check it's source code:
// ...
child: ConstrainedBox(constraints: const BoxConstraints.expand()),
);
but if you check also the Scaffold source code :
// ....
final BoxConstraints fullWidthConstraints = looseConstraints.tighten(width: size.width);
so trying to expand that Container even within infinity, will expand it at maximum on the fullWidthConstraints which is, in this case, the screen's width.

How to make Flutter Stepper body expand to fill entire screen height

Because Flutter Stepper is scrollable, it can't be set the step content to fill its height.
I want to make a layout like this
While I'm getting this layout
I've used SizedBox with fixed height, but it's incorrect way while screens have different height values.
You can use SizedBox , just specify a non-fixed height and get the current screen height via
MediaQuery. of(context). size. height
this is how it works normally regardless of the screen size
Step(
isActive: currentStep >=0,
title: Text('Account'),
content: SizedBox(
height: MediaQuery. of(context). size. height - 300,
child: Text("sdf"),),
),

How to make a decorated border in Flutter

I wanna make a decorated border as in the image in scrollable widget
Your images dimension is 473 × 670. Corner decoration size 115 x 115. So you can use the centerSlice property to stretch your image according to your needs. Just like this...
Image.asset(
"images/decorated_image.png",
height: 1000, // device or widget height
width: 350, // device or widget height
centerSlice: const Rect.fromLTRB(115, 115, 358, 555),
)
Now you can use stack or any other of your prefered method to put this behind your scrollable list.
You can use Stack:
Stack(
children: [
Image(), // your border image
Container(margin: EdgeInsets.all(12)) // other widgets inside border
]
)

Flutter - How to create fluid / dynamic container that follows it's parent height?

I want to have a line that has 100% parent height, the line should has a fluid height following it's parent's height. the parent's height would be dynamic because every content has it's own height. Just like in Path app.
This is my app, currently I'm setting the height as a constant, how to make it dynamic following it's parent's height? :
Container(
width: 1,
color: Colors. redAccent,
height: 300, // <-- this height
)
try to use the Expanded Widget which uses the available space. you just have to definewhat is the available space here
Expanded(
child: Container(
color: Colors.amber,
width: 100,
),
),
here, if you dont put something on top of the expanded, it will take all the screen
and if not on the bottom, it will reach the bottom of the screen.
it takes the whole free space.
I solved this by adding container and add border left :)

How do you disable the auto-grow on a material ui select input?

I want the material UI to stay the same width it is before an item is selected. (How the Lab Autocomplete works).
For example if you select the 3rd option here, it will grow, how do I disable that?
https://codesandbox.io/s/material-demo-i4ckf
Instead I would like it to act like the autocomplete does, (Choose Lord of the rings)
https://codesandbox.io/s/kcq04
Instead of using minWidth just set the exact width that you need:
formControl: {
margin: theme.spacing(1),
width: 120
}
You've given minWidth property, usually in flex layouts if there's no restriction like maxWidth or flexGrow:0 then it will occupy as much space as available
you can set a fixed width for it like below
also to add text overflow add the necessary css below
formControl: {
margin: theme.spacing(1),
width: 120,
// ellipsis overflow
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}
here's the link https://wsh90.csb.app/
Edit as pointed by Dekel,
Overflow part is may not be necessary