currency_converter_pro 0.1.0 copy "currency_converter_pro: ^0.1.0" to clipboard
currency_converter_pro: ^0.1.0 copied to clipboard

Professional Currency and Crypto Converter for Flutter. Supports multi-providers, offline cache, historical rates, batch conversion, and real-time streams.

currency_converter_pro #

A simple and user-friendly Currency and Crypto Currency Converter Flutter application that allows users to convert currencies and crypto currencies, input an amount, and convert it to their desired target currency or crypto currency. The app leverages the CurrencyConverterPro plugin to fetch real-time exchange rates and perform accurate conversions.

logo Screen #

Features #

Multi-Currency and Crypto Support: Convert seamlessly between fiat currencies and cryptocurrencies within a single API call.

Multi-Currency Support: Convert between multiple currencies including USD, INR, EUR, GBP, JPY, AUD, CAD and more.

Easy Integration: Simple API to integrate currency conversion functionality into your Flutter applications.

Asynchronous Operations: Perform currency conversion in a non-blocking manner.

Cryptocurrency Conversion: Easily convert between popular cryptocurrencies such as Bitcoin (BTC), Ethereum (ETH), Ripple (XRP), and more.

Real-Time Exchange Rates: Access real-time data for accurate cryptocurrency conversions, ensuring your app always provides up-to-date information.

User-Friendly API: A simple and intuitive API designed for easy integration of cryptocurrency conversion functionality into your Flutter applications.

Example Application: Comes with a complete example application demonstrating how to implement cryptocurrency conversion features effectively.

Multi-Provider Support: Choose from multiple exchange rate providers or plug in your own.

Automatic Fallback: Configure multiple providers to ensure high availability.

Offline Cache: Automatically save exchange rates locally with configurable expiry and force-refresh support.

Historical Rates: Fetch exchange rates for any date in the past for accounting and reporting.

Batch Conversion: Convert one base currency to multiple target currencies in a single API call for better performance.

Live Exchange Rate Stream: Get real-time updates for currency pairs at configurable intervals.

Rich Conversion Result: Get detailed metadata including exchange rate, timestamp, provider info, and cache status.

Currency Formatter: Easily format amounts for different locales and currencies (e.g., ₹12,34,567.89).

Currency Picker Widget: A ready-made Flutter widget to select currencies with flags, search, and favorites.

Better Error Handling: Typed exceptions for easier debugging and robust apps.

Exchange Rate API: Simple method to fetch the raw exchange rate between two currencies.


Screenshots #

| Main Converter | Live Rates | Pro Features |


Getting Started #

