搜尋套件、儲存庫與 APP 分類

套件詳情v2.3.2

currency_text_input_formatter

Flutter 的貨幣文字輸入格式化程式。在您的 Flutter 應用中輕鬆簡單地使用它。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
12.1萬
喜歡數
293
Pub 分數
160

安裝套件

flutter pub add currency_text_input_formatter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可將文字輸入格式化為貨幣,自動加入符號、分隔符和小數點。它透過在使用者輸入時確保一致的格式化,簡化了文字欄位中金額值的處理。非常適合需要輸入財務資料的表單,支援多個平台,包括行動裝置、Web 與桌面。該格式化工具易於整合,並透過提供即時的貨幣輸入視覺反饋來提升使用者體驗。

適用情境

  • 金融應用程式表單輸入
  • 電子商務價格輸入
  • 費用追蹤應用程式
  • 發票和計費系統
  • 使用者資料財務細節
  • 支付網關整合

主要特色

  • 即時貨幣格式化
  • 支援自訂貨幣符號
  • 自動小數與千位分隔符
  • 跨平台相容性
  • 與 TextFields 的簡單整合
  • 可設定的小數位數

適合對象

  • 開發金融相關應用的開發者
  • 需要格式化貨幣輸入的應用程式
  • 需要一致數字格式的項目
  • 優先考慮使用者輸入可用性的團隊
  • Flutter 初學者尋找簡單的格式化工具

使用建議

  • 可能需要針對邊緣情況進行額外驗證
  • 自訂選項僅限基本格式
  • 不處理貨幣轉換
  • 在沒有額外邏輯的情況下,不適用於多貨幣環境
  • 性能影響微乎其微但存在,尤其是在高頻率更新時

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Currency Text Input Formatter

pub package

Currency Text Input Formatter for Flutter. https://pub.dev/packages/currency_text_input_formatter

Installation

Solving Intl package conflict

Add this code end of pubspec.yaml.

dependency_overrides:
  intl: your intl package version

Usage

Basic
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: TextField(
            inputFormatters: [CurrencyTextInputFormatter.currency()],
            // inputFormatters: [CurrencyTextInputFormatter.simpleCurrency()], < for simple
            // inputFormatters: [CurrencyTextInputFormatter()], < for basic
            keyboardType: TextInputType.number,
          ),
        ),
      ),
    );
  }
}
With initialValue
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Welcome to Flutter'),
        ),
        body: Center(
          child: MyFormField(),
        ),
      ),
    );
  }
}

class MyFormField extends StatefulWidget {
  const MyFormField({ super.key });

  @override
  State<MyFormField> createState() => _MyFormFieldState();
}

class _MyFormFieldState extends State<MyFormField> {
  final CurrencyTextInputFormatter _formatter = CurrencyTextInputFormatter.currency();

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      initialValue: _formatter.formatString('2000'),
      inputFormatters: <TextInputFormatter>[_formatter],
      keyboardType: TextInputType.number,
    );
  }
}
Custom Options
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Welcome to Flutter'),
        ),
        body: Center(
          child: TextField(
            inputFormatters: <TextInputFormatter>[
              CurrencyTextInputFormatter.currency(
                locale: 'ko',
                decimalDigits: 0,
                symbol: 'KRW(원) ',
              ),
            ],
            keyboardType: TextInputType.number,
          ),
        ),
      ),
    );
  }
}
With built-in methods
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Welcome to Flutter'),
        ),
        body: Center(
          child: MyFormField(),
        ),
      ),
    );
  }
}

class MyFormField extends StatefulWidget {
  const MyFormField({ super.key });

  @override
  State<MyFormField> createState() => _MyFormFieldState();
}

class _MyFormFieldState extends State<MyFormField> {
  final CurrencyTextInputFormatter _formatter = CurrencyTextInputFormatter.currency();

  @override
  Widget build(BuildContext context) {
    // Built-in Methods
    print(_formatter.getFormattedValue()); // $ 2,000
    print(_formatter.getUnformattedValue()); // 2000.00
    print(_formatter.formatString('2000')); // $ 2,000
    print(_formatter.formatDouble(20.00)); // $ 20

    return TextFormField(
      inputFormatters: <TextInputFormatter>[_formatter],
      keyboardType: TextInputType.number,
    );
  }
}

Recommend Libraries

Maintainer

License

MIT

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案