Flutter框架TextField组件的textInputAction属性

阳航
2023-12-01

textInputAction属性列表
textInputAction: TextInputAction.none,
textInputAction: TextInputAction.unspecified,
textInputAction: TextInputAction.done,
textInputAction: TextInputAction.go,
textInputAction: TextInputAction.search,
textInputAction: TextInputAction.send,
textInputAction: TextInputAction.next,
textInputAction: TextInputAction.previous,
textInputAction: TextInputAction.continueAction,
textInputAction: TextInputAction.join,
textInputAction: TextInputAction.route,
textInputAction: TextInputAction.emergencyCall,
textInputAction: TextInputAction.newline,

[
    发送,
    textInputAction:TextInputAction.send,
    搜索,
    textInputAction:TextInputAction.search,
    加入(仅ios支持),
    textInputAction:TextInputAction.join,
    访问,
    textInputAction:TextInputAction.go,
    上一个(ios不支持),
    textInputAction:TextInputAction.previous,
    下一个,
    textInputAction:TextInputAction.next,
    完成按钮
    textInputAction:TextInputAction.done,
    操作系统自己选择最优
    textInputAction: TextInputAction.unspecified,
    操作系统自己选(仅安卓支持)
    textInputAction: TextInputAction.none,
    继续(仅ios支持)
    textInputAction: TextInputAction.continueAction,
    路线(仅ios支持)
    textInputAction: TextInputAction.route,
    紧急呼叫(仅ios支持)
    textInputAction: TextInputAction.emergencyCall,
    安卓(换行回车)ios(返回)
    textInputAction: TextInputAction.newline,

]

用户请求文本输入控件执行的操作。
每个动作代表一个逻辑意义,同时也配置软键盘显示某种动作按钮。
操作按钮的视觉外观可能在同一操作系统的版本之间有所不同。
尽管每个动作都有逻辑意义,但选择特定的 [TextInputAction] 并不一定会导致任何特定行为发生,除非在适当时更改焦点。
开发人员有责任确保按下操作按钮时发生的行为适合所选的操作按钮。
例如:如果用户按下 iOS 上的键盘操作按钮,当它
读取“紧急呼叫”,结果不应该是焦点更改到下一个
文本域。此行为在逻辑上不适用于显示以下内容的按钮
“紧急电话”。
有关自定义操作按钮行为的更多信息,请参阅 [EditableText]。
Android 和 iOS 均支持大多数 [TextInputAction]。
但是,Android 的 IME 输入类型和 iOS 的键盘返回类型之间没有完整的直接映射。
因此,某些 [TextInputAction] 不适用于其中一个平台。
如果开发者在调试模式下运行时选择了不合适的[TextInputAction],将会抛出错误。
如果在发布模式下做同样的事情,那么 Android 将在平台端使用“未指定”,而 iOS 将在平台端使用“默认”,而不是发送不适当的值。
也可以看看:

  • [TextInput],配置平台的键盘设置。
  • [EditableText],当操作按钮被按下时调用回调。
// An action the user has requested the text input control to perform.
// Each action represents a logical meaning, and also configures the soft keyboard to display a certain kind of action button. 
// The visual appearance of the action button might differ between versions of the same OS.
// Despite the logical meaning of each action, choosing a particular [TextInputAction] does not necessarily cause any specific behavior to happen, other than changing the focus when appropriate. 
// It is up to the developer to ensure that the behavior that occurs when an action button is pressed is appropriate for the action button chosen.
// For example: If the user presses the keyboard action button on iOS when it
// reads "Emergency Call", the result should not be a focus change to the next
// TextField. This behavior is not logically appropriate for a button that says
// "Emergency Call".
// See [EditableText] for more information about customizing action button behavior.
// Most [TextInputAction]s are supported equally by both Android and iOS.
// However, there is not a complete, direct mapping between Android's IME input types and iOS's keyboard return types. 
// Therefore, some [TextInputAction]s are inappropriate for one of the platforms. 
// If a developer chooses an inappropriate [TextInputAction] when running in debug mode, an error will be thrown.
// If the same thing is done in release mode, then instead of sending the inappropriate value, Android will use "unspecified" on the platform side and iOS will use "default" on the platform side.
// See also:
// * [TextInput], which configures the platform's keyboard setup.
// * [EditableText], which invokes callbacks when the action button is pressed.

textInputAction: TextInputAction.none,
逻辑含义:当前输入源没有相关的输入动作,例如[TextField]。
Android:对应Android的“IME_ACTION_NONE”。 键盘设置由操作系统决定。 键盘可能会显示一个返回键。
iOS:iOS 没有“无”的键盘返回类型。 在 iOS 上运行时选择这个 [TextInputAction] 是不合适的。

// Logical meaning: There is no relevant input action for the current inputsource, e.g., [TextField].
// Android: Corresponds to Android's "IME_ACTION_NONE". The keyboard setup is decided by the OS. The keyboard will likely show a return key.
// iOS: iOS does not have a keyboard return type of "none." It is inappropriate to choose this [TextInputAction] when running on iOS.

