How can I add a border to a widget in Flutter

0 votes

I'm using Flutter and I'd like to add a border to a widget (in this case, a Text widget).

I tried TextStyle and Text, but I didn't see how to add a border.

Feb 27 in Android by Ashwini
• 5,380 points
120 views

1 answer to this question.

0 votes

To add a border to a widget in Flutter, you can wrap it with a Container widget and set its decoration property to a BoxDecoration with the desired border settings.

Here's an example of how to add a border to a Text widget:

Container(
  decoration: BoxDecoration(
    border: Border.all(
      color: Colors.black,
      width: 2,
    ),
    borderRadius: BorderRadius.circular(10),
  ),
  child: Text(
    'Hello, World!',
    style: TextStyle(fontSize: 24),
  ),
),

In this example, we wrapped the Text widget with a Container widget and set its decoration property to a BoxDecoration with a black border of width 2, and a border radius of 10. You can adjust these values to suit your needs.

Note that you can also use other types of borders, such as BorderDirectional, and you can set different border properties such as dashPattern, style, and side.

To know more about Flutter, join our Best Flutter Course today.

answered Mar 1 by vishalini

Related Questions In Android

0 votes
1 answer

How can I remove the debug banner in Flutter?

The debug banner in Flutter can be ...READ MORE

answered Mar 1 in Android by vishalini
109 views
0 votes
1 answer

How do I disable a Button in Flutter?

To disable a button in Flutter, you ...READ MORE

answered Mar 10 in Android by vinayak
1,141 views
0 votes
0 answers

How do I turn a C# object into a JSON string in .NET?

I have classes like these: class MyDate { ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,160 points
134 views
0 votes
0 answers

How to define a circle shape in an Android XML drawable file?

I'm having some trouble locating the Android ...READ MORE

Nov 22, 2022 in Android by Edureka
• 12,530 points
1,019 views
0 votes
1 answer
0 votes
1 answer

How to deal with unwanted widget build?

There are a few strategies that you ...READ MORE

answered Mar 10 in Android by vinayak
136 views
0 votes
1 answer

Adding a splash screen to Flutter apps

To add a splash screen to your ...READ MORE

answered Mar 18 in Android by anonymous
126 views
0 votes
1 answer
0 votes
1 answer

Passing Data to a Stateful Widget in Flutter

The recommended way of passing data to ...READ MORE

answered Mar 18 in Android by pooja
818 views
0 votes
2 answers

How can I inspect element in an Android browser?

On Android smartphones, there are various ways ...READ MORE

answered Nov 15, 2022 in Android by Edureka
• 13,160 points
294 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP