【问题标题】:How to add button in Flutter如何在 Flutter 中添加按钮
【发布时间】:2021-12-27 19:33:49
【问题描述】:

我是 Flutter 的新手。 我正在关注一些 YouTube 视频来学习颤振。在卡片(主屏幕)中添加图片后,现在我想在该图片下方添加两个按钮。我该怎么做。

图片添加代码

body: Center(
        child: Card(
          child: Column(
            children: [Image.asset("assets/image-name")],
          ),
        ),
      ),

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    Here you have a great page,您可以在其中找到 Flutter 中基本材质小部件的实现。

    对于您的示例,它看起来像这样:

    body: Center(
            child: Card(
              child: Column(
                children: [
                  Image.asset("assets/image-name"),
                  ElevatedButton(
                    onPressed: () {
                      // Respond to button press
                    },
                  child: Text('CONTAINED BUTTON'),
                  )
                ],
              ),
            ),
          ),
    

    对于第二个按钮,您可以在 children 数组中添加另一个按钮。 您还可以将两个按钮包装在 Row 小部件中,这样您就可以将它们水平放置,彼此相邻。

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 2021-11-08
    • 2020-04-07
    • 2019-02-14
    • 2023-02-24
    • 1970-01-01
    • 2023-01-29
    • 2020-06-08
    • 1970-01-01
    • 2018-11-23
    相关资源
    最近更新 更多