How to add borders to a widget in Flutter

There a few different ways to add a boundary to a Flutter gadget. The most fundamental route is to enclose your gadget by a DecoratedBox. Be that as it may, the Container gadget additionally has a DecoratedBox implicit. In the accompanying models I will utilize Container for the comfort of adding edge and cushioning.

Here is the overall arrangement for flutter.

1. Let’s say we want to make a square then all we need to do is:

Container(
margin: const EdgeInsets.all(30.0),
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
border: Border.all(),
),
child: Text(
"Exerror.com",
style: TextStyle(fontSize: 30.0),
),
)

Which will look like this:

2. Let’s say we want to make a square with blue borders all we need to do is:

         Container(
            margin: const EdgeInsets.all(30.0),
            padding: const EdgeInsets.all(10.0),
            decoration: BoxDecoration(
              border: Border.all(
                color: Colors.green,
                width: 2,
              ),
            ),
            child: Text(
              "Exerror.com",
              style: TextStyle(fontSize: 30.0),
            ),
          ),

Which will look like this:

3. If we want Corner Border then tryout this

      Container(
            margin: const EdgeInsets.all(30.0),
            padding: const EdgeInsets.all(10.0),
            decoration: BoxDecoration(
              border: Border.all(
                color: Colors.green,
                width: 2,
              ),
              borderRadius: BorderRadius.circular(10.0),
            ),
            child: Text(
              "Exerror.com",
              style: TextStyle(fontSize: 30.0),
            ),
          ),

Which will look like this:

4. Border side to Widget

 Container(
            margin: const EdgeInsets.all(30.0),
            padding: const EdgeInsets.all(10.0),
            decoration: BoxDecoration(
              border: Border(
                left: BorderSide(
                  color: Colors.black,
                  width: 3.0,
                ),
                top: BorderSide(
                  color: Colors.black,
                  width: 3.0,
                ),
              ),
            ),
            child: Text(
              "Exerror.com",
              style: TextStyle(fontSize: 30.0),
            ),
          ),

Which will look like this:

5.  BoxDecoration offers more customization like the possibility to define :

        Container(
            margin: EdgeInsets.all(30),
            padding: EdgeInsets.all(30),
            child: Text(' Exerror.com '),
            decoration: BoxDecoration(
              color: Colors.yellow,
              border: Border.all(
                color: Colors.red,
                width: 2.0,
              ),
              borderRadius: BorderRadius.circular(15),
            ),
          ),

Which will look like this:

I trust this post encourages you use the gadgets that Flutter offers to make a custom line to your own gadgets.

Summery

So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below on your suggestion.

Check Out Below Article

TypeError: this.getOptions is not a function in vue.js

exerror.com specifically for sharing programming issues and examples. We’ll be sharing some chunks of codes of PHP, Laravel Framework, CSS3, HTML5, MYSQL, Bootstrap, CodeIgniter Framework, JQuery, Javascript, Server, Ionic Framework, Python, flutter, macOS, Angular, etc Programming Language. On our site, I am sure you will find something good solution and a fine example of topics of PHP, Laravel Framework, CSS3, HTML5, MYSQL, Bootstrap, CodeIgniter Framework, JQuery, Javascript, Server, Ionic Framework, Python, flutter, macOS, Angular, etc Programming Language.

Leave a Comment

x