To integrate this package into your Flutter project, follow these steps:

  1. Add Dependency Add the following to your pubspec.yaml file:

    dependencies:
      currency_converter_pro: ^0.1.0
    
  2. Install Dependencies Run the following command in your terminal:

    flutter pub get
    
    import 'package:currency_converter_pro/currency_converter_pro.dart';
    
  3. Currency Conversion Usage Here's how to use the CurrencyConverterPro plugin in your app for currency:

      final _currencyConverterProPlugin = CurrencyConverterPro();
          final result = await _currencyConverterProPlugin.convertCurrency(
            amount: 1.0,
            fromCurrency: 'usd',
            toCurrency: 'inr',
          );
    
  4. Currency Conversion Usage Here's how to use the CurrencyConverterPro plugin in your app for Crypto currency:

      final _currencyConverterProPlugin = CurrencyConverterPro();
          final result = await _currencyConverterProPlugin.convertCrypto(
            amount: 1.0,
            fromCurrency: 'bitcoin',
            toCurrency: 'ethereum',
          );
    
  5. Multi-Provider Support (New ⭐) You can now choose between different exchange rate providers or configure a fallback mechanism.

    Using a specific provider:

    final converter = CurrencyConverterPro(
      provider: FrankfurterProvider(),
    );
    

    Using a fallback mechanism:

    final converter = CurrencyConverterPro(
      provider: FallbackCurrencyProvider([
        ExchangeRateApiProvider(),
        FrankfurterProvider(),
        DefaultCurrencyProvider(),
      ]),
    );
    

    Custom Provider: Implement the CurrencyProvider interface to use your own API.

    class MyCustomProvider implements CurrencyProvider {
      @override
      Future<double> fetchExchangeRate({required String fromCurrency, required String toCurrency}) async {
        // Your custom logic here
      }
    }
    
  6. Offline Cache (New ⭐) Automatically save exchange rates locally. This ensures your app works even when the user is offline.

    Enable Caching:

    final converter = CurrencyConverterPro(
      cacheDuration: Duration(hours: 12), // Cache rates for 12 hours
    );
    

    Force Refresh:

    converter.forceRefresh();
    final rate = await converter.fetchExchangeRate(fromCurrency: 'usd', toCurrency: 'inr');
    

    Clear Cache:

    await converter.clearCache();
    
  7. Historical Exchange Rates (New ⭐) Fetch exchange rates for a specific date in the past. This is useful for accounting, tax reports, and tracking portfolio history.

    final converter = CurrencyConverterPro();
    final historicalRate = await converter.convertCurrency(
      amount: 100,
      fromCurrency: "usd",
      toCurrency: "inr",
      date: DateTime(2024, 5, 1),
    );
    
  8. Batch Conversion (New ⭐) Instead of making multiple requests, you can convert a base currency to multiple target currencies at once.

    final converter = CurrencyConverterPro();
    final results = await converter.convertMany(
      amount: 100,
      fromCurrency: "USD",
      toCurrencies: ["INR", "EUR", "GBP", "JPY"],
    );
       
    print(results['INR']); // 8330.0
    print(results['EUR']); // 92.5
    
  9. Live Exchange Rate Stream (New ⭐) For financial dashboards or trading apps, you can listen to a real-time stream of exchange rates.

    final converter = CurrencyConverterPro();
    final stream = converter.rateStream(
      fromCurrency: "USD",
      toCurrency: "INR",
      interval: Duration(minutes: 5),
    );
    
    stream.listen((rate) {
      print("Current Rate: $rate");
    });
    
  10. Rich Conversion Result (New ⭐) Instead of just a number, you now get a ConversionResult object with metadata.

    final result = await converter.convertCurrency(
      amount: 100,
      fromCurrency: "USD",
      toCurrency: "INR",
    );
    
    print(result.convertedAmount); // 8330.0
    print(result.rate);            // 83.3
    print(result.provider);        // FrankfurterProvider
    print(result.timestamp);       // 2024-05-21 10:00:00
    print(result.isCached);        // false
    
  11. Currency Formatter (New ⭐) Format currency amounts correctly for different regions.

    // Standard Formatting
    String formatted = CurrencyFormatter.format(
      amount: 1234567.89,
      currency: "INR",
    ); // ₹12,34,567.89
    
    // Accounting Format
    String accounting = CurrencyFormatter.formatAccounting(
      amount: -1234.56,
      currency: "USD",
    ); // ($1,234.56)
    
    // Conveniently from a result
    final result = await converter.convertCurrency(amount: 50, fromCurrency: "USD", toCurrency: "EUR");
    print(result.formattedAmount); // €46.50
    
  12. Currency Picker Widget (New ⭐) A ready-made Flutter widget to select currencies with flags, search, and favorites.

    // Show the picker
    CurrencyPickerWidget.show(
      context: context,
      showFlag: true,
      showSearchField: true,
      favorite: ['USD', 'INR', 'EUR'],
      onSelect: (Currency currency) {
        print('Selected currency: ${currency.name} (${currency.code})');
      },
    );
    
  13. Better Error Handling (New ⭐) The package provides typed exceptions to help you handle errors gracefully.

    try {
      final result = await converter.convertCurrency(
        amount: 100,
        fromCurrency: "USD",
        toCurrency: "INVALID",
      );
    } on InvalidCurrencyException catch (e) {
      print("Caught invalid currency: ${e.currencyCode}");
    } on NetworkException catch (e) {
      print("Network error: ${e.message}");
    } on RateLimitException catch (e) {
      print("Rate limit reached: ${e.message}");
    } catch (e) {
      print("Generic error: $e");
    }
    
  14. Exchange Rate API (New ⭐) If you only need the exchange rate without converting a specific amount.

    final rate = await converter.getRate(
      from: "USD",
      to: "INR",
    );
    print("1 USD = $rate INR"); // 1 USD = 83.45 INR
    

Full Code Example #

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:currency_converter_pro/currency_converter_pro.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
   return const MaterialApp(
      home: ConverterTabs(),
   );
}
}

class ConverterTabs extends StatelessWidget {
const ConverterTabs({super.key});

@override
Widget build(BuildContext context) {
   return DefaultTabController(
      length: 2,
      child: Scaffold(
         appBar: AppBar(
            title: const Text('Currency and Crypto Converter'),
            bottom: const TabBar(
               tabs: [
                  Tab(text: 'Currency'),
                  Tab(text: 'Crypto'),
               ],
            ),
         ),
         body: const TabBarView(
            children: [
               CurrencyConverterScreen(),
               CryptoConverterScreen(),
            ],
         ),
      ),
   );
}
}

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

