【问题标题】:Why my Center widget doesn't work in Dart? | Flutter为什么我的 Center 小部件在 Dart 中不起作用? |扑
【发布时间】:2021-09-16 00:30:50
【问题描述】:

我正在尝试将所有小部件(2 个图标和文本)居中,但是当我添加中心小部件(在子之前:我放置子行之前:居中(下面的代码))时,没有任何反应, 0 个错误,它只是不工作。

Container(
        width: 100.0,
        height: 100.0,
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(
            Radius.circular(15),
          ),
        ),
        child: const Icon(
          Icons.outbond_outlined,
          color: Colors.amber,
          size: 50.0,
        ),
      ),
      Container(
        width: 220.0,
        height: 100.0,
        decoration: const BoxDecoration(
          color: Colors.black,
          borderRadius: BorderRadius.all(
            Radius.circular(15),
          ),
        ),
        child: Row(
          // ignore: prefer_const_literals_to_create_immutables
          children: [
            const Icon(
              Icons.call_end_sharp,
              color: Colors.amber,
              size: 30.0,
            ),
            const Text(
              "Skrt",
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 30.0,
                  fontFamily: "Lato"),
            ),
            const Icon(
              Icons.call_end_sharp,
              color: Colors.amber,
              size: 30.0,
            ),
          ],
        ),
      ),

【问题讨论】:

  • 嗨马拉克,看起来有两个小部件容器。这些是列还是行?你在哪里使用中心小部件?
  • 里面有包装
  • 我在第二个Container之前使用它,宽度为220.0

标签: flutter dart widget row center


【解决方案1】:

在你的行中使用 mainAxisAlignment: MainAxisAlignment.center

示例:

Row(
      // ignore: prefer_const_literals_to_create_immutables
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Icon(
          Icons.call_end_sharp,
          color: Colors.amber,
          size: 30.0,
        ),
        const Text(
          "Skrt",
          style: TextStyle(
              color: Colors.black,
              fontSize: 30.0,
              fontFamily: "Lato"),
        ),
        const Icon(
          Icons.call_end_sharp,
          color: Colors.amber,
          size: 30.0,
        ),
      ],
    ),

【讨论】:

  • 欢迎兄弟! :)
猜你喜欢
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 2021-08-27
  • 2020-07-08
  • 2013-03-06
  • 1970-01-01
相关资源
最近更新 更多