currency_decimal_formatter 0.0.8 copy "currency_decimal_formatter: ^0.0.8" to clipboard
currency_decimal_formatter: ^0.0.8 copied to clipboard

Currency TextField formatter and utilities for converting between text and currency amounts.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:currency_decimal_formatter/currency_decimal_formatter.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: ExamplePage(title: 'ExamplePage'),
    );
  }
}

class ExamplePage extends StatefulWidget {
  final String title;

  const ExamplePage({Key key, this.title}) : super(key: key);

  @override
  _ExamplePageState createState() => _ExamplePageState();
}

class _ExampleMask {
  final TextEditingController textController = TextEditingController();
}

class _ExamplePageState extends State<ExamplePage> {
  String _currency;

  @override
  Widget build(BuildContext context) {
    String locale = Localizations.localeOf(context).toString();
    int decimalDigits = NumberFormat.currency(name: _currency).decimalDigits;
    CurrencyTextInputFormatter textFormatter = CurrencyTextInputFormatter(
      locale: locale,
      decimalDigits: decimalDigits,
    );
    return Scaffold(
        body: Center(
            child: Row(children: [
      DropdownButton<String>(
        items: <String>['USD', 'EUR', 'JPY', 'BRL'].map((String value) {
          return new DropdownMenuItem<String>(
            value: value,
            child: new Text(value),
          );
        }).toList(),
        onChanged: (String value) {
          _currency = value;
        },
      ),
      TextField(
        controller: textController,
        inputFormatters: [
          textFormatter,
        ],
      )
    ])));
  }
}
3
likes
110
pub points
54%
popularity

Publisher

unverified uploader

Currency TextField formatter and utilities for converting between text and currency amounts.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

decimal, flutter, intl

More

Packages that depend on currency_decimal_formatter