FMT – 2 (How to draw a horizontal line in Flutter?)

I need this horizontal line in almost all of my apps and it doesn’t change while developing apps with Flutter. Luckily, it is very easy to add this line in Flutter. Just copy and paste the following code to the appropriate place in your code.

Padding(
                padding: EdgeInsets.symmetric(horizontal: 20.0),
                child: Container(
                  height: 2.5,
                  width: 150.0,
                  color: Colors.black,
                  margin: EdgeInsets.only(bottom: 25.0),
                ),
              ),

Even though the code is very simple and self-explanatory I still want to mention that you can change the line’s specifications just changing the numbers.

Another way of adding this line is using the Divider class.

const Divider(
                color: Colors.black,
                height: 2.5,
                thickness: 2,
                indent: 50,
                endIndent: 0,
              ),

Divider class is easier and mostly sufficient for your needs but sometimes I prefer the first way as it let me use “margin” property.

Both methods are shown sequentially in the picture.

Happy coding…

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.