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
12,481 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
899 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
15,836 views
0 votes
1 answer

How to add background image in flutter ?

To set a background image in Flutter, ...READ MORE

answered Mar 10, 2023 in Android by vinayak
41,951 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
521 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
17,245 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,397 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,129 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,382 views
0 votes
1 answer

How to create border radius of elevatedbutton in flutter

To create a rounded button with border-radius ...READ MORE

answered Mar 1, 2023 in Android by vishalini
33,287 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
17,663 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