简体   繁体   中英

How to align widgets inside a row

I would like to align my widgets at the start and at the end of row and I am not able to acheive so? I am confused what to do

doing padding is a static solution and it is giving the overflow error in some devices I want to acheive it for generic all device I dont know how to do.

Kindly help

Padding(padding:EdgeInsets.only(top:60,left:30,right:30),child:
  Row(
    children: <Widget>[                    
       Cancel_btn,
       Retry_btn
     ],
   )
)

minimal amount of code

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: Container(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween, // magic is here
            children: <Widget>[
              RaisedButton(child: Text('Cancel'), onPressed: () {}),
              RaisedButton(child: Text('Retry'), onPressed: () {}),
            ],
          ),
        ),
      ),
    );
  }
}

在此处输入图片说明

There are many ways of doing it.

(I) Using mainAxisAlignment .

Row(
  mainAxisAlignment: MainAxisAlignment.spaceBetween, // add this
  children: [
    Child1(),
    Child2(),
  ]
)

(II) Using Spacer() .

Row(
  children: [
    Child1(),
    Spacer(), // or add this
    Child2(),
  ]
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM