首页 > 解决方案 > 使用 mainAxisAlignment.spaceBetween 后减少列小部件中的一些空格

问题描述

我试图分隔我的小部件,它与我的列小部件下的 mainAxisAlignment.spaceBetween 一起使用,但我想让一些小部件彼此更接近。我如何减少一些特定假发之间的空间......下面是我的颤振代码

Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(' '),
                  const Padding(
                    padding: EdgeInsets.only(left: 35.0),
                    child: Text(
                      'Cape Coast',
                      style: TextStyle(
                        fontSize: 40,
                        fontFamily: 'Dongle',
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                  IconButton(
                    onPressed: () {
                      debugPrint('Search pressed');
                    },
                    icon: const FaIcon(FontAwesomeIcons.locationArrow),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: const [
                  Text(
                    'Today, ',
                    style: TextStyle(
                        fontFamily: 'Dongle',
                        fontSize: 35,
                        fontWeight: FontWeight.w100),
                  ),
                  Text(
                    '22:07',
                    style: TextStyle(
                        fontFamily: 'Dongle',
                        fontSize: 35,
                        fontWeight: FontWeight.w100),
                  ),
                ],
              ),

标签: flutter

解决方案


如果要添加自定义空间,那么最好的方法是使用 SizedBox()。您仍然可以使用 spacebetween,但您可以在两者之间添加 sizebox 并添加高度。现在你会说它不会响应,所以你可以使用宽度MediaQuery.of(context).size.height / Number which you want(这个数字会增加和减少高度。

所以是这样的:

          Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  const Text(' '),
                  const Padding(
                    padding: EdgeInsets.only(left: 35.0),
                    child: Text(
                      'Cape Coast',
                      style: TextStyle(
                        fontSize: 40,
                        fontFamily: 'Dongle',
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                  IconButton(
                    onPressed: () {
                      debugPrint('Search pressed');
                    },
                    icon: const FaIcon(FontAwesomeIcons.locationArrow),
                  ),
                ],
              ),
              SizedBox(
              height: 30
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: const [
                  Text(
                    'Today, ',
                    style: TextStyle(
                        fontFamily: 'Dongle',
                        fontSize: 35,
                        fontWeight: FontWeight.w100),
                  ),
                  Text(
                    '22:07',
                    style: TextStyle(
                        fontFamily: 'Dongle',
                        fontSize: 35,
                        fontWeight: FontWeight.w100),
                  ),
                ],
              ),

推荐阅读