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

对着背影说爱祢 提交于 2019-12-22 11:28:43

问题


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 (.)?


回答1:


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



来源:https://stackoverflow.com/questions/55570414/flutter-textfield-with-number-keyboard-comma-is-needed-instead-of-period-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!