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

currency_textfield 封面
插件详情v5.0.0+1

currency_textfield

一个实现货币文本输入控制器的 Flutter 包。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
395
喜欢数
53
Pub 分数
160

安装插件

flutter pub add currency_textfield

插件介绍

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

一个 Flutter 包,提供专门的控制器来处理货币文本输入,具有自动格式化、掩码和验证功能。它确保用户以一致的格式输入货币值,自动插入小数点和货币符号,同时防止无效字符。非常适合需要精确财务数据输入的表单,支持移动、Web 和桌面等多种平台。该包通过减少输入错误并提高货币值的可读性,提升了用户体验。

适合场景

  • 财务表单输入
  • 电子商务结账字段
  • 预算应用
  • 发票和付款表单
  • 实时货币显示

主要特点

  • 自动小数格式化
  • 货币符号插入
  • 输入验证
  • 跨平台支持
  • 可自定义小数位数
  • 实时反馈

适合对象

  • 开发金融应用的开发者
  • 需要精确货币输入的应用程序
  • 需要严格数据格式的表单
  • 多平台金融工具
  • 专注于可用性和正确性的UI

使用建议

  • 可能需要额外的样式才能实现自定义外观
  • 仅限数值和货币特定行为
  • 不处理货币转换
  • 依赖于 TextEditingController 的正确初始化
  • 如果管理不当,与其他格式化程序可能存在潜在冲突

原始 README

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

currency_textfield

Build Status pub package

A Controller for currency text input

Demo

sample

Install

Follow this guide

Usage

Import the library

import 'package:currency_textfield/currency_textfield.dart';

Create the Controller

CurrencyTextFieldController controller = CurrencyTextFieldController()

Parameters and getters

Currency Symbol, Decimal and Thousand separator

It's possible to customize currencySymbol, decimalSymbol and thousandSymbol:

var controller = CurrencyTextFieldController(currencySymbol: "RR", decimalSymbol: ".", thousandSymbol: ",");
Get double value, get int value and get number in string format

To get the number value from controller, you can use both the doubleValue or the intValue properties:

//Double value:
final double val = controller.doubleValue;
//Int value:
final int val = controller.intValue;
//String number:
final int val = controller.textWithoutCurrencySymbol;
Initial value

You can initialize the controller using a int or a double, but not both at the same time. To make this, just use initDoubleValue or initIntValue:

final CurrencyTextFieldController controller2 = CurrencyTextFieldController(initDoubleValue: 10);
final CurrencyTextFieldController controller3 = CurrencyTextFieldController(initIntValue: 1000);

// this will raise an error!
final CurrencyTextFieldController controller4 = CurrencyTextFieldController(initIntValue: 1000,initDoubleValue: 10);
Position of the symbol and separator

You can decide if the symbol will be before or after the number. To make this, just use currencyOnLeft:

// default with the currency before the number
final CurrencyTextFieldController controller = CurrencyTextFieldController();

// currency after the number
final CurrencyTextFieldController controller2 = CurrencyTextFieldController(currencyOnLeft: false);

And also define the separator between the symbol and the value with currencySeparator:

// the default value is a single space
final CurrencyTextFieldController controller = CurrencyTextFieldController(currencySeparator: ' -> ');
Block the user from setting negative numbers

Just set enableNegative to false

Force a value from outside the TextField
final CurrencyTextFieldController controller = CurrencyTextFieldController();
// using a double
controller.forceValue(initDoubleValue: 300.5);

// using an int
controller.forceValue(initIntValue: 10000);
Change the currency symbol of the controller
final CurrencyTextFieldController controller = CurrencyTextFieldController();
// keeping the current value:
controller.replaceCurrencySymbol('EUR');

// reseting the current value:
controller.replaceCurrencySymbol('EUR', resetValue: true);

所属分类

源码仓库

使用此插件的项目

暂无相关数据。