首页 文章

将Flutter Widgets添加到FirebaseAnimatedList上方的布局中

提问于
浏览
0

所以我第一次构建一个Flutter应用程序,所以我仍然有办法完全理解框架,但我仍然坚持这个问题,我无法在其他任何地方找到一个好的答案 .

在我的布局中,我有一个可以无限滚动的FirebaseAnimatedList .

我只需要在FirebaseAnimatedList上面添加一个显示其他数据的小部件 .

Widget body = new ListView(
  children: <Widget>[
    new Text("Hello!"),
    new FirebaseAnimatedList(//..........)
    ],
);

然后我将该body小部件添加为新Scaffold对象的body元素 .

但是我收到以下错误:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ I/flutter (25559): The following assertion was thrown during performResize(): I/flutter (25559): Vertical viewport was given unbounded height. I/flutter (25559): Viewports expand in the scrolling direction to fill their container.In this case, a vertical I/flutter (25559): viewport was given an unlimited amount of vertical space in which to expand. This situation I/flutter (25559): typically happens when a scrollable widget is nested inside another scrollable widget. I/flutter (25559): If this widget is always nested in a scrollable widget there is no need to use a viewport because I/flutter (25559): there will always be enough vertical space for the children. In this case, consider using a Column I/flutter (25559): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size I/flutter (25559): the height of the viewport to the sum of the heights of its children.

我已经尝试过这些选项,但我已经能够解决这个问题,如果有人之前遇到过这个问题或者知道解决方案,那么任何一些帮助都会非常感激 .

1 回答

  • 1

    你想把静态小部件放在列表的顶部吗?

    你能教一些关于代码的东西吗?

    REASON: 原因是您在调用FirebaseAnimatedList时创建了一个列表,而FirebaseAnimatedList正在生成另一个列表 .

    Container getContent() {
      return new Container(
        child: new Column(
          children: <Widget>[
             new Text("HELLO"),
             new Flexible(
              child: new FirebaseAnimatedList(
                query: Your database reference,
                itemBuilder: (_, DataSnapshot snapshot, Animation<double> 
                animation, int index) {
                   return new Column();
                }
              ),
            )
          ]
        )
      );
    }
    

    感谢您的回答,但是,在您的解决方案中,如何使用FirebaseanimatedList滚动新文本(“Hello”)消息而不是附加在顶部 .

    Container getContent() {
          return new Container(
            child: new Column(
              children: <Widget>[
                 new Flexible(
                  child: new FirebaseAnimatedList(
                    query: Your database reference,
                    itemBuilder: (_, DataSnapshot snapshot, Animation<double> 
                    animation, int index) {
                       return new Container(
                          child: new Column(
                            children: <Widget>[
                              new Text("HELLO"),
                            ]
                          )
                       );
                    }
                  ),
                )
              ]
            )
          );
        }
    

相关问题