Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set margin for a Button in Flutter

I am just creating a form in Flutter. I am not able to set the top margin for the button.

class _MyHomePageState extends State<MyHomePage> {  String firstname;  String lastname; final scaffoldKey = new GlobalKey<ScaffoldState>(); final formKey = new GlobalKey<FormState>();       @override   Widget build(BuildContext context) {     return new Scaffold(       key: scaffoldKey,       appBar: new AppBar(         title: new Text('Validating forms'),       ),       body: new Padding(         padding: const EdgeInsets.all(16.0),         child: new Form(           key: formKey,           child: new Column(             children: [               new TextFormField(                 decoration: new InputDecoration(labelText: 'First Name'),                 validator: (val) =>                     val.length == 0 ?"Enter FirstName" : null,                 onSaved: (val) => firstname = val,               ),               new TextFormField(                 decoration: new InputDecoration(labelText: 'Password'),                 validator: (val) =>                     val.length ==0 ? 'Enter LastName' : null,                 onSaved: (val) => lastname = val,                 obscureText: true,               ),               new RaisedButton(                 onPressed: _submit,                 child: new Text('Login'),               ),             ],           ),         ),       ),     );   } 
like image 930
Raja Jawahar Avatar asked May 05 '18 06:05

Raja Jawahar


People also ask

How do I give a padding button in Flutter?

In Flutter, you can provide padding property to Button widget. To provide padding to Button, assign the padding property with EdgeInsets object. The following code snippet applies padding of 30 to all the four sides of the button. padding: EdgeInsets.

How do you change the button size in Flutter?

You need to use an Expanded Widget. But, if your button is on a column, the Expanded Widget fills the rest of the column. So, you need to enclose the Expanded Widget within a row.


Video Answer


1 Answers

Put your button inside a Container and then set the margin

new Container(     margin: const EdgeInsets.only(top: 10.0),     child : new RaisedButton(                 onPressed: _submit,                 child: new Text('Login'),               ), 
like image 71
Raouf Rahiche Avatar answered Sep 24 '22 10:09

Raouf Rahiche