Different First Item, in Firebaseanimiatedlist

2019-08-19 23:46发布

问题:

I have below code to include all the list of items but i need to display a card item on top, which should be scrollable along with Firebaseanimatedlist, but the card should be visible only for the First Item.

How can i achieve this. With the below code, Card() sticks at the top and does not scroll in the scaffold.

return getContent() {
  return new Container(
    child: new Column(
      children: <Widget>[
         new Card(
                child: new Text("STATIC ITEM TO DISPLAY ON TOP AS A HEADER FOR BELOW FIREBAE LIST"),
                 ),
         new Flexible(
          child: new FirebaseAnimatedList(
            query: Your database reference,
            itemBuilder: (_, DataSnapshot snapshot, Animation<double> 
            animation, int index) {
               return new Column();
            }
          ),
        )
      ]
    )
  );
}

回答1:

The int index returns every element of the list, 0, 1, 2, 3, 4 ... depending on the elements you can tell it to return a different design for each one.

I do not know if it's the best way to do it, but I think it could be worth it.

return 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) {
               if(index==0){
                  return new Column(
                    children: <Widget>[
                      new Card(
                       child: new Text("STATIC ITEM TO DISPLAY ON TOP AS A 
                       HEADER FOR BELOW FIREBAE LIST"),
                      ),
                    ]
                  );
               } else {
                 return new Column();
               }
            }
          ),
        )
      ]
    )
  );
}


标签: dart flutter