dart 行对齐小部件到TextBasline不工作

kq0g1dla  于 2023-09-28  发布在  其他
关注(0)|答案(1)|浏览(74)

我的CloseButton Widget不愿意进入行内并在textBaseLine(文本下方的绿色线)上正确对齐
最小代码:

Container(
                color: Colors.red,
                height: 20.h,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'request_card_for'.tr(),
                      style: Theme.of(context).textTheme.headline5?.copyWith(
                          fontSize: 14.sp, fontWeight: FontWeight.w600),
                    ),
                    const CloseButtonWidget()
                  ],
                ),
              ),

screen shot of the issue
我试过了CrossAxisAlign行内构件
使CloseButton小部件居中
... and nevermind fix it lol.

class CloseButtonWidget extends StatelessWidget {
  const CloseButtonWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return IconButton(
**padding: EdgeInsets.zero,** // <--- Fix... iconButton has default padding of .all(8.0), which caused misaligning of IconButton in Row for me
      onPressed: () {
        AutoRouter.of(context).pop();
      },
      icon: Icon(
        Icons.close,
        color: Theme.of(context).primaryColor,
        size: 18,
      ),
    );
  }
}

编辑:无法找到这从一个快速谷歌搜索,所以把它留在这里,也许它会帮助别人面临同样的问题

4jb9z9bj

4jb9z9bj1#

这工作(更清楚地了解)

Container(
            color: Colors.red,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Padding(
                  padding: const EdgeInsets.only(left: 8.0),
                  child: Text(
                    'request_card_for',
                    style: Theme.of(context)
                        .textTheme
                        .headline5
                        ?.copyWith(fontSize: 14, fontWeight: FontWeight.w600),
                  ),
                ),
                IconButton(
                  // **padding: EdgeInsets.zero,** // <--- Fix... iconButton has default padding of .all(8.0), which caused misaligning of IconButton in Row for me
                  onPressed: () {},
                  icon: Icon(
                    Icons.close,
                    color: Theme.of(context).primaryColor,
                    size: 18,
                  ),
                ),
              ],
            ),
          ),

相关问题