Currency Converter Pro: Simplifying Currency Conversions for Flutter Developers

A powerful and easy-to-use Flutter package to handle real-time currency conversions effortlessly in your apps.

Shirsh Shukla
5 min readDec 20, 2024

Hello and welcome, Flutter enthusiasts! Are you building an app that needs to handle currency conversions? Look no further! Introducing Currency_Converter_Pro, a powerful yet simple-to-use package designed specifically for Flutter developers. Whether you’re crafting a global e-commerce app or a travel budget planner, this package takes the pain out of currency conversion and makes your development process smoother.

Why Currency Converter Pro is a Game-Changer

Handling currency conversions manually is not only time-consuming but also prone to errors. You’d need to fetch exchange rates, write complex logic to process them, and then worry about maintaining everything as rates change daily. With Currency Converter Pro, all of that is handled for you. Here’s why it stands out:

  1. Designed for Flutter Developers: We’ve crafted this package with Flutter’s simplicity and versatility in mind. No unnecessary complications — just a tool that works seamlessly.
  2. Accurate Conversions: Get real-time, reliable exchange rates so your users always see the correct numbers.
  3. Ease of Integration: Minimal setup and intuitive APIs make it easy to implement, even if you’re a beginner.
  4. Free and Open-Source: No hidden costs. It’s available for everyone, and contributions from developers like you can make it even better!

Installation Guide

Adding Currency Converter Pro to your Flutter project is super simple. Start by including it in your pubspec.yaml file:

dependencies:
currency_converter_pro: ^latest_version

Run the command below to fetch the package:

flutter pub get

And you’re all set to start using the magic of Currency Converter Pro.

How to Get Started

Let’s dive into some code examples to see how Currency Converter Pro can make your life easier. The first step is to import the package into your Dart file:

import 'package:currency_converter_pro/currency_converter_pro.dart';

Example: Simple Conversion

Here’s a basic example where we convert 100 USD to EUR:

void convertCurrency() async {
final converter = CurrencyConverter();
double amountInUSD = 100.0;
  try {
double amountInEUR = await converter.convert(
from: 'USD',
to: 'EUR',
amount: amountInUSD,
);
print('Converted Amount: €$amountInEUR');
} catch (e) {
print('Error: $e');
}
}

When you run this function, it fetches the latest exchange rate and calculates the equivalent value in euros. Isn’t that cool?

Example: Dropdown Integration for User Input

If you’re building a UI where users select currencies, here’s a quick example:

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

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

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

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
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);
print("Converted Amount $_convertedAmount");
});
} catch (e) {
setState(() {
_convertedAmount = 'Error: \$e';
});
}
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Currency Converter'),
backgroundColor: Colors.blue,
),
body: 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,
),
],
),
),
),
);
}
}

This example provides a user-friendly interface for selecting currencies and entering amounts. When users click the “Convert” button, they instantly see the converted amount.

Advanced Features

Batch Conversions

Imagine needing to convert multiple amounts at once. You can extend this package to perform batch conversions:

void convertBatch() async {
final converter = CurrencyConverter();
Map<String, double> results = {};
  List<Map<String, dynamic>> conversions = [
{'from': 'USD', 'to': 'EUR', 'amount': 100.0},
{'from': 'USD', 'to': 'INR', 'amount': 100.0},
];
for (var item in conversions) {
try {
double result = await converter.convert(
from: item['from'],
to: item['to'],
amount: item['amount'],
);
results['${item['from']} to ${item['to']}'] = result;
} catch (e) {
print('Error converting ${item['from']} to ${item['to']}: $e');
}
}
results.forEach((key, value) {
print('$key: $value');
});
}

This approach processes multiple conversions efficiently, saving time for larger apps.

Future Plans

Currency Converter Pro is evolving. Upcoming features include:

  • Offline Mode: Store exchange rates locally for offline access.
  • Historical Data: Allow users to view trends in exchange rates.
  • Cryptocurrency Support: Enable conversions with Bitcoin, Ethereum, and more.

Final Words

Currency Converter Pro is a handy tool for Flutter developers looking to add robust currency conversion features to their apps. It’s simple, flexible, and backed by a community of developers. Start using it today, and let your app handle currency conversions like a pro!

Don’t forget to check out the documentation for more details and examples. Happy coding!

If you got something wrong? Mention it in the comments. I would love to improve. your support means a lot to me! If you enjoy the content, I’d be grateful if you could consider subscribing to my YouTube channel as well.

I am Shirsh Shukla, a creative Developer, and a Technology lover. You can find me on LinkedIn or maybe follow me on Twitter or just walk over my portfolio for more details. And of course, you can follow me on GitHub as well.

Have a nice day!🙂

https://drive.google.com/file/d/1hdC-E7Kf97NM3YzWKvpm5olb89kNrIcs/view

--

--

Shirsh Shukla
Shirsh Shukla

Written by Shirsh Shukla

SDE at Reliance Jio | Mobile Application Developer | Speaker | Technical Writer | community member at Stack Overflow | Organizer @FlutterIndore

No responses yet