Search code examples
flutter

flutter - create stack from a list


I'm tring to acheive this:

enter image description here

I am tring to do this using a stack (so that part of one image is above another. see picture). nothing appear on screen and not errors. What i'm doing wrong?


Solution

  • You don't need ListView to achieve it.
    Instead you put all child widgets into Stack and wrap them into Positioned widget, which will allow you to control their position.

    Example code:

    Widget build(BuildContext context) {
      final avatars = <Widget>[];
      final avatarWidth = 40;
      final overlayWidth = 10;
      for(int i = 0; i < attendingImagesList.length; i++) {
        avatars.add(
          Positioned(
            left: (avatarWidth - overlayWidth)*i,
            child: // put image widget here,   
          )
        );
      }
    
      return Stack(children: avatars);
    }