Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

How to randomly position widgets in a layout in flutter

Lets say I want to randomly position the widgets in a specific layout, like in the image attached below, how could I achieve it ? The Image

I was thinking of using a wrap widget , but that did not quit work, because it is not randomizing the children in a line. My code until now

return Wrap(
   spacing: 30,
   children: [
        buildprofile(),
        buildprofile(),
        buildprofile(),
        buildprofile(),
      ],
    );

buildprofile() {
  return Column(
    children: [
      CircleAvatar(
        radius: 64,
        backgroundColor: Colors.pink,
        child: (CircleAvatar(
          radius: 62,
          backgroundImage: NetworkImage(profilepic),
        )),
      ),
      SizedBox(
        height: 10,
      ),
      Text(
        "Sivaram",
        style: mystyle(16, Colors.black, FontWeight.w700),
      )
    ],
  );
}





与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could use flutter_staggered_grid_view

  StaggeredGridView.count(
    crossAxisCount: 4,
    children: List.generate(
        3,
        (index) => Center(
              child: CircleAvatar(
                radius: 64,
                backgroundColor: Colors.pink,
              ),
            )),
    staggeredTiles: [
      StaggeredTile.count(2, 2), // takes up 2 rows and 2 columns space
      StaggeredTile.count(2, 1), // takes up 2 rows and 1 column
      StaggeredTile.count(1, 2), // takes up 1 row and 2 column space
    ], // scatter them randomly
  );

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...