In Flutter's InputDecoration, there are 4 main border types that you can use. Each border type can be customized with different styles and colors.
The 4 Border Types
1. UnderlineInputBorder
- The default border style for Material Design
- Shows only a line at the bottom of the input field
- Commonly used in forms with a clean, minimal look
TextField(
decoration: InputDecoration(
labelText: "Underline Border",
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
),
),
)
2. OutlineInputBorder
- Shows a complete rectangular border around the input field
- Most commonly used for modern Material Design text fields
- Can have rounded corners with
borderRadius
TextField(
decoration: InputDecoration(
labelText: "Outline Border",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(color: Colors.green),
),
),
)
3. InputBorder.none
- Removes all borders from the input field
- Useful when you want a completely borderless text field
- Often used with custom containers or backgrounds
TextField(
decoration: InputDecoration(
labelText: "No Border",
border: InputBorder.none,
filled: true,
fillColor: Colors.grey[200],
),
)
4. Custom Border (Using InputBorder base class)
- You can create custom border implementations by extending
InputBorder
- Rarely needed, but allows for completely custom border designs
Border States in InputDecoration
For each border type, you can define different appearances for different states:
TextField(
decoration: InputDecoration(
labelText: "All Border States",
// Default border when not focused
border: OutlineInputBorder(),
// Border when enabled but not focused
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0),
),
// Border when focused
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue, width: 2.0),
),
// Border when disabled
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey[300]!, width: 1.0),
),
// Border when there's an error
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 1.0),
),
// Border when focused with an error
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 2.0),
),
),
)
Complete Example Showing All Border Types
import 'package:flutter/material.dart';
class BorderTypesDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("InputDecoration Border Types")),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
// 1. Underline Border
TextField(
decoration: InputDecoration(
labelText: "Underline Border (Default)",
helperText: "This is the default Material Design style",
border: UnderlineInputBorder(),
),
),
SizedBox(height: 20),
// 2. Outline Border
TextField(
decoration: InputDecoration(
labelText: "Outline Border",
helperText: "Modern Material Design style",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
SizedBox(height: 20),
// 3. No Border
TextField(
decoration: InputDecoration(
labelText: "No Border",
helperText: "Completely borderless",
border: InputBorder.none,
filled: true,
fillColor: Colors.grey[100],
),
),
SizedBox(height: 20),
// 4. Custom styled outline
TextField(
decoration: InputDecoration(
labelText: "Custom Styled Outline",
helperText: "With different colors for each state",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.purple,
width: 2.0,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.orange,
width: 3.0,
),
),
),
),
],
),
),
);
}
}
Summary
The main border types are:
- UnderlineInputBorder - Bottom line only (default)
- OutlineInputBorder - Full rectangle border
- InputBorder.none - No border
- Custom borders - By extending InputBorder class
Each can be customized for different states (enabled, focused, disabled, error) to create rich, interactive text field experiences.