Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter mainaxisAlignment.spaceEvenly not working on multiple flex(Row & Column)

Tags:

flutter

I am creating a screen like Instagram profile but mainaxisAlignment.spaceEvenly is not working. It works just fine if the row is not inside any other row or column but in this case It didn't. How can I solve this? Please Help.

Container(
                margin: EdgeInsets.all(15.0),
                child: Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Container(
                          width: 100.0,
                          height: 100.0,
                          margin: EdgeInsets.only(
                            right: 10.0,
                          ),
                          decoration: new BoxDecoration(
                            shape: BoxShape.circle,
                            image: new DecorationImage(
                              fit: BoxFit.fill,
                              image: new CachedNetworkImageProvider(
                                profile.dp,
                                scale: 100.0,
                              ),
                            ),
                          ),
                        ),
                        Column(
                          children: <Widget>[
                            Row(
                              mainAxisAlignment:
                                  MainAxisAlignment.spaceEvenly,
                              children: <Widget>[
                                Column(
                                  children: <Widget>[
                                    Text(
                                      profile.postcount.toString(),
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Text('posts'),
                                  ],
                                ),
                                Column(
                                  children: <Widget>[
                                    Text(
                                      profile.followers.toString(),
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Text('followers'),
                                  ],
                                ),
                                Column(
                                  children: <Widget>[
                                    Text(
                                      profile.followings.toString(),
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Text('following'),
                                  ],
                                ),
                              ],
                            ),
                            new RaisedButton(
                              child: Text('Edit Profile'),
                              onPressed: () {},
                            ),
                          ],
                        )
                      ],
                    )
                  ],
                )),

Expectation:

Reality:

like image 294
Ashutosh Sharma Avatar asked Oct 10 '18 10:10

Ashutosh Sharma


1 Answers

Here you go

enter image description here

Widget _buildRow() {
  return Container(
    padding: const EdgeInsets.all(16),
    child: Row(
      children: <Widget>[
        CircleAvatar(
          radius: 40,
          backgroundImage: AssetImage("your_image_asset"),
        ),
        SizedBox(width: 12),
        Expanded(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      Text("2", style: TextStyle(fontWeight: FontWeight.bold)),
                      Text("Gold", style: TextStyle(color: Colors.grey)),
                    ],
                  ),
                  Column(
                    children: <Widget>[
                      Text("22", style: TextStyle(fontWeight: FontWeight.bold)),
                      Text("Silver", style: TextStyle(color: Colors.grey)),
                    ],
                  ),
                  Column(
                    children: <Widget>[
                      Text("5464", style: TextStyle(fontWeight: FontWeight.bold)),
                      Text("Reputation", style: TextStyle(color: Colors.grey)),
                    ],
                  ),
                ],
              ),
              OutlineButton(onPressed: () {}, child: Text("CopsOnRoad (Edit Profile)")),
            ],
          ),
        ),
      ],
    ),
  );
}
like image 80
CopsOnRoad Avatar answered Sep 28 '22 02:09

CopsOnRoad