首页 > 解决方案 > 在 Web 服务器上运行时,sweepGradient 不起作用

问题描述

使用以下 cmd 行运行时

flutter run -d web-server --web-hostname=0.0.0.0

我的仪表看起来(截图1)与 sweepGradient 的预期一样明显

但是当使用下面的 cmd 行运行时:

flutter run --web-renderer html -v -d web-server --web-hostname=0.0.0.0

渐变完全消失了在此处输入图像描述

下面是我的代码:

  Widget build(BuildContext context) {
    return SfRadialGauge(
      axes: <RadialAxis>[
        RadialAxis(
            showLabels: false,
            showTicks: false,
            minimum: 0,
            maximum: 100,
            radiusFactor: 0.8,
            axisLineStyle: const AxisLineStyle(
                cornerStyle: CornerStyle.bothCurve,
                thicknessUnit: GaugeSizeUnit.factor, 
                thickness: 0.1
            ),
            annotations: <GaugeAnnotation>[
              GaugeAnnotation(
                  angle: 180,
                  widget: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Container(
                        child: Text(
                          '50%',
                          style: TextStyle(
                              fontSize: 25,
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                    ],
                  )),
            ],
            pointers: const <GaugePointer>[
              RangePointer(
                  value: 50,
                  cornerStyle: CornerStyle.bothCurve,
                  enableAnimation: true,
                  animationDuration: 4500,
                  animationType: AnimationType.ease,
                  sizeUnit: GaugeSizeUnit.factor,
                  gradient: SweepGradient(
                      colors: <Color>[Color(0xFFFCE38A), Color(0xFFF38181)],
                      stops: <double>[0.25, 0.75]),
                  color: Color(0xFF00A8B5),
                  width: 0.15),
            ]),
      ],
    );
  }

当两者都在 Web 服务器上运行时,为什么我会得到两个不同的结果?

标签: flutterdart

解决方案


尝试使用您的其他 Web 渲染器command

renderer canvaskit

代替

renderer html


推荐阅读