Giter Club home page Giter Club logo

digit_currency_converter's Introduction

Digit Currency Converter

The digit_currency_converter package is a powerful tool for handling currency conversions, retrieving real-time exchange rates, and obtaining device-specific locale information in Flutter applications. This package offers robust API integration and is designed to be flexible, catering to both direct API usage and managed state via provider pattern within the Flutter framework.

Features

  • Direct Currency Conversion: Convert amounts directly from one currency to another using up-to-date exchange rates.
  • Device Locale Information: Automatically fetch the currency and country based on the device's IP address.
  • Exchange Rate Retrieval: Get the latest exchange rates between two specified currencies.
  • Provider State Management: Utilize a provider to manage and reactively update UI components based on currency-related data changes.

Installation

Add the digit_currency_converter to your project's pubspec.yaml file:

dependencies:
  digit_currency_converter:
    git: 
      url: https://github.com/Corneille9/digit_currency_converter
      ref: main

Usage

Setup

First, set up the DigitCurrencyConverter with your API credentials:

import 'package:digit_currency_converter/digit_currency_converter.dart';

const credentials = Credentials(username: "YOUR_USERNAME", password: "YOUR_PASSWORD");
final converter = DigitCurrencyConverter(credentials: credentials);

Performing Currency Conversions

Convert an amount from one currency to another:

final result = await converter.convert(from: Currency.xof, to: Currency.eur, amount: 50000);

Retrieving Device Currency and Country

Get the device's current currency and country based on IP:

final deviceCurrency = await DigitCurrencyConverter.deviceCurrency();
final deviceCountry = await DigitCurrencyConverter.deviceCountry();

Fetching Exchange Rates

Retrieve the current exchange rate between two currencies:

final rate = await converter.rate(from: Currency.xof, to: Currency.eur);

Converting with Specific or Device Country/Currency

Convert amounts using a specific country's currency or directly using the device's detected values:

final resultWithCountry = await converter.convertWithCountry(countryCode: "BJ", from: Currency.usd, amount: 100);
final resultWithDeviceCountry = await converter.convertWithDeviceCountry(from: Currency.usd, amount: 100);
final resultWithDeviceCurrency = await converter.convertWithDeviceCurrency(from: Currency.usd, amount: 100);

Using DigitCurrencyProvider

For applications needing reactive state management:

ChangeNotifierProvider(
  create: (_) => DigitCurrencyProvider(
    credentials: credentials,
    from: Currency.xof,
    to: Currency.eur, // Optional
    useDeviceCurrency: false, // Set to true to use the device's currency
  ),
  child: Consumer<DigitCurrencyProvider>(
    builder: (context, provider, child) {
      if (provider.hasError) {
        return Text('Failed to load data');
      }
      if (!provider.initialized) {
        return CircularProgressIndicator();
      }
      return Text('Rate: ${provider.rate}');
    },
  ),
);

Contributing

We welcome contributions to enhance the digit_currency_converter package. Please read the contributing guidelines for more information on how to submit pull requests, report issues, or make feature requests.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

digit_currency_converter's People

Contributors

corneille9 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.