首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SyncFusion颤振仪

SyncFusion颤振仪
EN

Stack Overflow用户
提问于 2021-10-27 10:54:04
回答 2查看 152关注 0票数 0

我目前使用的是SyncFusion颤动径向测量仪。我已经分配了GaugeTitle,它出现在屏幕的顶部。我想知道如何将它向下移动,这样它就可以显示在仪表的正上方。下面是我的代码:

代码语言:javascript
复制
class _MyHomePageState extends State<MyHomePage> {
    @override
    Widget build(BuildContext context) {
    // TODO: implement build
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.green,
          title: Text(
            'Speedometer',
            style: Theme.of(context).textTheme.headline6,
          ),
        ),
        body: Center(
          child: SfRadialGauge(
              title: GaugeTitle(
                  text: 'Speed Level', alignment: GaugeAlignment.center),
              enableLoadingAnimation: true,
              axes: <RadialAxis>[
                RadialAxis(
                  pointers: <GaugePointer>[
                    NeedlePointer(value: 90, enableAnimation: true),
                  ],
                  annotations: <GaugeAnnotation>[
                    GaugeAnnotation(
                        widget: Text(
                          '90.0',
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold),
                        ),
                        positionFactor: 0.5,
                        angle: 90),
                  ],
                ),
              ]),
        ),
      ),
    );
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-28 11:00:12

您可以使用center属性将标题放在仪表的正上方。默认情况下,gauge位于可用尺寸的中心,因为centerX和centerY的默认值为0.5。现在,您可以调整centerY值以减少标题和仪表之间的间距。

链接:https://help.syncfusion.com/flutter/radial-gauge/axes

代码语言:javascript
复制
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {

    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.green,
          title: Text(
            'Speedometer',
            style: Theme.of(context).textTheme.headline6,
          ),
        ),
        body: Center(
          child: SizedBox(
            height: 500,
            width: 300,
            child: SfRadialGauge(
              title: const GaugeTitle(
                  text: 'Speed Level', alignment: GaugeAlignment.center),
              enableLoadingAnimation: true,
              axes: <RadialAxis>[
                RadialAxis(
                  centerY: 0.3,
                  pointers: <GaugePointer>[
                    const NeedlePointer(value: 90, enableAnimation: true),
                  ],
                  annotations: <GaugeAnnotation>[
                    GaugeAnnotation(
                        widget: const Text(
                          '90.0',
                          style: TextStyle(
                              fontSize: 20.0, fontWeight: FontWeight.bold),
                        ),
                        positionFactor: 0.5,
                        angle: 90),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

此外,您可以使用文本小部件添加标题,而不是使用GaugeTitle。根据需要排列文本小部件和指向Stack小部件的SfRadialGauge。

代码语言:javascript
复制
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.green,
          title: Text(
            'Speedometer',
            style: Theme.of(context).textTheme.headline6,
          ),
        ),
        body: Center(
          child: Stack(
            alignment: Alignment.topCenter,
            children: [
              const Text('Speed Level'),
              Padding(
                padding: const EdgeInsets.only(top: 10.0),
                child: SfRadialGauge(
                  enableLoadingAnimation: true,
                  axes: <RadialAxis>[
                    RadialAxis(
                      pointers: <GaugePointer>[
                        NeedlePointer(value: 90, enableAnimation: true),
                      ],
                      annotations: <GaugeAnnotation>[
                        GaugeAnnotation(
                            widget: const Text(
                              '90.0',
                              style: TextStyle(
                                  fontSize: 20.0, fontWeight: FontWeight.bold),
                            ),
                            positionFactor: 0.5,
                            angle: 90),
                      ],
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
票数 1
EN

Stack Overflow用户

发布于 2021-10-27 11:03:25

您可以将文本小部件包装在堆栈中,并将其放置在您想要的任何位置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69737353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档