18

I creating game with single and two players. for selection i want slide look so i have tried with switch method but its look very small. how to increase height and width of switch? is there any way creating look like this is welcome?

    new Center(
      child:
      new Padding(padding:EdgeInsets.all(50.00),
          child:
        new Column(
        mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            new Switch(value: _value, onChanged: (bool value1)

            {
              _value=value1;

            },
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              activeThumbImage: new AssetImage("assets/Images/1.png"),
              inactiveThumbImage: new AssetImage("assets/Images/1.png"),

            )
          ],
        )           ,
     ),
    )

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Kathir vtv
  • 305
  • 2
  • 7
  • 19
  • I'm also looking for ways to update the active and inactive images to use a canvas/picuture/image instead of having to use a local asset image or a network image, do you know how? – Eradicatore May 06 '19 at 21:18
  • Hey Kathir! I think you should mark the answer by diegoveloper as correct, it's very helpful – OlegBezr Jun 11 '23 at 18:09

6 Answers6

82

You could wrap your Switch inside a Transform widget and change the scale.

        Transform.scale(scale: 2.0,
                 child: Switch(
                          value: true,
                          onChanged: (bool value1){},
                        ),
                 )

Scale = 1 is the default size , 0.5 half size , 2.0 double size, you can play with the values :)

UPDATE

Now you can also do it using SizedBox + FittedBox

SizedBox(
        width: 150,
        height: 40,
        child: FittedBox(
          fit: BoxFit.fill,
          child: Switch(
            value: true,
            onChanged: (bool value1) {},
          ),
        ),
      ),

Don't forget the BoxFit.fill value :)

diegoveloper
  • 93,875
  • 20
  • 236
  • 194
  • 3
    The solution is good. I was using `SwitchListTile` and there this solution does magnify the title too and makes the UI weird. Anyways +1 because it solved the question asked. – CopsOnRoad Sep 30 '18 at 07:35
1

You can wrapper your Switch widget inside a SizedBox and set width and height to it.

SizedBox(
  width: 80,
  height: 40,
  child: Switch(
    value: isChecked,
    onChanged: (value) {
      //Do you things
    }
  )
)
1

The accepted answer using a scale will increase both height and width, if you want to control both height and width

Use it like this

          SizedBox(
            width: 50,
            height: 30,
            child: FittedBox(
              fit: BoxFit.fill,
              child: Switch(
                onChanged: (bool value) {
                },
              ),
            ),
          )
    
1

Try to CupertinoSwitch, You can copy paste run full code below You can use Transform.scale and set scale, 1 means normal size, 0.8 means smaller size

Transform.scale(
  scale: 0.8,
  child: CupertinoSwitch(
    value: _switchValue,
    onChanged: (bool value) {
      setState(() {
        switchValue = value;
      });
    },
  ),
)
P.J.Radadiya
  • 1,493
  • 1
  • 12
  • 21
-2

You should put your switch inside a container and give it both a height and a width as per your requirement.

Stphane
  • 3,368
  • 5
  • 32
  • 47
-4

You can simply use Container that are more compatible everywhere.

flutter

Container(
                height: //whatever you want
                widget: //whatever you want
                child: Switch(
                    value: true, 
                    onChanged: (){

                }),
              )
Nitin0310
  • 19
  • 3