@override
State<CurrencyConverterScreen> createState() =>
        _CurrencyConverterScreenState();
}

class _CurrencyConverterScreenState extends State<CurrencyConverterScreen> {
final TextEditingController _amountController = TextEditingController();
String _convertedAmount = '';
String _fromCurrency = 'usd';
String _toCurrency = 'inr';
final List<String> _currencies = [
   'usd',
   'inr',
   'eur',
   'gbp',
   'jpy',
   'aud',
   'cad'
];

Future<void> _convertCurrency() async {
   final double amount = double.tryParse(_amountController.text) ?? 0;
   try {
      final _currencyConverterProPlugin = CurrencyConverterPro();
      final result = await _currencyConverterProPlugin.convertCurrency(
         amount: amount,
         fromCurrency: _fromCurrency,
         toCurrency: _toCurrency,
      );
      setState(() {
         _convertedAmount = result.toStringAsFixed(2);
      });
   } catch (e) {
      setState(() {
         _convertedAmount = 'Error: $e';
      });
   }
}

@override
Widget build(BuildContext context) {
   return Container(
      padding: const EdgeInsets.all(16.0),
      child: Column(
         crossAxisAlignment: CrossAxisAlignment.stretch,
         children: [
            const Text(
               'Currency Converter',
               style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.blue,
               ),
               textAlign: TextAlign.center,
            ),
            const SizedBox(height: 20),
            Row(
               children: [
                  Expanded(
                     child: DropdownButtonFormField<String>(
                        value: _fromCurrency,
                        items: _currencies.map((String currency) {
                           return DropdownMenuItem<String>(
                              value: currency,
                              child: Text(currency.toUpperCase()),
                           );
                        }).toList(),
                        onChanged: (value) {
                           setState(() {
                              _fromCurrency = value ?? 'usd';
                           });
                        },
                        decoration: const InputDecoration(
                           labelText: 'From Currency',
                           border: OutlineInputBorder(),
                        ),
                     ),
                  ),
                  const SizedBox(width: 10),
                  const Icon(Icons.swap_horiz, size: 30, color: Colors.blue),
                  const SizedBox(width: 10),
                  Expanded(
                     child: DropdownButtonFormField<String>(
                        value: _toCurrency,
                        items: _currencies.map((String currency) {
                           return DropdownMenuItem<String>(
                              value: currency,
                              child: Text(currency.toUpperCase()),
                           );
                        }).toList(),
                        onChanged: (value) {
                           setState(() {
                              _toCurrency = value ?? 'inr';
                           });
                        },
                        decoration: const InputDecoration(
                           labelText: 'To Currency',
                           border: OutlineInputBorder(),
                        ),
                     ),
                  ),
               ],
            ),
            const SizedBox(height: 20),
            TextField(
               controller: _amountController,
               keyboardType: TextInputType.number,
               decoration: const InputDecoration(
                  labelText: 'Enter Amount',
                  border: OutlineInputBorder(),
                  prefixIcon: Icon(Icons.confirmation_number, color: Colors.blue),
               ),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
               onPressed: _convertCurrency,
               style: ElevatedButton.styleFrom(
                  backgroundColor: Colors.blue,
                  padding: const EdgeInsets.symmetric(vertical: 16.0),
               ),
               child: const Text(
                  'Convert Currency',
                  style: TextStyle(fontSize: 18, color: Colors.white),
               ),
            ),
            const SizedBox(height: 20),
            Text(
               _convertedAmount.isEmpty
                       ? 'Converted Amount will appear here'
                       : 'Converted Amount: $_convertedAmount $_toCurrency',
               style: const TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  color: Colors.blue,
               ),
               textAlign: TextAlign.center,
            ),
         ],
      ),
   );
}
}

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

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

