Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide one side of the border of a TextField, in Flutter?

I am using the TextField widget, and I want to hide the left side border, as shown here:

pic

TextField(
  decoration: new InputDecoration(
      border: new OutlineInputBorder(
          borderSide: const BorderSide(width: 2.0, style: BorderStyle.solid),
          borderRadius: BorderRadius.circular(50.0)),
      focusedBorder: OutlineInputBorder(
        borderSide: const BorderSide(color: Colors.grey, width: 2.0),
        borderRadius: BorderRadius.circular(50.0),
      ),
      hintText: 'User Name',
      hintStyle: new TextStyle(color: Colors.grey, fontWeight: FontWeight.bold),
      suffixIcon: const Icon(Icons.person, size: 30.0, color: Colors.grey),
      errorText: snapshot.error),
);

Thanks in advance!

like image 945
Sangeet Avatar asked Sep 01 '25 20:09

Sangeet


2 Answers

As of 2022 I'd like to add a solution using package assorted_layout_widgets:

NonUniformOutlineInputBorder

Can be used to style text-fields and containers.

Similar to Flutter's native OutlineInputBorder, but you can hide some of the sides, by setting hideTopSide, hideBottomSide, hideRightSide and hideLeftSide to true.

Usage for text-fields:

TextField(
   decoration: InputDecoration(
      enabledBorder: NonUniformOutlineInputBorder(hideLeftSide: true, ...),
      ...

Usage for containers:

Container(
   decoration: ShapeDecoration(
      shape: NonUniformOutlineInputBorder(
         hideLeftSide: true,
         borderSide: BorderSide(width: 10),
         borderRadius: BorderRadius.only(
            topRight: Radius.circular(15),
            bottomRight: Radius.circular(35),
         ),          
   ...

NonUniformRoundedRectangleBorder

Can be used to style buttons and containers.

Similar to Flutter's native RoundedRectangleBorder but you can hide some of the sides, by setting hideTopSide, hideBottomSide, hideRightSide and hideLeftSide to true.

Usage for buttons:

ElevatedButton(
   style: ElevatedButton.styleFrom(
      shape: NonUniformRoundedRectangleBorder(
         hideLeftSide: true,
         side: BorderSide(color: Colors.black87, width: 15.0),
         borderRadius: BorderRadius.only(
            topRight: Radius.circular(15),
            bottomRight: Radius.circular(35),
         ), 
      ...

Usage for containers:

Container(
   decoration: ShapeDecoration(
      shape: NonUniformRoundedRectangleBorder(...)),
   ...

Note: I'm the author of that package.

like image 86
MarcG Avatar answered Sep 03 '25 14:09

MarcG


You can change your BoxDecoration

decoration: BoxDecoration(
   border: Border(
    left: BorderSide(width: 16.0, color: Colors.transparent),
    top: BorderSide(width: 16.0, color: Colors.lightBlue.shade900),
    right: BorderSide(width: 16.0, color: Colors.lightBlue.shade900),
    bottom: BorderSide(width: 16.0, color: Colors.lightBlue.shade900),
),
like image 44
Ash Khachatryan Avatar answered Sep 03 '25 15:09

Ash Khachatryan