Skip to content
The Chat Archive
Amazon Novaamazon-nova-experimental-chat-05-14· Amazon LMArena Human Preference 140K

InputDecoration , how many border type are there?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-opus-4-20250514’s answer.
  1. User

    InputDecoration , how many border type are there?

  2. Assistant

    In Flutter, the InputDecoration class is used to style TextField and TextFormField widgets. The InputDecoration class provides several properties to customise the appearance of the input field, including various border types.

    There are five types of borders you can specify in InputDecoration. Each border type corresponds to a different state of the TextField:

    1. enabledBorder:

      • The border to display when the TextField is enabled and not focused.
    2. focusedBorder:

      • The border to display when the TextField is focused.
    3. errorBorder:

      • The border to display when the TextField has an error and is not focused.
    4. focusedErrorBorder:

      • The border to display when the TextField has an error and is focused.
    5. disabledBorder:

      • The border to display when the TextField is disabled.

    Here is an example demonstrating how to use these border types in an InputDecoration:

    TextField(
      decoration: InputDecoration(
        labelText: 'Enter text',
        // Border when the TextField is enabled and not focused
        enabledBorder: OutlineInputBorder(
          borderSide: BorderSide(color: Colors.grey, width: 2.0),
          borderRadius: BorderRadius.circular(10.0),
        ),
        // Border when the TextField is focused
        focusedBorder: OutlineInputBorder(
          borderSide: BorderSide(color: Colors.blue, width: 2.0),
          borderRadius: BorderRadius.circular(10.0),
        ),
        // Border when the TextField has an error and is not focused
        errorBorder: OutlineInputBorder(
          borderSide: BorderSide(color: Colors.red, width: 2.0),
          borderRadius: BorderRadius.circular(10.0),
        ),
        // Border when the TextField has an error and is focused
        focusedErrorBorder: OutlineInputBorder(
          borderSide: BorderSide(color: Colors.redAccent, width: 2.0),
          borderRadius: BorderRadius.circular(10.0),
        ),
        // Border when the TextField is disabled
        disabledBorder: OutlineInputBorder(
          borderSide: BorderSide(color: Colors.grey.shade400, width: 2.0),
          borderRadius: BorderRadius.circular(10.0),
        ),
      ),
    )
    

    Border Types

    In addition to specifying different borders for different states, Flutter also provides several pre-defined border types that you can use for these properties. Here are the most commonly used border types:

    1. UnderlineInputBorder:
      • Displays a simple underline below the text field.
      UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.blue),
      )
      
    2. OutlineInputBorder:
      • Displays a rectangular border around the text field.
      OutlineInputBorder(
        borderSide: BorderSide(color: Colors.blue),
        borderRadius: BorderRadius.circular(10.0),
      )
      
    3. StadiumBorder:
      • Displays a stadium-shaped (pill-shaped) border around the text field.
      StadiumBorder(
        side: BorderSide(color: Colors.blue),
      )
      
    4. RoundedRectangleBorder:
      • Displays a border with rounded corners around the text field.
      RoundedRectangleBorder(
        side: BorderSide(color: Colors.blue),
        borderRadius: BorderRadius.circular(10.0),
      )
      
    5. InputBorder.none:
      • Displays no border.
      InputBorder.none
      

    You can use these border types for any of the five border properties (enabledBorder, focusedBorder, errorBorder, focusedErrorBorder, and disabledBorder) in the InputDecoration.

    Complete Example with Different Border Types

    Here is a complete example that demonstrates using different border types for each state:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            appBar: AppBar(title: const Text('InputDecoration Border Example')),
            body: const Padding(
              padding: EdgeInsets.all(16.0),
              child: MyTextField(),
            ),
          ),
        );
      }
    }
    
    class MyTextField extends StatelessWidget {
      const MyTextField({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return TextField(
          decoration: InputDecoration(
            labelText: 'Enter text',
            enabledBorder: const UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.grey),
            ),
            focusedBorder: OutlineInputBorder(
              borderSide: const BorderSide(color: Colors.blue, width: 2.0),
              borderRadius: BorderRadius.circular(10.0),
            ),
            errorBorder: const StadiumBorder(
              side: BorderSide(color: Colors.red, width: 2.0),
            ),
            focusedErrorBorder: RoundedRectangleBorder(
              side: const BorderSide(color: Colors.redAccent, width: 2.0),
              borderRadius: BorderRadius.circular(10.0),
            ),
            disabledBorder: InputBorder.none,
          ),
        );
      }
    }
    

    In this example:

    • enabledBorder uses UnderlineInputBorder.
    • focusedBorder uses OutlineInputBorder.
    • errorBorder uses StadiumBorder.
    • focusedErrorBorder uses RoundedRectangleBorder.
    • disabledBorder uses InputBorder.none.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.