如何使容器占满整个屏幕宽度?

huangapple go评论54阅读模式
英文:

How can I make a container take all the screen width?

问题

怎样让这个容器(黑色部分)占据整个屏幕宽度

目前我的代码如下:

Container(
              height: 50,
              width: MediaQuery.of(context).size.width,
              color: const Color(0xFF262724),
              child: const Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Icon(Icons.mic_none, color: Colors.white),
                  Icon(
                    Icons.check_box_outlined,
                    color: Colors.white,
                  ),
                ],
              ),
            ),

我尝试将宽度设置为MediaQuery.of(context).size.width,这显然是屏幕的宽度,但不起作用。

英文:

How can I make this container (with the black color) take all the screen's width

如何使容器占满整个屏幕宽度?

Here is my code for the moment:

Container(
              height: 50,
              width: MediaQuery.of(context).size.width,
              color: const Color(0xFF262724),
              child: const Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Icon(Icons.mic_none, color: Colors.white),
                  Icon(
                    Icons.check_box_outlined,
                    color: Colors.white,
                  ),
                ],
              ),
            ),

I tried to set the width to be MediaQuery.of(context).size.width which apparently is the width of the screen, but it's not working.

答案1

得分: 2

你也可以在 with 中使用 double.infinity,但我认为你应该在父部件中使用填充或边距。

英文:

you can also use double.infinity in with but I think You use padding or margin in parent widget

huangapple
  • 本文由 发表于 2023年4月19日 22:59:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76056020.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定