How to add a border to a widget in Flutter

October 09, 2022 No comments flutter dart border flutter-widget

Introduction

In Flutter, we may need to add a border to a widget. We'll examine how to do it in this tutorial.

How to add a border to a widget in Flutter

To add a border to a widget in Flutter you can add the Text as a child to a Container that has a BoxDecoration with border property:

Container(
  margin: const EdgeInsets.all(15.0),
  padding: const EdgeInsets.all(3.0),
  decoration: BoxDecoration(
    border: Border.all(color: Colors.blueAccent)
  ),
  child: Text('This is a nice border'),
)

Conclusion

In this short article, we described how to add a border to a widget in Flutter.

{{ message }}

{{ 'Comments are closed.' | trans }}