Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
How to add one side border to container widget flutter

How to add one side border to container widget flutter?

Aman Jain, September 17, 2022March 16, 2024

In this tutorial we will learn to add add one side border to container widget flutter. Border is used to create border around the widget or container and using the border we can style it in different way like adding the width of border, color of border and one side border.

Flutter use BoxDecoration class and BorderSide class is user to render the border in container widget it accepts multiple options like border, border radius, color, background image, gradient, shape and etc. so to add the border first we need to add decoration option to container and then in decoration value we need to assign BoxDecoration class to implement the border.

You can simple create border to container as follow

 Container(
      decoration: BoxDecoration(
         border: Border.all(color:Colors.red,width:2.0)
      ),
      child: Text(
        'Hello, World!',
        style: TextStyle(color:Colors.white,fontSize:30),
      ),
    );
Flutter add border to widget all side
Flutter add border to widget all side

One side border to widget flutter

Sometimes we also want to add border to only one side of widget or container so then we can use BorderSide class to add the border to the one side or any side like left, right, bottom and top of container as follow

Container(
      decoration: BoxDecoration(
         border: Border(bottom:BorderSide(color:Colors.yellow))
      ),
      child: Text(
        'Hello, World!',
        style: Theme.of(context).textTheme.headline4,
      ),
    );
Flutter border to one side only
Flutter border to one side only

We can also add to right side as follow

Container(
      decoration: BoxDecoration(
         border: Border(right:BorderSide(color:Colors.yellow),
                       top:BorderSide(color:Colors.red,widht:2.0),
                       bottom:BorderSide(color:Colors.green,widht:4.0)
                 )
      ),
      child: Text(
        'Hello, World!',
        style: TextStyle(color:Colors.white,fontSize:30),,
      ),
    );

Then to each part of border we can configure the color, width and style of border.

Let’s understand add one side border to container widget flutter with example

Step 1 : Create flutter project

Very first step is to create the fluter application using command line tool or in Android studio.

flutter create example_app

This will create a new project with name my_app then go in to the folder .

Step 2 : Create a simple widget

Now, Create a simple state less widget to add the border to widget as follow

File : lib/borderexample.dart


class BorderExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
         border: Border(bottom:BorderSide(color:Colors.yellow))
      ),
      child: Text(
        'Hello, World!',
        style: TextStyle(color:Colors.white,fontSize:30),
      ),
    );
  }
}

Step 3: Import and use the widget in main

We just created a new widget with name BorderExample, now we are going to use it in our main.dart file as below

import 'package:flutter/material.dart'; 
import 'package:example_app/BorderExample.dart';;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: BorderExample(),
        ),
      ),
    );
  }
}

Step 4: Run the project

Simply run the project using command line or in android studio to check the implementation.

flutter run lib/main.dart

Read Also : How to Use Hash Hexadecimal Color Code in flutter ?

Related

Dart Flutter borderborderSideFluttterOne Part

Post navigation

Previous post
Next post

Related Posts

Dart How to add rounded border radius to image in flutter

How to add rounded border radius to image in flutter ?

September 19, 2022March 16, 2024

In this article we will learn to add rounded border radius to image in flutter. In flutter rounded corner border can be added using borderRadius but to add the rounded border to image is not same because by adding the border radius to container it won’t apply to child image….

Read More
Flutter Create a bottom tab in flutter

How to create bottom tab bar in flutter ?

January 9, 2022January 15, 2022

In this tutorial i will show you to create bottom tab in flutter. Now days bottom tabbing is much popular then creating drawer because tabbing is much easy to user and you can easily switch between the tabs. I will show you in this article to change the color of…

Read More
Dart How to create a scroll like tiktok in flutter

How to create a scroll like tiktok in flutter ?

January 8, 2022January 15, 2022

Flutter such a great framework to develop the mobile application using flutter we can create any type of complex using with ease. In this tutorial i will show you how can we make a UI like tiktok, Reels, moj like scroll in flutter. We will use PageView to create the…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version