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, 2023 in Android by Ashwini
• 5,430 points
11,457 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, 2023 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, 2023 in Android by vishalini
755 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, 2023 in Android by vinayak
14,732 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,620 points
456 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,690 points
2,320 views
0 votes
1 answer

How to add a ListView to a Column in Flutter?

To add a ListView to a Column ...READ MORE

answered Mar 9, 2023 in Android by pooja
15,493 views
0 votes
1 answer

How to deal with unwanted widget build?

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

answered Mar 10, 2023 in Android by vinayak
3,147 views
0 votes
1 answer

Adding a splash screen to Flutter apps

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

answered Mar 18, 2023 in Android by anonymous
1,017 views
0 votes
1 answer

What is the difference between functions and classes to create reusable widgets?

In Flutter, you can create reusable widgets ...READ MORE

answered Mar 24, 2023 in Flutter by vinayak
1,271 views
0 votes
1 answer

Passing Data to a Stateful Widget in Flutter

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

answered Mar 18, 2023 in Android by pooja
16,873 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,620 points
827 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