【问题标题】:How to give custom margin around 'CupertinoSwitch' thumb?如何在“CupertinoSwitch”拇指周围提供自定义边距?
【发布时间】:2023-02-16 21:20:11
【问题描述】:

有什么办法可以在“CupertinoSwitch”拇指周围添加自定义边距吗?下面是我如何使用“CupertinoSwitch”,我没有找到任何可用于此小部件的属性。

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

下面是它的样子——

默认情况下,(白色圆形拇指)边距为 1px,我希望它根据业务需求进行自定义。请建议是否有任何可用的解决方法,如果需要更多详细信息,也请告诉我。提前致谢!

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    • 这是 thumb_painter.dart && geometry.dart 形式的 flutter 源代码。

      您可以根据需要编辑@param delta。

      /// 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),
        );
      }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多