input_language library
Detect, observe and (on macOS / Windows) switch the active keyboard / input language, and resolve a text field's direction from it with a Unicode bidi first-strong-character fallback.
Solves flutter/flutter#25841. Start with KeyboardLanguage and
AutoDirectionTextField.
Classes
- AutoDirectionBuilder
-
Rebuilds any text field (
TextField,TextFormField,CupertinoTextField,EditableText) with the direction resolved from the keyboard language and the typed text. - AutoDirectionTextField
-
A Material TextField whose
textDirectionfollows the active keyboard language, falling back to the first strong character of the typed text. - InputLanguage
- A keyboard / input language reported by the platform.
- KeyboardDirectionController
-
Keeps a TextDirection in sync with a text field's content, focus and the
active keyboard language. Pass value to any
TextField.textDirection, or useAutoDirectionBuilder/AutoDirectionTextField. - KeyboardLanguage
- Reads, observes and (on macOS / Windows) switches the active keyboard / input language.
- KeyboardLanguageCapabilities
- What the current platform lets this package do.
- KeyboardLanguagePlatform
-
The interface every platform implementation of
input_languageimplements. Apps useKeyboardLanguage; this class is for implementers and tests. - MethodChannelKeyboardLanguage
- KeyboardLanguagePlatform backed by the native iOS, Android, macOS and Windows implementations over platform channels.
Enums
- AutoDirectionPolicy
- How resolveTextDirection combines the keyboard language with the typed text.
- InputLanguageSource
- Where an InputLanguage value came from.
- StrongDirection
- Strong bidirectional class of a single code point, as far as paragraph direction detection is concerned.
Constants
- kBidiUnicodeVersion → const String
- Unicode version the strong-direction table was generated from.
-
kRtlLanguages
→ const Set<
String> -
Languages whose default script is right-to-left, used when a tag has no
script subtag. Languages that are commonly written in several scripts
(e.g.
kuKurmanji,paPunjabi,azAzerbaijani,uzUzbek) default to their most common Latin / Indic script and are therefore not listed; tag them with a script (ku-Arab,pa-Arab) to get right-to-left. -
kRtlScripts
→ const Set<
String> - Script subtags (ISO 15924) whose text is written right-to-left.
Functions
-
canonicalizeLanguageTag(
String tag) → String -
Canonicalises a BCP-47 or POSIX/Java-style locale string:
_becomes-, the language is lower-cased, a 4-letter script is title-cased, a 2-letter region is upper-cased, legacy codes (iw,ji,in) are replaced, and a POSIX suffix (.UTF-8,@euro) is dropped. -
detectTextDirection(
String text) → TextDirection? -
Detects the paragraph direction of
textfrom its first strong character, following rules P2 and P3 of the Unicode Bidirectional Algorithm (UAX #9). -
isLanguageBearingTag(
String tag) → bool -
Whether
tagnames a real language (not the iOSemoji/dictationpseudo-modes or an undetermined / empty tag). -
isRtlLanguageTag(
String languageTag) → bool -
Whether text in the language identified by
languageTagis written right-to-left. -
localeFromLanguageTag(
String tag) → Locale - Converts a canonical BCP-47 tag to a Locale with language, optional script and optional region.
-
resolveTextDirection(
{required String text, InputLanguage? keyboard, AutoDirectionPolicy policy = AutoDirectionPolicy.keyboardThenText, TextDirection fallback = TextDirection.ltr}) → TextDirection -
Resolves the TextDirection for a text field whose content is
textwhile the user types withkeyboard. -
strongDirectionOf(
int codePoint) → StrongDirection? -
Returns the strong direction of
codePoint, ornullwhen the code point is not strong (digits, Arabic-Indic digits, punctuation, spaces, combining marks such as Arabic harakat or Hebrew niqqud, emoji, controls).
Typedefs
- AutoDirectionWidgetBuilder = Widget Function(BuildContext context, TextDirection direction, FocusNode focusNode)
- Signature of AutoDirectionBuilder.builder.