class _CryptoConverterScreenState extends State<CryptoConverterScreen> {
final _currencyConverterProPlugin = CurrencyConverterPro();
double amount = 1.0;
double convertedAmount = 0.0;
String fromCrypto = 'bitcoin';
String toCrypto = 'ethereum';

final List<String> cryptoList = [
   'bitcoin',
   'ethereum',
   'litecoin',
   'ripple',
   'cardano',
   'dogecoin',
];

Future<void> convert() async {
   convertedAmount = await _currencyConverterProPlugin.convertCrypto(
           fromCrypto, toCrypto, amount);
   setState(() {});
}

@override
Widget build(BuildContext context) {
   return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
         children: [
            const Text(
               'Crypto Currency Converter',
               style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.blue,
               ),
               textAlign: TextAlign.center,
            ),
            const SizedBox(height: 20),
            Row(
               children: [
                  Expanded(
                     child: DropdownButtonFormField<String>(
                        value: fromCrypto,
                        items: cryptoList.map((String crypto) {
                           return DropdownMenuItem<String>(
                              value: crypto,
                              child: Text(crypto.toUpperCase()),
                           );
                        }).toList(),
                        onChanged: (value) {
                           setState(() {
                              fromCrypto = value ?? 'bitcoin';
                           });
                        },
                        decoration: const InputDecoration(
                           labelText: 'From Crypto',
                           border: OutlineInputBorder(),
                        ),
                     ),
                  ),
                  const SizedBox(width: 10),
                  const Icon(Icons.swap_horiz, size: 30, color: Colors.blue),
                  const SizedBox(width: 10),
                  Expanded(
                     child: DropdownButtonFormField<String>(
                        value: toCrypto,
                        items: cryptoList.map((String crypto) {
                           return DropdownMenuItem<String>(
                              value: crypto,
                              child: Text(crypto.toUpperCase()),
                           );
                        }).toList(),
                        onChanged: (value) {
                           setState(() {
                              toCrypto = value ?? 'ethereum';
                           });
                        },
                        decoration: const InputDecoration(
                           labelText: 'To Crypto',
                           border: OutlineInputBorder(),
                        ),
                     ),
                  ),
               ],
            ),
            const SizedBox(height: 20),
            TextField(
               decoration: const InputDecoration(
                  labelText: 'Enter Amount',
                  border: OutlineInputBorder(),
                  prefixIcon: Icon(Icons.confirmation_number, color: Colors.blue),
               ),
               keyboardType: TextInputType.number,
               onChanged: (value) {
                  amount = double.tryParse(value) ?? 0.0;
               },
            ),
            const SizedBox(height: 20),
            SizedBox(
               width: MediaQuery.of(context).size.width,
               child: ElevatedButton(
                  onPressed: convert,
                  style: ElevatedButton.styleFrom(
                     backgroundColor: Colors.blue,
                     padding: const EdgeInsets.symmetric(vertical: 16.0),
                  ),
                  child: const Text(
                     'Cypto Convert Currency',
                     style: TextStyle(fontSize: 18, color: Colors.white),
                  ),
               ),
            ),
            const SizedBox(height: 20),
            Text('Equivalent: ${convertedAmount.toStringAsFixed(6)} $toCrypto'),
         ],
      ),
   );
}
}


How Example Works #

  1. Currency and Crypto Currency Dropdown: Users can select the source and target currencies using dropdown menus.
  2. Amount Input: Users can enter the amount to be converted.
  3. Convert Button: Upon clicking "Convert Currency," the app fetches the exchange rate and displays the converted amount.

Supported Currencies and crypto Currencies #

The app supports popular currencies including:

  • USD (US Dollar)
  • INR (Indian Rupee)
  • EUR (Euro)
  • GBP (British Pound)
  • JPY (Japanese Yen)
  • AUD (Australian Dollar)
  • CAD (Canadian Dollar)
  • CHF (Swiss Franc)
  • CNY (Chinese Yuan)
  • NZD (New Zealand Dollar)
  • SGD (Singapore Dollar)
  • HKD (Hong Kong Dollar)
  • NOK (Norwegian Krone)
  • SEK (Swedish Krona)
  • MXN (Mexican Peso)
  • RUB (Russian Ruble)
  • ZAR (South African Rand)
  • BRL (Brazilian Real)
  • DKK (Danish Krone)
  • PLN (Polish Zloty)
  • THB (Thai Baht) And more...

The app also supports popular cryptocurrencies including:

  • BTC (Bitcoin)
  • ETH (Ethereum)
  • XRP (Ripple)
  • LTC (Litecoin)
  • BCH (Bitcoin Cash)
  • ADA (Cardano)
  • DOT (Polkadot)
  • SOL (Solana)
  • DOGE (Dogecoin)
  • USDT (Tether)
  • LINK (Chainlink)
  • BNB (Binance Coin)
  • XLM (Stellar) And more...

Contributions #

Contributions to Currency Converter Pro are welcome! Feel free to submit issues or pull requests to enhance the package.


License #

The MIT License (MIT) Copyright (c) 2024 Shirsh Shukla

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


10
likes
120
points
294
downloads

Documentation

API reference

Publisher

verified publishershirsh.dev

Weekly Downloads

Professional Currency and Crypto Converter for Flutter. Supports multi-providers, offline cache, historical rates, batch conversion, and real-time streams.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, http, intl, plugin_platform_interface, shared_preferences

More

Packages that depend on currency_converter_pro

Packages that implement currency_converter_pro