【问题标题】:I want to re-create this UI but I don't know how to shape this buttons (Flutter)我想重新创建这个 UI,但我不知道如何塑造这个按钮 (Flutter)
【发布时间】:2019-12-13 23:57:22
【问题描述】:

我正在尝试使用 Flutter 重新创建 iOS 的秒表 UI,我需要创建这两个按钮,但我不知道如何塑造它们。

我已经尝试过使用标准 CupertinoButton,但没有与圆形按钮相关的选项。

这是类,我想我应该把这两个按钮放在一行中。

class _StopWatchState extends State<StopWatch> {


@override
  Widget build(BuildContext context) {
    return CupertinoTabView(
      builder: (context) {
        return CupertinoPageScaffold(
          navigationBar: CupertinoNavigationBar(
            middle: Text('Stopwatch'),
          ),
          child: Column(
            children: <Widget>[
              Expanded(
                child: Center(
                  child: Text('00:00,000'),
                ),
              ),
              Expanded(
                child: Row(
                  children: <Widget>[
                  ],
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}

【问题讨论】:

  • 你能展示你想要达到的目标吗
  • 是的,我刚刚添加了一个图片链接

标签: android ios user-interface flutter flutter-cupertino


【解决方案1】:

您创建一个用于创建自定义按钮的函数,如下所示:

Widget createButton({Function onTap, Color buttonColor, Color borderColor}) {
  return GestureDetector(
      onTap: onTapAction,
      child: Container(
          height: 200,
          width: 200,
          child: Stack(
            alignment: Alignment.center,
            children: [
              Container(
                height: 100,
                width: 100,
                decoration: BoxDecoration(
                  color: buttonColor,
                  borderRadius: BorderRadius.circular(50.0),
                ),
              ),
              Container(
                child: Center(
                  child: actionTitle,
                ),
                height: 90,
                width: 90,
                decoration: BoxDecoration(
                  color: buttonColor,
                  borderRadius: BorderRadius.circular(45),
                  border: Border.all(width: 2.0, color: Colors.black),
                ),
              ),
            ],
          ),
        ),
    );

在此之后,您将它们添加到您的行小部件中:

Row(
  children: <Widget>[
    createButton(onTap: () {}, buttonColor: Colors.grey, borderColor: Colors.black),
    createButton(onTap: () {}, buttonColor: Colors.green, borderColor: Colors.black),
  ]
)

【讨论】:

  • 非常感谢!我是 Flutter 初学者,这很简单。我不知道为什么我之前没有尝试过:O
  • 如果你想让按钮变成圆形,那么你应该使用正好是按钮一半大小的 BorderRadius。
猜你喜欢
  • 2023-03-02
  • 1970-01-01
  • 2021-09-27
  • 2012-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-04
  • 1970-01-01
相关资源
最近更新 更多