Reputation: 345
So I have this code I tried using center() widget but I can't get the element in the center here's how they look.
the funny thing is the green container consumes all the screen width but the widgets inside the container are not aligned to center horizontally.
here's the code
Center(
child: Container(
color : Colors.green,
alignment: Alignment(0.0, 0.0),
child: Row(
children: <Widget>[
InkWell(
child: Text(
" Likes \n" + document['likes'].toString()),
onTap: () => LikeQuote(document),
),
InkWell(
child: Text(" Dislikes \n" +
document['dislikes'].toString()),
onTap: () => DislikeQuote(document),
),
InkWell(
child: Text(" Shares \n" +
document['shares'].toString()),
onTap: () => ShareQuote(),
),
],
),
),
),
I want the like dislike and share to be in the center . How do i do that?
Upvotes: 0
Views: 655
Reputation: 630
To align the widget within a Row or Columns, we can use these parameters inside Row or Columns.
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
Row:
Column:
Upvotes: 1
Reputation: 83
You should use mainAxisAlignment
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[ comp1(), comp2()
Upvotes: 2
Reputation: 19514
Container(
color : Colors.green,
alignment: Alignment(0.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Text(
" Likes \n" + document['likes'].toString()),
onTap: () => LikeQuote(document),
),
InkWell(
child: Text(" Dislikes \n" +
document['dislikes'].toString()),
onTap: () => DislikeQuote(document),
),
InkWell(
child: Text(" Shares \n" +
document['shares'].toString()),
onTap: () => ShareQuote(),
),
],
)
,
),
Upvotes: 0