Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter – User Images from database aligned like the example

I am working on a small project trying to learn flutter. I have card events pulled from my database and I would like to visually show current users that are joined. I a similar way like the image bellow.

enter image description here

My biggest question is the frontend part of how to arrange them like that.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I already have the full database.

The structure is every Event has an ID and rest of the info, then it has a group which is all users who are joined and then each of those users [1][2][3] has their user details and userimage: ‘avatar1example.png’is one of them. I know how to pull the image id and connect it with the imageasset (images are preset avatars not user uploads) so my question is mostly the frontend part + the number.

>Solution :

You can use this widget:

_buildImages() {
    int limmit = 3;
    List<Widget> _children = [];
    int index = 0;
    for (var element in _images) {
      if (index < limmit) {
        Widget image = Container(
          decoration: BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(width: 1, color: Colors.white)),
          child: CircleAvatar(
            foregroundImage: AssetImage(element),
            radius: 15,
          ),
        );
        if (index != 0) {
          _children.add(Positioned(
            child: image,
            left: index * 20,
            top: 0,
          ));
        } else {
          _children.add(image);
        }
      } else {
        int number = _images.length - limmit;
        _children.add(Positioned(
          left: index * 20,
          top: 0,
          child: Container(
            decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: Border.all(width: 1, color: Colors.white)),
            child: CircleAvatar(
              child: Center(child: Text('+$number')),
              radius: 15,
            ),
          ),
        ));
        break;
      }
      index++;
    }
    return SizedBox(
      width: double.infinity,
      height: 30 + 2, // image height + 2 white border width
      child: Stack(
        children: _children,
      ),
    );
  }

and use it like this:

_buildImages(),

also remember _images is list of your profile image.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading