首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flutter:在AnimatedContainer内部呈现列

Flutter:在AnimatedContainer内部呈现列
EN

Stack Overflow用户
提问于 2021-01-04 04:34:05
回答 1查看 31关注 0票数 0

我试图像这样给人一种扩展的效果。

代码语言:javascript
复制
  isOpened == true
                        ? AnimatedContainer(
                            duration: Duration(seconds: 2),
                            curve: Curves.fastOutSlowIn,
                            child: Container(
                              width: !_mapViewController.cardExpanded()
                                  ? MediaQuery.of(context).size.width * 0.00
                                  : MediaQuery.of(context).size.width * 0.85,
                              height: !_mapViewController.cardExpanded()
                                  ? MediaQuery.of(context).size.height * 0.00
                                  : MediaQuery.of(context).size.height * 0.28,
                              child: Column(
                                children: [
                                  Container(height: 100, width: 100, color: Colors.orange),
                                  ListWidget(),
                                ],
                              ),
                            ),
                          )
                        : Container(),

我的列表小部件是

代码语言:javascript
复制
  @override
  Widget build(BuildContext context) {
    
    return ListView(
      shrinkWrap: true,
      scrollDirection: Axis.horizontal,
      children: [
        RaisedButton(
          onPressed: () {
            print('heey');
          },
          child: Text(
            'heuhaiuh',
          ),
        ),
        Container(
          height: 35,
          width: 35,
        ),
        Container(
          height: 35,
          width: 35,
          color: Colors.green,
        ),
        Container(
          height: 35,
          width: 35,
          color: Colors.yellow,
        ),
        Container(
          height: 35,
          width: 35,
          color: Colors.orange,
        ),
      ],
    );
  }

我收到成堆的错误,说

代码语言:javascript
复制
flutter: Another exception was thrown: RenderConstrainedBox does not meet its constraints.
flutter: Another exception was thrown: RenderDecoratedBox does not meet its constraints.
flutter: Another exception was thrown: Null check operator used on a null value
flutter: Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 1704 pos 12: '!_debugDoingThisLayout': is not true.

它在没有ListWidget()的情况下运行良好。如果我将Column()替换为ListWidget(),那么它也可以工作得很好。在这种情况下,如何将ListView()放入Column()中?

而且,动画效果不是很好。容器只是在没有动画的情况下出现。想知道我怎么也能调整这个吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-04 04:39:32

由于您的ListView滚动方向是水平的,因此必须指定其父对象的高度。将ListView包装在Container中,并为容器指定高度

代码语言:javascript
复制
return Container(
   height: PREFERRED_HEIGHT,
   child: ListView(
     // ...
   ),
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65554643

复制
相关文章

相似问题

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