How to add Space between two widgets?

This Article is posted by seven.srikanth at 9/21/2019 9:42:05 AM



In this article, I'm going to share the code on how to add space between two widgets.

Here is how it looks before and after.

Before:


After:



This can be achieved through FractionalSizedBox, by specifying heightFactor.

FractionallySizedBox(heightFactor: 0.1,)

But, you will see the yellow-striped lines with both widgets places on extreme ends when you don't wrap it inside a Flexible widget.

So, in order to achieve this, below is the code which is required.

Flexible(child:FractionallySizedBox(
heightFactor: 0.1,
)), 

Here is the final code from main.dart file.

import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double padValue = 0;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text("Space between widgets Example"),
          ),
          body: Center(
            child: Column(
                children:  
                [    
                   Flexible(
                    child:FractionallySizedBox(
                    heightFactor: 0.1,
                  )),              
                  RaisedButton(
                  onPressed: () {
                    print('Button Clicked');
                    },
                  child: Text('Click me'),
                ),
                  Flexible(
                    child:FractionallySizedBox(
                    heightFactor: 0.1,
                  )),  
                RaisedButton(
                  onPressed: () {
                    print('Button Clicked');
                    },
                  child: Text('Click me'),
                )]
              ),
          )),
    );
  }
}

Thanks,
Srikanth



Tags: FractionallySizedBox; Flexible;








0 Comments
Login to comment.
Recent Comments












© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com