skip to Main Content

Is there any way we can add custom margin around ‘CupertinoSwitch’ thumb? Below is how I am using ‘CupertinoSwitch’, I don’t find any property for the same available for this widget.

`CupertinoSwitch(
                onChanged: onChanged,
                value: value,
                activeColor:
                    MyColors.primaryColor.platformBrightnessColor(context),
                trackColor:
                    MyColors.greyColor.platformBrightnessColor(context),
              ),`

And below is how it is looking–

enter image description here

Bydefault the (white-circular thumb) margin is 1px, I want to make it custom as per the business needs. Please suggest if there is any workaround available for this, also let me know if more details required on the same. Thanks in advance!

2

Answers


    • this is flutter source code form thumb_painter.dart && geometry.dart.

      you can edit @param delta for you need.

      /// Returns a new [RRect] with edges and radii moved outwards by the given
      /// delta.
      RRect inflate(double delta) {
        return RRect._raw(
          left: left - delta,
          top: top - delta,
          right: right + delta,
          bottom: bottom + delta,
          tlRadiusX: math.max(0, tlRadiusX + delta),
          tlRadiusY: math.max(0, tlRadiusY + delta),
          trRadiusX: math.max(0, trRadiusX + delta),
          trRadiusY: math.max(0, trRadiusY + delta),
          blRadiusX: math.max(0, blRadiusX + delta),
          blRadiusY: math.max(0, blRadiusY + delta),
          brRadiusX: math.max(0, brRadiusX + delta),
          brRadiusY: math.max(0, brRadiusY + delta),
        );
      }
    
    
    Login or Signup to reply.
  1.  '   Container(
          // margin:EdgeInsets.only(left: 10,right: 5,top: 50,bottom: 20),
          //margin: EdgeInsets.all(50),
          //margin: EdgeInsets.symmetric(vertical: 50,horizontal: 50),
          child:CupertinoSwitch(
                onChanged: onChanged,
                value: value,
                activeColor:
                    MyColors.primaryColor.platformBrightnessColor(context),
                trackColor:
                    MyColors.greyColor.platformBrightnessColor(context),))    `
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search