【问题标题】:How to create a UI like below in Flutter如何在 Flutter 中创建如下所示的 UI
【发布时间】:2021-01-21 08:27:22
【问题描述】:

我需要一个像上面这样的 BMI 可视化器,我该如何创建它?是否有任何 WidgetsPlugin 可用于此类 UI。

【问题讨论】:

    标签: flutter user-interface flutter-design


    【解决方案1】:

    我创建了自定义 UI 类来执行此操作

    class BmiVisualizer extends StatelessWidget {
      final double bmiValue;
      final String bodyType;
    
      BmiVisualizer({@required this.bmiValue, this.bodyType});
      @override
      Widget build(BuildContext context) {
        return Container(
          padding: EdgeInsets.symmetric(horizontal: 24),
          height: 100,
          child: Column(
            children: [
              Wrap(
                children: [
                  Text("$bmiValue "),
                  Text(
                    "$bodyType",
                    style: TextStyle(
                      fontWeight: FontWeight.w800,
                      color: bmiValue == null
                          ? Colors.lightGreen[200]
                          : bmiValue <= 18.5
                              ? Colors.lightGreen[200]
                              : bmiValue > 18.5 && bmiValue.round() <= 24
                                  ? Colors.green
                                  : bmiValue.round() > 24 && bmiValue.round() <= 30
                                      ? Colors.orange
                                      : bmiValue > 30 && bmiValue <= 35
                                          ? Colors.red[300]
                                          : bmiValue > 35 && bmiValue <= 40
                                              ? Colors.red
                                              : Colors.red,
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.max,
                children: [
                  for (double i = 15; i <= 45; i++)
                    Container(
                      height:
                          (bmiValue != null && bmiValue < 15 && i.round() == 15) ||
                                  (bmiValue != null &&
                                      bmiValue > 45 &&
                                      i.round() == 45) ||
                                  i.round() == bmiValue?.round()
                              ? 50
                              : 30,
                      width: i.round() == bmiValue?.round() ? 3 : 2,
                      color: i <= 18.5
                          ? Colors.lightGreen[200]
                          : i > 18.5 && i.round() <= 24
                              ? Colors.green
                              : i.round() > 24 && i.round() <= 30
                                  ? Colors.orange
                                  : i > 30 && i <= 35
                                      ? Colors.red[300]
                                      : i > 35 && i <= 40 ? Colors.red : Colors.red,
                    )
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.max,
                children: [
                  for (double i = 15.5; i < 45; i++)
                    Container(
                      child: Text(i == 18.5
                          ? "18.5"
                          : i.round() == 25
                              ? "25"
                              : i.round() == 30
                                  ? "30"
                                  : i.round() == 35
                                      ? "35"
                                      : i.round() == 40 ? "40" : ""),
                    )
                ],
              ),
            ],
          ),
        );
        throw UnimplementedError();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-04
      • 2022-12-11
      • 2020-01-04
      • 1970-01-01
      • 2021-08-07
      • 2013-04-06
      • 1970-01-01
      • 2019-11-07
      相关资源
      最近更新 更多