1

On the image below the Demo Text label by default a little bit small. I tried to change labelSmall and labelMedium styles but it doesn't work for that. What style is responsible for that?

enter image description here

rozerro
  • 5,787
  • 9
  • 46
  • 94

3 Answers3

1

You can use floatingLabelStyle in InputDecoration of the TextField

Example:

    TextField(
      decoration: InputDecoration(
        floatingLabelStyle: TextStyle(
          color: Colors.red,
          fontSize: 12
        ),
        labelText: 'Demo Text',
        labelStyle: TextStyle(
          fontSize: 16
        )
      ),
    ),
Balaji
  • 1,773
  • 1
  • 17
  • 30
1

You can set the style using the parameter floatingLabelStyle in decoration:. See the example below:

TextField(
    decoration: InputDecoration(
        labelText: 'Enter your username',
        floatingLabelStyle: TextStyle(fontSize: 1)
    ),
)

Take a look at the Flutter docs about TextField widget here: https://docs.flutter.dev/cookbook/forms/text-input

Àlex Garcia
  • 101
  • 6
1

You can try this code:

var textStyle = const TextStyle(
                        fontSize: 40.0,
                        color: Colors.green,);
                
///
StatefulBuilder(
            builder: (BuildContext context, StateSetter setState) {
              return TextField(
                onChanged: (value) {
                  if (value.isEmpty) {
                    setState(() {
                      textStyle = const TextStyle(
                        fontSize: 40.0,
                        color: Colors.green,
                      );
                    });
                  } else {
                    setState(() {
                      textStyle = const TextStyle(
                        fontSize: 16.0,
                        color: Colors.red,
                      );
                    });
                  }
                },
                decoration: InputDecoration(
                  labelStyle: textStyle,
                    floatingLabelStyle: const TextStyle(
                    fontSize: 16.0,
                    color: Colors.red,
                  ),
                  label: Text('Demo Text'),
         
                ),
              );
            },
          )

Here is the screenshot of when the TextField is Empty:

enter image description here

Here is the screenshot of when the TextField is NotEmpty or is active:

enter image description here

And when you make the TextField Empty it changes to your Empty style.

happy coding...

Amirali Eric Janani
  • 1,477
  • 3
  • 10
  • 20