无法使用column()颤动将我的小部件置于容器中

发布于 2025-01-31 15:02:30 字数 1825 浏览 5 评论 0原文

在这张照片上是我的 step1

,当我使用column()时,我的设计不是中心:(观看它- &gt

;请参阅任何错误:

 Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      color: colorMars,
                    ),
                    height: 200,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        IconButton(
                            icon: const FaIcon(
                              FontAwesomeIcons.mars,
                              size: 80,
                            ),
                            onPressed: () {
                              colorMars = active;
                              if (colorMars == active) {
                                colorVenus = inActive;
                              } else {
                                colorMars = inActive;
                              }

                              setState(() {});
                            }),
                      ],
                    ),
                  ),
                ),
              ),

图标的ps我使用此软件包 font_awsome_flutter 在pubspec.yaml中:

dependencies:
  flutter:
    sdk: flutter
  font_awesome_flutter: ^10.1.0

这里有完整的代码 - > full_code

On this pic is my
step1

And when I use Column(), my design isn't a center :( Watch it -> step2

also I cant press on it when I wrapped in Column() and I dont see any mistakes:

 Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      color: colorMars,
                    ),
                    height: 200,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        IconButton(
                            icon: const FaIcon(
                              FontAwesomeIcons.mars,
                              size: 80,
                            ),
                            onPressed: () {
                              colorMars = active;
                              if (colorMars == active) {
                                colorVenus = inActive;
                              } else {
                                colorMars = inActive;
                              }

                              setState(() {});
                            }),
                      ],
                    ),
                  ),
                ),
              ),

PS For icons I use this package font_awesome_flutter
In pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  font_awesome_flutter: ^10.1.0

Full of code here -> full_code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2025-02-07 15:02:30

添加IconSize:80在您的iconbutton中。完整的代码将

 Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      color: colorMars,
                    ),
                    height: 200,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        IconButton(
                            iconSize: 80,
                            icon: const FaIcon(
                              FontAwesomeIcons.mars,
                            ),
                            onPressed: () {
                              colorMars = active;
                              if (colorMars == active) {
                                colorVenus = inActive;
                              } else {
                                colorMars = inActive;
                              }

                              setState(() {});
                            }),
                      ],
                    ),
                  ),
                ),
              ),

基于iconbutton

用图标创建图标按钮时,请勿覆盖图标的
尺寸与其图标。大小参数,使用图标按钮的Iconsize
代替参数。例如,这样做:

iconbutton(Iconsize:72,ICON:ICON(ICON.FARAITE),...)

避免这样做:

iconbutton(图标:ICON(ICON.FARAITE,size:72),...)

如果这样做,按钮的大小将基于默认图标大小,
不是72,可能会产生意外的布局和剪辑问题。

如果您覆盖faicon带有80的尺寸,而无需添加iconbutton大小,则faicon将大于其父(iconbutton) )您会得到意外的布局。

Add iconSize: 80 in your IconButton. And full code will be

 Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      color: colorMars,
                    ),
                    height: 200,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        IconButton(
                            iconSize: 80,
                            icon: const FaIcon(
                              FontAwesomeIcons.mars,
                            ),
                            onPressed: () {
                              colorMars = active;
                              if (colorMars == active) {
                                colorVenus = inActive;
                              } else {
                                colorMars = inActive;
                              }

                              setState(() {});
                            }),
                      ],
                    ),
                  ),
                ),
              ),

Based on the IconButton documentation

When creating an icon button with an Icon, do not override the icon's
size with its Icon.size parameter, use the icon button's iconSize
parameter instead. For example do this:

IconButton(iconSize: 72, icon: Icon(Icons.favorite), ...)

Avoid doing this:

IconButton(icon: Icon(Icons.favorite, size: 72), ...)

If you do, the button's size will be based on the default icon size,
not 72, which may produce unexpected layouts and clipping issues.

If you override FaIcon with size 80 without adding IconButton size, the FaIcon will be bigger than its parent (IconButton) and you get unexpected layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文