currency_converter 2.0.0 copy "currency_converter: ^2.0.0" to clipboard
currency_converter: ^2.0.0 copied to clipboard

Live Currency converter in flutter

example/lib/main.dart

import 'package:currency_converter/currency.dart';
import 'package:currency_converter/currency_converter.dart';
import 'package:flutter/material.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  //def variable
  String? usdToInr;

  @override
  void initState() {
    super.initState();
// add in initState
    convert();
  }

// call function to convert
  void convert() async {
    Currency myCurrency = await CurrencyConverter.getMyCurrency();
    var usdConvert = await CurrencyConverter.convert(
      from: Currency.usd,
      to: myCurrency,
      amount: 1,
      withoutRounding: true,
    );
    setState(() {
      usdToInr = usdConvert.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Money Convertor Example'),
          centerTitle: true,
        ),
        body: Container(
          padding: const EdgeInsets.all(20),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                "1 USD = ",
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
              ),
              const SizedBox(
                width: 10,
              ),
              Expanded(
                child: Text(
                  "$usdToInr ${Currency.inr.name.toUpperCase()}",
                  style: const TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 22,
                    color: Colors.green,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
17
likes
110
pub points
88%
popularity

Publisher

unverified uploader

Live Currency converter in flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, http, intl

More

Packages that depend on currency_converter