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

Related

What widget should I use for full width?

I am using Wrap widget and I got following result.
But I want full width like the following image
What widget should I use? Please guide me a for a piece of code snippet
For this layout you can either use staggeredGridView or if you wish to keep the wrap you have to define the width of each widget. You can probably use
SizedBox(
width: MediaQuery.of(context).size.width * 0.31, //0.33 will give 1/3 of the width.
child: Container(), // your widget here
),
I used assorted_layout_widgets package. That is exactly what I want.
WrapSuper(
wrapType: WrapType.balanced,
wrapFit: WrapFit.larger,
spacing: 8.0,
lineSpacing: 8.0,
children:[]),

How to use a variable with AnimatedContainer but still revert back to default properties

I am trying to add a collapsable note that expands to the full height determined by the amount of text inside of it with the click of a button.
The problem I am facing is when adding variable to determine the height of the AnimatedContainer
I want the AnimatedContainer to take a certain height if isCollapsed is true and a default height (that is, as much height as needed for the children (same as not specifying height)). I am trying to use condition ? do something : do something else but because it requires the :, I cannot just tell it to revert back to default.
This is simplified for the purpose of demonstration:
return AnimatedContainer(
duration: Duration(milliseconds: 300),
height: isCollapsed ? 100 : (revert to default),
child: Column(
TextField(),
TextField(),
),
)
Have you tried setting it to null?
height: isCollapsed ? 100 : null,

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

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:
...
}),