首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flutter:带有列子溢出警告的AnimatedContainer

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

Stack Overflow用户
提问于 2021-01-17 09:49:24
回答 2查看 126关注 0票数 0
代码语言:javascript
复制
      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'),
              ],

我正在尝试使用带有Column小部件的AnimatedContainer。我怎样才能在AnimatedContainer中做到这一点?我希望Text()小部件在容器下,并且当AnimatedContainer展开时它会保持这种状态。

试图通过OverflowBox()来实现这一点,但它似乎不工作或可能我在这里做错了什么。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-17 13:39:28

使用Exapanded() Widget,您的问题将会得到解决。

代码语言:javascript
复制
Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                        Expanded(child: Text('heey')),
                      ],
                    ),
票数 1
EN

Stack Overflow用户

发布于 2021-01-17 13:24:38

我已经修改了你的代码,我想你想要这样的东西:

更改:使用在列子小部件中展开

在SetState方法中调用open。

代码语言:javascript
复制
         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')),
                      ],
                    ),
                  ),
                ),
              ),
            )
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65756557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档