currency_kit_flutter 0.0.2
currency_kit_flutter: ^0.0.2 copied to clipboard
Flutter widgets for currency_kit — a currency picker, an exchange-rate editor, a switch button and money text, all built on display-only conversion.
example/main.dart
import 'package:currency_kit_flutter/currency_kit_flutter.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ExampleApp());
/// Shows a stored AED amount read through a chosen currency.
class ExampleApp extends StatefulWidget {
/// Const constructor.
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
/// The books are kept in AED. This value never changes below.
static const _stored = Money(36.70, CurrencyCode.aed);
static final _usdToAed = ExchangeRate(
base: CurrencyCode.usd,
quote: CurrencyCode.aed,
rate: 3.67,
);
CurrencyCode _displayed = CurrencyCode.aed;
ExchangeRate get _rate => _displayed == CurrencyCode.usd
? _usdToAed
: const ExchangeRate.identity(CurrencyCode.aed);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// AED 36.70, then USD 10.00 — the same stored amount.
MoneyText(
_stored,
rate: _rate,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 16),
CurrencySwitchButton(
selected: _displayed,
rate: _rate,
options: [
const CurrencyOption(code: CurrencyCode.aed),
CurrencyOption(code: CurrencyCode.usd, rate: _usdToAed),
],
onChanged: (option) => setState(() => _displayed = option.code),
),
const SizedBox(height: 8),
Text('stored: ${_stored.format()}'),
],
),
),
),
);
}
}