FlutterMoneyFormatter

FlutterMoneyFormatter is a Flutter extension to formatting various types of currencies according to the characteristics you like, without having to be tied to any localization.

latest version last commit License

Dependencies :

intl


Install

For complete steps in installing FlutterMoneyFormatter you can see in the Installation Guide.

Usage

Import the library

import 'package:flutter_money_formatter/flutter_money_formatter.dart';

Getting Started

To be able to format your double value into the various formats you want, you first need to create a FlutterMoneyFormatter instance like the following:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(amount: 12345678.9012345);

Note, the code above still uses the default configuration as explained here.

After that you can request various results of the format as follows:

// normal form
print(fmf.formattedNonSymbol); // 12,345,678.90
print(fmf.formattedLeftSymbol); // $12,345,678.90
print(fmf.formattedRightSymbol); // 12,345,678.90$
print(fmf.fractionDigitsOnly); // 90
print(fmf.withoutDecimal); // 12,345,678

// compact form
print(fmf.compactNonSymbol) // 12.3M
print(fmf.compactLeftSymbol) // $12.3M
print(fmf.compactRightSymbol) // 12.3M$

See demo section to get more info.

Configurations

To adjust the format to suit your needs, you can use my favorite notation way:

FlutterMoneyFormatter fmf = new FlutterMoneyFormatter(amount: 12345678.9012345)
    ..symbol = 'IDR'
    ..thousandSeparator = '.'
    ..decimalSeparator = ','
    ..fractionDigits = 3
    ..symbolAndNumberSeparator = '-';

Of course, you don't need to change the whole properties like on above sample. By default the properties have the default values as follows:

Configuration PropertyData TypeDefault ValueDescription
symbolString$ (Dollar Sign)The symbol that will be used on formatted output.
thousandSeparatorString,The character that will be used as thousand separator on formatted output.
decimalSeparatorString.The character that will be used as decimal separator on formatted output.
fractionDigitsint2The fraction digits that will be used on formatted output.
symbolAndNumberSeparatorString' ' (Space)If the value is true then formatted output will shown space between the number and the currency symbol.
compactFormatTypeCompactFormatTypeCompactFormatType.sortCompact format type, sort or long type.

CompactFormatType

You can change the type of compact format like for million using M or million, or trillion using T or trillion. and so on. This type only supports two type as described below:

ValueDescription
CompactFormatType.sortUsed to make the compact format displayed using sort text.
CompactFormatType.longUsed to make the compact format displayed using long text.

Duplicating Instance

For some reasons, you may need to duplicate the instance and just need to change some configurations. To do that, you can use the copyWith method as below:

FlutterMoneyFormatter fmf = FlutterMoneyFormatter(amount: 12345678.9012345)

print(fmf.formattedLeftSymbol); // $ 12,345,678.90
print(fmf.copyWith(symbol: 'IDR', symbolAndNumberSeparator: '-').formattedLeftSymbol); // IDR-12,345,678.90

Complete Methods

MethodParameterDescriptions
isLowerThanamountCheck current instance-amount is lower than amount or not.
isGreaterThanamountCheck current instance-amount is greater than amount or not.
isEqualamountCheck current instance amount is equal than amount or not.
isEqualOrLowerThanamountCheck current instance amount is equal or lower than amount or not.
isEqualOrGreaterThanamountCheck current instance amount is equal or greater than amount or not.
CopyWithsee heresee here

Demo

For more complete samples, you can grab it from the example directory.

Help Me

If you find an issue, bug, question, or want to request a new feature you can do it here. You can also help me to improve features or fix some issues by forking this project via Github

ChangeLog

Are you curious about the changes that occur in each version? See here for detailed informations.

Libraries

flutter_money_formatter
Copyright (c) 2019, Fadhly Permata. email : fadhly.permata@gmail.com github : https://github.com/fadhly-permata/flutter_money_formatter

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]