搜索插件、代码仓与 APP 分类

插件详情v1.0.0+9

number_text_input_formatter

Flutter 的数字文本输入格式化程序

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3
喜欢数
32
Pub 分数
130

安装插件

flutter pub add number_text_input_formatter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可将文本输入格式化为数字,自动处理小数点、千位分隔符和负号。它确保用户输入符合数字规范,同时在文本字段中保持清晰易读的格式。非常适合需要输入数值的表单,例如价格、数量或度量值。该格式化程序可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上运行,无论设备如何,都能提供一致的行为。支持自定义小数精度和特定地区的格式化。

适合场景

  • 价格的表单输入
  • 带格式的数量输入
  • 测量数据收集
  • 金融应用
  • 用户友好的数字输入
  • 实时验证的数据输入

主要特点

  • 数字的自动格式化
  • 支持小数和负数
  • 千位分隔符支持
  • 可自定义的小数精度
  • 跨平台一致性
  • 本地化感知格式化

适合对象

  • 开发金融应用的开发者
  • 需要数值输入的表单
  • 需要实时输入反馈的应用程序
  • 跨平台 Flutter 项目
  • 偏好格式化数字输入的用户

使用建议

  • 可能需要对边缘情况额外进行验证
  • 如果配置不当,可能会干扰键盘导航
  • 仅限数字格式化
  • 默认情况下不处理非数字字符
  • 对高频更新的性能影响

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Number Text Input Formatter

Number Text Input Formatter for Flutter.

Installation

dependencies:
  number_text_input_formatter: ^1.0.0

Usage

NumberTextInputFormatter

General-purpose formatter for numeric input fields.

TextField(
  inputFormatters: [
    NumberTextInputFormatter(
      integerDigits: 10,
      decimalDigits: 2,
      maxValue: '1000000000.00',
      decimalSeparator: '.',
      groupDigits: 3,
      groupSeparator: ',',
      allowNegative: false,
      overrideDecimalPoint: true,
      insertDecimalPoint: false,
      insertDecimalDigits: true,
    ),
  ],
  keyboardType: TextInputType.number,
),
Parameters
Parameter Type Default Description
integerDigits int? null Maximum number of integer digits. Must be > 0 if provided.
decimalDigits int? null Maximum number of decimal digits. Must be >= 0 if provided.
maxValue String? null Maximum allowed value (e.g. '9999.99'). Infers integerDigits and decimalDigits if not set.
decimalSeparator String '.' Character used as the decimal point. Must be a single character.
groupDigits int? null Group integer digits every N digits (e.g. 3 for thousands). Must be > 1 if provided.
groupSeparator String ',' Character used as the grouping separator. Must be a single character, different from decimalSeparator.
allowNegative bool false Whether to allow negative numbers.
fixNumber bool true Inserts 0 before a leading decimal point, and 0 after a trailing decimal point.
insertDecimalPoint bool false Automatically inserts the decimal point as the user types (e.g. 123 → 1.23). Requires decimalDigits to be set.
insertDecimalDigits bool false Always appends decimal digits with zeros (e.g. 5 → 5.00). Requires decimalDigits to be set.
overrideDecimalPoint bool false When a second decimal point is typed, moves the decimal point to the new position instead of ignoring it.
prefix String? null String prepended to the formatted value (e.g. '\$ ').
suffix String? null String appended to the formatted value (e.g. ' USD').

CurrencyTextInputFormatter

Pre-configured formatter for currency input. Defaults: 2 decimal digits, grouping every 3 digits, decimal point auto-inserted.

TextField(
  inputFormatters: [
    CurrencyTextInputFormatter(
      prefix: '\$ ',
    ),
  ],
  keyboardType: TextInputType.number,
),
Parameters

Same as NumberTextInputFormatter with these defaults:

Parameter Default
decimalDigits 2
groupDigits 3
insertDecimalPoint true

PercentageTextInputFormatter

Pre-configured formatter for percentage input. Defaults: max 100, 0 decimal digits, decimal digits always inserted.

TextField(
  inputFormatters: [
    PercentageTextInputFormatter(
      suffix: '%',
    ),
  ],
  keyboardType: TextInputType.number,
),
Parameters

Same as NumberTextInputFormatter with these defaults:

Parameter Default
integerDigits 3 (minimum 3)
decimalDigits 0
insertDecimalDigits true

The maxValue is automatically computed from integerDigits and decimalDigits (e.g. integerDigits: 3 → max 100).

所属分类

源码仓库

使用此插件的项目

暂无相关数据。