textInputAction: TextInputAction.unspecified,
逻辑含义:让操作系统决定哪个动作最合适。
Android:对应Android的“IME_ACTION_UNSPECIFIED”。
操作系统选择要显示的键盘操作。
该决定可能是完成按钮或返回键。
iOS:对应于 iOS 的“UIReturnKeyDefault”。 动作按钮中显示的标题是“返回”。

// Logical meaning: Let the OS decide which action is most appropriate.
// Android: Corresponds to Android's "IME_ACTION_UNSPECIFIED". 
// The OS chooses which keyboard action to display. 
// The decision will likely be a done button or a return key.
// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in the action button is "return".

textInputAction: TextInputAction.done,
逻辑含义:用户完成为一组输入(如表单)提供输入。
现在应该发生某种终结行为。
Android:对应Android的“IME_ACTION_DONE”。 操作系统显示一个代表完成的按钮,例如,一个复选标记按钮。
iOS:对应iOS的“UIReturnKeyDone”。 操作按钮中显示的标题是“完成”。

// Logical meaning: The user is done providing input to a group of inputs(like a form). 
// Some kind of finalization behavior should now take place.
// Android: Corresponds to Android's "IME_ACTION_DONE". The OS displays a button that represents completion, e.g., a checkmark button.
// iOS: Corresponds to iOS's "UIReturnKeyDone". The title displayed in the action button is "Done".

textInputAction: TextInputAction.go,
逻辑含义:用户输入了一些代表目的地的文本,例如餐厅名称。
“开始”按钮旨在采取
用户访问与此目的地对应的应用程序部分。
Android:对应Android的“IME_ACTION_GO”。
操作系统会显示一个按钮,表示将“用户带到他们所阅读的文本的目标”
typed”,例如,一个向右的箭头按钮。
iOS:对应iOS的“UIReturnKeyGo”。 操作按钮中显示的标题是“开始”。

// Logical meaning: The user has entered some text that represents adestination, e.g., a restaurant name.
// The "go" button is intended to take
// the user to a part of the app that corresponds to this destination.
// Android: Corresponds to Android's "IME_ACTION_GO". 
// The OS displays a button that represents taking "the user to the target of the text they
// typed", e.g., a right-facing arrow button.
// iOS: Corresponds to iOS's "UIReturnKeyGo". The title displayed in the action button is "Go".

textInputAction: TextInputAction.search,
逻辑含义:执行搜索查询。
Android:对应Android的“IME_ACTION_SEARCH”。 操作系统显示代表搜索的按钮,例如放大镜按钮。
iOS:对应iOS的“UIReturnKeySearch”。 操作按钮中显示的标题是“搜索”。

// Logical meaning: Execute a search query.
// Android: Corresponds to Android's "IME_ACTION_SEARCH". The OS displays a button that represents a search, e.g., a magnifying glass button.
// iOS: Corresponds to iOS's "UIReturnKeySearch". The title displayed in the action button is "Search".

textInputAction: TextInputAction.send,
逻辑含义:发送用户编写的内容,例如邮件或短信。
Android:对应Android的“IME_ACTION_SEND”。 操作系统会显示一个代表发送内容的按钮,例如纸飞机按钮。
iOS:对应iOS的“UIReturnKeySend”。 操作按钮中显示的标题是“发送”。

// Logical meaning: Sends something that the user has composed, e.g., an nemail or a text message.
// Android: Corresponds to Android's "IME_ACTION_SEND". The OS displays a button that represents sending something, e.g., a paper plane button.
// iOS: Corresponds to iOS's "UIReturnKeySend". The title displayed in the action button is "Send".

textInputAction: TextInputAction.next,
逻辑含义:用户已经完成了当前输入源,想要移动到下一个输入源。
将焦点移动到同一 [FocusScope] 中的下一个可聚焦项目。
Android:对应Android的“IME_ACTION_NEXT”。 操作系统显示一个代表向前移动的按钮,例如,一个向右的箭头按钮。
iOS:对应iOS的“UIReturnKeyNext”。 操作按钮中显示的标题是“下一步”。

// Logical meaning: The user is done with the current input source and wants to move to the next one.
// Moves the focus to the next focusable item in the same [FocusScope].
// Android: Corresponds to Android's "IME_ACTION_NEXT". The OS displays a button that represents moving forward, e.g., a right-facing arrow button.
// iOS: Corresponds to iOS's "UIReturnKeyNext". The title displayed in the action button is "Next".

textInputAction: TextInputAction.previous,
逻辑含义:用户希望返回到组中之前的输入源,例如一个有多个[TextField]的表单。
将焦点移动到同一 [FocusScope] 中的上一个可聚焦项目。
Android:对应Android的“IME_ACTION_PREVIOUS”。 操作系统显示一个代表向后移动的按钮,例如,一个向左的箭头按钮。
iOS:iOS 没有“previous”的键盘返回类型。 在 iOS 上运行时选择这个 [TextInputAction] 是不合适的。

// Logical meaning: The user wishes to return to the previous input source in the group, e.g., a form with multiple [TextField]s.
// Moves the focus to the previous focusable item in the same [FocusScope].
// Android: Corresponds to Android's "IME_ACTION_PREVIOUS". The OS displays a button that represents moving backward, e.g., a left-facing arrow button.
// iOS: iOS does not have a keyboard return type of "previous." It is inappropriate to choose this [TextInputAction] when running on iOS.

