简体   繁体   English

Flutter:带有列子溢出警告的 AnimatedContainer

[英]Flutter: AnimatedContainer with Column child overflow warning

      Container(
      color: Colors.yellow,
      child: Center(
          child: GestureDetector(
        onTap: () {
          open = !open;
          print(open);
        },
        child: AnimatedContainer(
          color: Colors.white,
          duration: Duration(seconds: 2),
          curve: Curves.easeInCubic,
          width: open ? 200 : 20,
          height: open ? 200 : 15,
          child: Container(
            width: 200,
            height: 200,
            child: Column(
              children: [
                Text('heey'),
                Text('heey'),
                Text('heey'),
              ],
           

在此处输入图像描述

I am trying to have the AnimatedContainer with the Column widget.我正在尝试将 AnimatedContainer 与 Column 小部件一起使用。 How can I make it inside the AnimatedContainer?如何在 AnimatedContainer 中制作它? I want the Text() Widgets are under the Container and it stays that way when the AnimatedContainer expands.我希望Text()小部件位于 Container 下,并且在AnimatedContainer展开时保持这种状态。

Tried to achieve this by OverflowBox() but it seems not working or prob I am doing something wrong here.试图通过OverflowBox()来实现这一点,但它似乎不起作用或者我在这里做错了什么。

I've modified your code, i think you want something like that:我修改了你的代码,我想你想要这样的东西:

Changes: Use expanded in column child widgets更改:在列子小部件中使用扩展

Call open in SetState method.在 SetState 方法中调用 open。

         Container(
              color: Colors.yellow,
              child: Center(
                child: GestureDetector(
                  onTap: () {
                    setState(() {
                      open = !open;
                    });
                    print(open);
                  },
                  child: AnimatedContainer(
                    color: Colors.white,
                    duration: Duration(seconds: 2),
                    curve: Curves.easeInCubic,
                    width: open ? 200 : 20,
                    height: open ? 200 : 15,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Spacer(),
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                      ],
                    ),
                  ),
                ),
              ),
            )

Use Exapanded() Widget your Problem will be solved.使用 Exapanded() 小部件,您的问题将得到解决。

Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                      ],
                    ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM