我希望将所有行项均匀地放置在一行中,就像align-Item : center在html中所做的那样.

我的项目是下面的图像,但图像没有与按钮对齐. 纽扣比图片高一点.

enter image description here

我的密码是:

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  const Home({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Row(
            children: [
              Spacer(),
              ElevatedButton(
                onPressed: (() {}),
                child: Text("Report"),
                style: ElevatedButton.styleFrom(
                    backgroundColor: Color(0xffffb200),
                    foregroundColor: Color(0xff00324B)),
              ),
              Spacer(),
              ElevatedButton(
                onPressed: (() {}),
                child: Text("Donate"),
                style: ElevatedButton.styleFrom(
                    backgroundColor: Color(0xffffb200),
                    foregroundColor: Color(0xff00324B)),
              ),
              Spacer(),
              ElevatedButton(
                onPressed: (() {}),
                child: Text("Adopt"),
                style: ElevatedButton.styleFrom(
                    backgroundColor: Color(0xffffb200),
                    foregroundColor: Color(0xff00324B)),
              ),
              Spacer(),
              Container(
                margin: EdgeInsets.fromLTRB(0, 30, 0, 10),
                height: 60.0,
                width: 60.0,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(95),
                  image: DecorationImage(
                    image: AssetImage("assets/images/download.jpg"),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              SizedBox(
                width: 14,
              )
            ],
          ),
        ],
      ),
    );
  }
}

我甚至试了mainAxisAlignment: MainAxisAlignment.center

以及crossAxisAlignment: CrossAxisAlignment.center美元,但都不起作用.

推荐答案

基本上,您可以通过放入以下代码来解决问题

Row(crossAxisAlignment: CrossAxisAlignment.center)

但问题出在您的代码上. 如果你go 掉照片的页边距,问题就解决了

margin: EdgeInsets.fromLTRB(0, 30, 0, 10),

Flutter相关问答推荐

类型flatter doctor get zsh:未找到命令:macO中flatter

Flutter在创建时为提供者调用初始化函数

如何使用Firebase Firestore来获取外部集合中的文档子集合中的文档

如何从外部控制有状态窗口小部件本身?

CMakeLists.txt处的CMake错误:3(项目)找不到指定的Visual Studio实例

关闭模式,但再次打开时微件条件相同

在Flutter 中每次点击按钮时都很难调用自定义函数

dart /长笛中的返回早期模式和拆分方法

即使小部件比Flutter 中的屏幕更宽,也始终显示滚动条

在 Dart 中按土耳其语字母顺序对字符串进行排序

如何将取消图标放置在右上角

Flutter RIverpod 奇怪地改变状态

Cloud firestore:如何使用 map 对象创建和更新嵌套数组

Flutter/Dart - 从外部类更新状态

flutter 创建一个带有 2 个图标的按钮

Listview 如何转到下一行/新行?

在 CircleAvatar 中放置芯片

Flutter 中父容器顶部的 Gridview 间距额外区域

设计响应式卡片的最佳方法,以避免像素溢出错误或 _AssertionError

如何在Flutter 中专注于列表视图中最新添加的项目