A Flutter Package to Select A Currency From A List Of Currencies

Currency picker

A flutter package to select a currency from a list of currencies.

n1

Getting Started

Add the package to your pubspec.yaml:

currency_picker: ^2.0.15

In your dart file, import the library:

import 'package:currency_picker/currency_picker.dart';

Show currency picker using showCurrencyPicker:

showCurrencyPicker(
   context: context,
   showFlag: true,
   showCurrencyName: true,
   showCurrencyCode: true,
   onSelect: (Currency currency) {
      print('Select currency: ${currency.name}');
   },
);

Parameters:

  • onSelect: Called when a currency is select. The currency picker passes the new value to the callback (required)
  • showFlag: Shows flag for each currency. Default value true (optional).
  • searchHint: Option to customize hint of the search TextField (optional).
  • showCurrencyName: Option to show/hide the currency name, default value true (optional).
  • showCurrencyCode: Option to show/hide the currency code, default value true (optional).
  • showSearchField: Option to show/hide the search TextField, default value true (optional).
  • currencyFilter: Can be used to filter the Currency list (optional).
 showCurrencyPicker(
    context: context,
    onSelect: (Currency currency) {
       print('Select currency: ${currency.name}');
    },
    currencyFilter: <String>['EUR', 'GBP', 'USD', 'AUD', 'CAD', 'JPY', 'HKD', 'CHF', 'SEK', 'ILS'],
 );
  • favorite: Can be used to show the favorite currencies at the top of the list (optional).
  • theme: Can be used to customizing the currency list bottom sheet. (optional).
 showCurrencyPicker(
    context: context,
    theme: CurrencyPickerThemeData(
       flagSize: 25,
       titleTextStyle: TextStyle(fontSize: 17),
       subtitleTextStyle: TextStyle(fontSize: 15, color: Theme.of(context).hintColor),
       bottomSheetHeight: MediaQuery.of(context).size.height / 2,
    ),
    onSelect: (Currency currency) => print('Select currency: ${currency.name}'),
 );

Contributions

Contributions of any kind are more than welcome! Feel free to fork and improve currency_picker in any way you want, make a pull request, or open an issue.

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add currency_picker

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  currency_picker: ^2.0.16

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:currency_picker/currency_picker.dart';

example/lib/main.dart

import 'package:currency_picker/currency_picker.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo for currency picker package',
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Demo for currency picker')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showCurrencyPicker(
              context: context,
              showFlag: true,
              showSearchField: true,
              showCurrencyName: true,
              showCurrencyCode: true,
              onSelect: (Currency currency) {
                print('Select currency: ${currency.name}');
              },
              favorite: ['SEK'],
            );
          },
          child: const Text('Show currency picker'),
        ),
      ),
    );
  }
}

Download details:

Author: Daniel-Ioannou

Source: https://github.com/Daniel-Ioannou/flutter_currency_picker

#flutter #android #web-development #web #ios #Picker 

A Flutter Package to Select A Currency From A List Of Currencies
3.95 GEEK