Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TextField with number keyboard, comma is needed instead of period (Only iOS)

I want to create a TextField in Flutter. The TextField is for decimal numbers. So i set keyboardType: TextInputType.numberWithOptions(decimal: true). Now I get a number keyboard on iOS, but this number keyboard has a period (.) instead of a comma (,). The language of the iOS device is German.

My current TextField:

TextField(
  key: Key("pricePerLiter"),
  style: TextStyle(color: inputTextColor),
  textAlign: TextAlign.end,
  focusNode: pricePerLiterFocusNode,
  keyboardType:
      TextInputType.numberWithOptions(decimal: true),
  decoration: inputDecoration.copyWith(
      suffixText: "€", errorText: pricePerLiterError),
  controller: pricePerLiterTextController,
  onEditingComplete: () {},
  onChanged: (value) {},
)

My Localization is set up like following in my Material app:

MaterialApp(
  localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
  ],
  supportedLocales: [
    const Locale('de', 'DE'),
  ],
  home: MyHomePage(),
)

What do I need to change to get a number keyboard with a comma (,) instead of a period (.)?

like image 850
Niklas Raab Avatar asked Nov 06 '22 18:11

Niklas Raab


1 Answers

On iOS you have to enable the de (or any other locale than en_US) locale in the ios build settings even for flutter apps. Open the ios/Runner.xcworkspace of your flutter app with Xcode. Select the Project Runner. On the "Info" page you will see the locales enabled for your app under "Localisations". Add the de locale (or any other) here. Rebuild the app (by Xcode or Flutter, doesn't matter).

Look also here for another approach:

https://flutter.dev/docs/development/accessibility-and-localization/internationalization#appendix-updating-the-ios-app-bundle

like image 83
Olaf Schlüter Avatar answered Nov 15 '22 06:11

Olaf Schlüter