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

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

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 increase width of Switch in flutter?

I want to create a Switch like below :
I tried using Transform.scale as parent Widget but it doesn't match with that i want.
How should I increase Switch width? or any other suggestion for create similar(like Toggle or ...)?
As far as I know, you only can increase size of Switch with Tranform.scale, can't increase only width like you want. If you really need that Switch, try use this package flutter_switch like this :
FlutterSwitch(
width: 300,
height: 30.0,
value: true,
onToggle: (val) {},
)
Using SizedBox and FittedBox should do the trick
Same problem discussed here

MaxHeight causes widget to expand

I'm building an expansible card in flutter, which I wanto to animate. I want the parent Container to have a limited height while the card is collapsed, and to have whatever height is necessary for the child when it's expanded. I can reach this result using maxHeight: double.infinity:
Container(
alignment: Alignment.topCenter,
clipBehavior: Clip.hardEdge,
constraints: isExpanded
? BoxConstraints(maxHeight: double.infinity)
: BoxConstraints(maxHeight: 76),
decoration: BoxDecoration(),
child: widget.child,
),
)
But whatever maxHeight value I use other than double.infinity causes the parent to have that exact height, instead of just having the height needed by the child. I can't use double.infinity because that's not animatable. I've tried following this answer's tips, but whatever I wrap the child with, the parent always grows. I've tried changing the child, but even if I use maxHeight on the child itself, the parent always grows to the defined maxHeight.
Why does this happen? Shouldn't maxHeight only cause the parent to expand if needed? How come it works correctly with double.infinity, but doesn't with anything else?
Also, I have tried reaching this result with AnimatedSize, it sort of works. When it is expanding, it works perfectly, but when the child is collapsing, it collapses instantly, and the AnimatedSize's animation follows after.
Edit:
I see what you mean, you want to use AnimatedContainer, but in order to be animated like you want it, it requires you to specify the height. double.infinity won't do in this case, the error message you're getting is correct.
There are ways to get widget height.. I suggest you check this answer: https://stackoverflow.com/a/49650741/7248289
Also, this one might help: https://stackoverflow.com/a/54173729/7248289

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

Set width and height for Cupertino Picker

Cupertino Picker in flutter takes 100% width.
How do we give it custom styling? Height, Width, Borders?
I tried putting it inside a container with width and all, didn't work.Instead there was a weird soft edged background when I gave container a color.
Answering my own question for the time being,
I got a workaround by making the following tree:
Row
Sized box(width:20)
Expanded
Cupertino Picker
Sized Box(width: 20)
I tried multiple workarounds but none worked
A better approach is highly appreciated!
you can try wrapping it up with a container and setting width or height
Container(
height: 250,
child: CupertinoPicker(
itemExtent: 32,
onSelectedItemChanged: (value) {
setState(() {});
},
children:
...
}),