Home > Back-end >  Flutter - how to change keyboard theme to dark?
Flutter - how to change keyboard theme to dark?

Time:12-15

I use dark theme for app, but keyboard which appears with TextField has white background and dark numbers (used keyboard type: TextInputType.number). How to change keyboard theme to dark?

theme: ThemeData.dark().copyWith( ...

CodePudding user response:

you can change it as:

final ThemeData themeDark = ThemeData(
  primaryColorBrightness: Brightness.dark,
  // ...
);

CodePudding user response:

Two methods below

If you use ThemeData for global styling of your app, you can set primaryColorBrightness. The keyboard of a text field will use this brightness (light or dark) if no value is given for keyboardAppearance.

    final ThemeData themeDark = ThemeData(
  primaryColorBrightness: Brightness.dark,
  // ...
);

This has the advantage that you don't have to define keyboardAppearance for each text field.

See https://api.flutter.dev/flutter/material/TextField/keyboardAppearance.html

OR

White keyboard use Brightness.light

Black keyboard use Brightness.dark

 body: Center(
            child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
                TextField(
                    keyboardType: TextInputType.text,
                    keyboardAppearance: Brightness.dark, // no matter what you set, it simply shows Black keyboard
                )
            ],
            ),
        )
  • Related