23

I would like to display both of my buttons next to each other horizontally. So far I can only display them from top to bottom.

With the following code, what would I have to change ?

new Container(
    child: new Column(

      children: <Widget>[

      new RaisedButton(
        child: new Text("LogIn"),
        color:  Colors.blueAccent[600],
        onPressed: null,
        ),


      new RaisedButton(
        child: new Text("SignUp"),
        color:  Colors.blueAccent[600],
        onPressed: null,
        ),


      ],
    ),
  ),
DESH
  • 530
  • 2
  • 11
  • 29

6 Answers6

32

Column is for items vertically arranged (hence a column), you are looking for Row. Just replace Column with Row, the rest of the code is fine. You can also use an Expanded if you want to fill all the available space.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Rene
  • 1,027
  • 10
  • 18
  • I have 7 buttons in a row. A row can have only 2-3 buttons as per available width of mobile. Kindly suggest me how can I wrap multiple buttons in row automatically? Thank you. – Kamlesh Jun 05 '21 at 08:14
  • @Kamlesh that sounds like a gridview to me: https://flutter.dev/docs/cookbook/lists/grid-lists – Rene Jun 08 '21 at 08:53
14
Wrap(
            children: <Widget>[
              RaisedButton(
                ...
              ),
              RaisedButton(
                ...
              ),
              RaisedButton(
                ...
              ),
            ],
          ),
Jansen Moscol
  • 307
  • 3
  • 5
  • I have 7 buttons in a row. A row can have only 2-3 buttons as per available width of mobile. "Wrap" solved my issue. Thank you. – Kamlesh Jun 05 '21 at 08:15
  • Wrap has alignment attribute but it is not capable to use full of out width then wrap the all the button align center. This is big issue for me. Still searching another solution. Thanks. – Kamlesh Jun 05 '21 at 08:40
4

If you have a column with text in it, and you want two buttons below that text right next to eachother you can use ButtonTheme.bar

Below is some of Flutter's starting code with it. You could plug it in to the starter to see it in action:

Just paste this after the second new text (the one with $counter in it)

        new ButtonTheme.bar(
        child: new ButtonBar(
        alignment: MainAxisAlignment.center,
        children: <Widget>[
                new RaisedButton(
                  onPressed: _incrementCounter,
                  child: new Icon(Icons.add),
                  color: Colors.green,
                ),
                new RaisedButton(
                  onPressed: _decrementCounter,
                  child: new Icon(Icons.remove),
                  color: Colors.red,
                ),
                  ],
        ),
        ),
fatcatdog
  • 41
  • 1
  • I have 7 buttons in a row. A row can have only 2-3 buttons as per available width of mobile. Kindly suggest me how can I wrap multiple buttons in row automatically? Thank you. – Kamlesh Jun 05 '21 at 08:14
3
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              "Rahul Srivastava",
            ),
            Text(
              "Varanasi, India",
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                FlatButton(
                    onPressed: () {
                      var player = AudioCache();
                      player.play('abc.mp3');
                    },
                    child: Text('Play')),
                FlatButton(
                    onPressed: () {
                      var player = AudioCache();
                      player.play('abc.mp3');
                    },
                    child: Text('Pause')),
              ],
            )
          ],
        ),
Rahul Srivastava
  • 513
  • 1
  • 5
  • 9
1

Do something like this

new Column(children: <Widget>[
          new Button(
            ...
            ...
          ),
          new Button(
            ...
            ...
          )
])
Aawaz Gyawali
  • 3,244
  • 5
  • 28
  • 48
-2

Just replace Column with that Row in your code It will work. Although I want to add some extra stuff here suppose that you have Column wrapped inside a row then how will you achieve that displaying of buttons side by side?

Simple just change Column to row n row to column as follows:

          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    child: ...
                  ),
                    child: ..                  
                  ),
                    child: ..
                  )
                ],
              ),

Prianca
  • 1,035
  • 5
  • 16
  • 30