textInputAction: TextInputAction.continueAction,
逻辑含义:在iOS应用中,“返回”按钮和“继续”按钮出现在屏幕顶部是很常见的。
但是,当键盘打开时,这些按钮通常会隐藏在屏幕外。
因此,iOS 上“继续”返回键的目的是让“继续”按钮在用户输入文本时可用。
除了历史背景,[TextInputAction.continueAction] 可以在“继续”一词似乎最适合给定动作的任何时候使用。
Android:Android 没有“继续”的 IME 输入类型。 在Android上运行时选择这个[TextInputAction]是不合适的。
iOS:对应iOS的“UIReturnKeyContinue”。 操作按钮中显示的标题是“继续”。 此操作仅适用于 iOS 9.0+。
这个值后置“Action”的原因是因为“continue”是 Dart 以及许多其他语言中的保留字。

// Logical meaning: In iOS apps, it is common for a "Back" button and "Continue" button to appear at the top of the screen.
// However, when the keyboard is open, these buttons are often hidden off-screen. 
// Therefore,the purpose of the "Continue" return key on iOS is to make the "Continue" button available when the user is entering text.
// Historical context aside, [TextInputAction.continueAction] can be used any time that the term "Continue" seems most appropriate for the given action.
// Android: Android does not have an IME input type of "continue." It is inappropriate to choose this [TextInputAction] when running on Android.
// iOS: Corresponds to iOS's "UIReturnKeyContinue". The title displayed in the action button is "Continue". This action is only available on iOS 9.0+.
// The reason that this value has "Action" post-fixed to it is because "continue" is a reserved word in Dart, as well as many other languages.

textInputAction: TextInputAction.join,
逻辑含义:用户想要加入某物,例如无线网络。
Android:Android 没有“加入”的 IME 输入类型。 在Android上运行时选择这个[TextInputAction]是不合适的。
iOS:对应iOS的“UIReturnKeyJoin”。 操作按钮中显示的标题是“加入”。

// Logical meaning: The user wants to join something, e.g., a wireless network.
// Android: Android does not have an IME input type of "join." It is inappropriate to choose this [TextInputAction] when running on Android.
// iOS: Corresponds to iOS's "UIReturnKeyJoin". The title displayed in the action button is "Join".

textInputAction: TextInputAction.route,
逻辑含义:用户想要路由选项,例如行车路线。
Android:Android 没有“路由”的 IME 输入类型。 在Android上运行时选择这个[TextInputAction]是不合适的。
iOS:对应iOS的“UIReturnKeyRoute”。 操作按钮中显示的标题是“路线”。

// Logical meaning: The user wants routing options, e.g., driving directions.
// Android: Android does not have an IME input type of "route." It is inappropriate to choose this [TextInputAction] when running on Android.
// iOS: Corresponds to iOS's "UIReturnKeyRoute". The title displayed in the action button is "Route".

textInputAction: TextInputAction.emergencyCall,
逻辑含义:向紧急服务发起呼叫。
Android:Android 没有“emergencyCall”的 IME 输入类型。 在Android上运行时选择这个[TextInputAction]是不合适的。
iOS:对应iOS的“UIReturnKeyEmergencyCall”。 操作按钮中显示的标题是“紧急呼叫”。

// Logical meaning: Initiate a call to emergency services.
// Android: Android does not have an IME input type of "emergencyCall." It is inappropriate to choose this [TextInputAction] when running on Android.
// iOS: Corresponds to iOS's "UIReturnKeyEmergencyCall". The title displayed in the action button is "Emergency Call".

textInputAction: TextInputAction.newline,
逻辑含义:在焦点文本输入中插入换行符,例如,[TextField]。
Android:对应Android的“IME_ACTION_NONE”。 操作系统显示一个代表新行的按钮,例如回车按钮。
iOS:对应于 iOS 的“UIReturnKeyDefault”。 动作按钮中显示的标题是“返回”。
Flutter 中存在 [TextInputAction.newline] 一词,但 Android 或 iOS 中不存在。
引入这个术语的原因是为了让开发者无需了解Android上的各种IME动作和iOS上的回车键就可以实现插入新行的通用结果。
因此,[TextInputAction.newline] 是一个方便的术语,它减轻了理解底层平台以实现这种常见行为的需要。

// Logical meaning: Insert a newline character in the focused text input,e.g., [TextField].
// Android: Corresponds to Android's "IME_ACTION_NONE". The OS displays a button that represents a new line, e.g., a carriage return button.
// iOS: Corresponds to iOS's "UIReturnKeyDefault". The title displayed in the action button is "return".
// The term [TextInputAction.newline] exists in Flutter but not in Androidor iOS. 
// The reason for introducing this term is so that developers can achieve the common result of inserting new lines without needing to understand the various IME actions on Android and return keys on iOS.
// Thus, [TextInputAction.newline] is a convenience term that alleviates the need to understand the underlying platforms to achieve this common behavior.
 类似资料: