【问题标题】:How to make ListView inside of AnimatedBuilder?如何在 AnimatedBuilder 中制作 ListView?
【发布时间】:2018-12-28 03:10:28
【问题描述】:

我正在练习 Youtube 的动画文本教程,我想在我的布局中实现它。在我的布局中,我有一个背景图片。所以我使用 Stack 以便我的动画文本位于背景图片上方,并且它必须是可滚动的。

没有 ListView 也能完美运行。但是,当我用 ListView 包装 Stack 时......所有小部件都消失了,它是空白的。请帮帮我

这是代码:

Widget build(BuildContext context) {
 final double width = MediaQuery.of(context).size.width;

return AnimatedBuilder(
    animation: animationController,
    builder: (BuildContext context, Widget child) {
      return Scaffold(
          appBar: new AppBar(....),

          //BODY

          body: new ListView {
           children: <Widget>[
            new Stack(
              children: <Widget>[
               new AspectRatio(
                aspectRatio: 100 / 100,
                child: new Container(
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/dashboard.png'),
                          alignment: Alignment.topCenter)),
                ),
              ),
                new Transform(
                  transform: Matrix4.translationValues(
                    animation.value * width,
                    0.0,
                    0.0,
                  ),
                    child: ListView{
                      children:<Widget>[
                        new Container(
                         child: Column(
                          children: <Widget>[
                            Row(
                            children: <Widget>[
                              Text(
                                'Have you subscribe',
                                style: TextStyle(
                                    color: Colors.black,
                                    fontSize: 28.0,
                                    fontFamily: 'Sego'),
                              )
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ));
    });
  }
}

【问题讨论】:

  • 请发布您遇到的错误。
  • 不是错误对不起,它只是空白。每个小部件都消失了(appbar 除外)

标签: listview flutter dart


【解决方案1】:

天哪,这实际上只是一个简单的错误。我的错误是在 ListView 内部制作 ListView,这会引发异常错误。我只需要在 Stack..

中删除 ListView
   Stack(
      //(.....)
     child: ListView{
         children:<Widget>[

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 2015-11-02
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多