搜尋套件、儲存庫與 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);

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。