mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2025-12-10 03:05:34 +00:00
Ability to cache currency selection
This commit is contained in:
@@ -19,7 +19,7 @@ abstract class BaseStatelessWidget<T extends BaseViewmodel>
|
|||||||
Widget build(BuildContext parent) {
|
Widget build(BuildContext parent) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Container(
|
body: Container(
|
||||||
padding: const EdgeInsets.all(PADDING_GLOBAL),
|
padding: const EdgeInsets.all(paddingGlobal),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/src/widgets/framework.dart';
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
|
|
||||||
import 'BaseStatelessWidget.dart';
|
import 'BaseStatelessWidget.dart';
|
||||||
|
import 'Utils/Constants.dart';
|
||||||
|
|
||||||
class HomePage extends BaseStatelessWidget<MainViewModel> {
|
class HomePage extends BaseStatelessWidget<MainViewModel> {
|
||||||
@override
|
@override
|
||||||
@@ -15,11 +16,13 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget displayWidget(
|
Widget displayWidget(BuildContext context, MainViewModel model, Widget? child) {
|
||||||
BuildContext context, MainViewModel model, Widget? child) {
|
|
||||||
TextEditingController controller1 = TextEditingController();
|
TextEditingController controller1 = TextEditingController();
|
||||||
TextEditingController controller2 = TextEditingController();
|
TextEditingController controller2 = TextEditingController();
|
||||||
|
|
||||||
|
String selected1 = model.getConversionPair(SelectionType.conversionFrom);
|
||||||
|
String selected2 = model.getConversionPair(SelectionType.conversionTo);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@@ -27,7 +30,10 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DropDownBox(model.data, (selected) {}),
|
DropDownBox(listOfCurrencies, selected1, (selected) {
|
||||||
|
selected1 = selected!;
|
||||||
|
model.setConversionPair(selected1, selected2);
|
||||||
|
}),
|
||||||
ConverterEditText("Enter conversion from", controller1, (input) => {
|
ConverterEditText("Enter conversion from", controller1, (input) => {
|
||||||
controller2.text = model.convertInput(input, SelectionType.conversionFrom)
|
controller2.text = model.convertInput(input, SelectionType.conversionFrom)
|
||||||
})
|
})
|
||||||
@@ -38,7 +44,10 @@ class HomePage extends BaseStatelessWidget<MainViewModel> {
|
|||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DropDownBox(model.data, (selected) {}),
|
DropDownBox(listOfCurrencies, selected2, (selected) {
|
||||||
|
selected2 = selected!;
|
||||||
|
model.setConversionPair(selected1, selected2);
|
||||||
|
}),
|
||||||
ConverterEditText("Enter conversion from", controller2, (input) => {
|
ConverterEditText("Enter conversion from", controller2, (input) => {
|
||||||
controller1.text = model.convertInput(input, SelectionType.conversionTo)
|
controller1.text = model.convertInput(input, SelectionType.conversionTo)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,165 +1,33 @@
|
|||||||
import 'package:easy_cc_flutter/BaseViewModel.dart';
|
import 'package:easy_cc_flutter/BaseViewModel.dart';
|
||||||
import 'package:easy_cc_flutter/Utils/SelectionType.dart';
|
import 'package:easy_cc_flutter/Utils/SelectionType.dart';
|
||||||
|
|
||||||
|
import 'Utils/Constants.dart';
|
||||||
|
import 'data/prefs/CurrencyPair.dart';
|
||||||
|
import 'data/repository/Repository.dart';
|
||||||
|
import 'data/repository/RepositoryImpl.dart';
|
||||||
|
import 'locator.dart';
|
||||||
|
|
||||||
class MainViewModel extends BaseViewmodel {
|
class MainViewModel extends BaseViewmodel {
|
||||||
|
final Repository _repository = locator<RepositoryImpl>();
|
||||||
|
|
||||||
double conversionRate = 1.4;
|
double conversionRate = 1.4;
|
||||||
|
|
||||||
final List<String> data = <String>['ALL - Albanian Lek',
|
String getConversionPair(SelectionType type) {
|
||||||
'AFN - Afghan Afghani',
|
CurrencyPair pair = _repository.getConversionPair();
|
||||||
'DZD - Algerian Dinar',
|
|
||||||
'AOA - Angolan Kwanza',
|
switch (type) {
|
||||||
'ARS - Argentine Peso',
|
case SelectionType.conversionFrom:
|
||||||
'AMD - Armenian Dram',
|
return pair.currencyOne != null ? pair.currencyOne! : listOfCurrencies[0];
|
||||||
'AWG - Aruban Florin',
|
case SelectionType.conversionTo:
|
||||||
'AUD - Australian Dollar',
|
return pair.currencyTwo != null ? pair.currencyTwo! : listOfCurrencies[0];
|
||||||
'AZN - Azerbaijani Manat',
|
default:
|
||||||
'BSD - Bahamian Dollar',
|
throw NullThrownError();
|
||||||
'BHD - Bahraini Dinar',
|
}
|
||||||
'BDT - Bangladeshi Taka',
|
}
|
||||||
'BBD - Barbadian Dollar',
|
|
||||||
'BYR - Belarusian Ruble',
|
void setConversionPair(String fromCurrency, String toCurrency) {
|
||||||
'BZD - Belize Dollar',
|
_repository.setConversionPair(fromCurrency, toCurrency);
|
||||||
'BTN - Bhutanese Ngultrum',
|
}
|
||||||
'BTC - Bitcoin',
|
|
||||||
'BOB - Bolivian Boliviano',
|
|
||||||
'BAM - Bosnia And Herzegovina Konvertibilna Marka',
|
|
||||||
'BWP - Botswana Pula',
|
|
||||||
'BRL - Brazilian Real',
|
|
||||||
'GBP - British Pound',
|
|
||||||
'BND - Brunei Dollar',
|
|
||||||
'BGN - Bulgarian Lev',
|
|
||||||
'BIF - Burundi Franc',
|
|
||||||
'KHR - Cambodian Riel',
|
|
||||||
'CAD - Canadian Dollar',
|
|
||||||
'CVE - Cape Verdean Escudo',
|
|
||||||
'KYD - Cayman Islands Dollar',
|
|
||||||
'XAF - Central African CFA Franc',
|
|
||||||
'XPF - CFP Franc',
|
|
||||||
'CLP - Chilean Peso',
|
|
||||||
'CNY - Chinese Yuan',
|
|
||||||
'COP - Colombian Peso',
|
|
||||||
'KMF - Comorian Franc',
|
|
||||||
'CDF - Congolese Franc',
|
|
||||||
'CRC - Costa Rican Colon',
|
|
||||||
'HRK - Croatian Kuna',
|
|
||||||
'CUP - Cuban Peso',
|
|
||||||
'CZK - Czech Koruna',
|
|
||||||
'DKK - Danish Krone',
|
|
||||||
'DJF - Djiboutian Franc',
|
|
||||||
'DOP - Dominican Peso',
|
|
||||||
'XCD - East Caribbean Dollar',
|
|
||||||
'EGP - Egyptian Pound',
|
|
||||||
'ERN - Eritrean Nakfa',
|
|
||||||
'ETB - Ethiopian Birr',
|
|
||||||
'EUR - Euro',
|
|
||||||
'FKP - Falkland Islands Pound',
|
|
||||||
'FJD - Fijian Dollar',
|
|
||||||
'GMD - Gambian Dalasi',
|
|
||||||
'GEL - Georgian Lari',
|
|
||||||
'GHS - Ghanaian Cedi',
|
|
||||||
'GIP - Gibraltar Pound',
|
|
||||||
'GTQ - Guatemalan Quetzal',
|
|
||||||
'GNF - Guinean Franc',
|
|
||||||
'GYD - Guyanese Dollar',
|
|
||||||
'HTG - Haitian Gourde',
|
|
||||||
'HNL - Honduran Lempira',
|
|
||||||
'HKD - Hong Kong Dollar',
|
|
||||||
'HUF - Hungarian Forint',
|
|
||||||
'ISK - Icelandic Kr\u00f3na',
|
|
||||||
'INR - Indian Rupee',
|
|
||||||
'IDR - Indonesian Rupiah',
|
|
||||||
'IRR - Iranian Rial',
|
|
||||||
'IQD - Iraqi Dinar',
|
|
||||||
'ILS - Israeli New Sheqel',
|
|
||||||
'JMD - Jamaican Dollar',
|
|
||||||
'JPY - Japanese Yen',
|
|
||||||
'JOD - Jordanian Dinar',
|
|
||||||
'KZT - Kazakhstani Tenge',
|
|
||||||
'KES - Kenyan Shilling',
|
|
||||||
'KWD - Kuwaiti Dinar',
|
|
||||||
'KGS - Kyrgyzstani Som',
|
|
||||||
'LAK - Lao Kip',
|
|
||||||
'LVL - Latvian Lats',
|
|
||||||
'LBP - Lebanese Lira',
|
|
||||||
'LSL - Lesotho Loti',
|
|
||||||
'LRD - Liberian Dollar',
|
|
||||||
'LYD - Libyan Dinar',
|
|
||||||
'MOP - Macanese Pataca',
|
|
||||||
'MKD - Macedonian Denar',
|
|
||||||
'MGA - Malagasy Ariary',
|
|
||||||
'MWK - Malawian Kwacha',
|
|
||||||
'MYR - Malaysian Ringgit',
|
|
||||||
'MVR - Maldivian Rufiyaa',
|
|
||||||
'MRO - Mauritanian Ouguiya',
|
|
||||||
'MUR - Mauritian Rupee',
|
|
||||||
'MXN - Mexican Peso',
|
|
||||||
'MDL - Moldovan Leu',
|
|
||||||
'MNT - Mongolian Tugrik',
|
|
||||||
'MAD - Moroccan Dirham',
|
|
||||||
'MZN - Mozambican Metical',
|
|
||||||
'MMK - Myanma Kyat',
|
|
||||||
'NAD - Namibian Dollar',
|
|
||||||
'NPR - Nepalese Rupee',
|
|
||||||
'ANG - Netherlands Antillean Gulden',
|
|
||||||
'TWD - New Taiwan Dollar',
|
|
||||||
'NZD - New Zealand Dollar',
|
|
||||||
'NIO - Nicaraguan Cordoba',
|
|
||||||
'NGN - Nigerian Naira',
|
|
||||||
'KPW - North Korean Won',
|
|
||||||
'NOK - Norwegian Krone',
|
|
||||||
'OMR - Omani Rial',
|
|
||||||
'TOP - Paanga',
|
|
||||||
'PKR - Pakistani Rupee',
|
|
||||||
'PAB - Panamanian Balboa',
|
|
||||||
'PGK - Papua New Guinean Kina',
|
|
||||||
'PYG - Paraguayan Guarani',
|
|
||||||
'PEN - Peruvian Nuevo Sol',
|
|
||||||
'PHP - Philippine Peso',
|
|
||||||
'PLN - Polish Zloty',
|
|
||||||
'QAR - Qatari Riyal',
|
|
||||||
'RON - Romanian Leu',
|
|
||||||
'RUB - Russian Ruble',
|
|
||||||
'RWF - Rwandan Franc',
|
|
||||||
'SHP - Saint Helena Pound',
|
|
||||||
'WST - Samoan Tala',
|
|
||||||
'STD - Sao Tome And Principe Dobra',
|
|
||||||
'SAR - Saudi Riyal',
|
|
||||||
'RSD - Serbian Dinar',
|
|
||||||
'SCR - Seychellois Rupee',
|
|
||||||
'SLL - Sierra Leonean Leone',
|
|
||||||
'SGD - Singapore Dollar',
|
|
||||||
'SBD - Solomon Islands Dollar',
|
|
||||||
'SOS - Somali Shilling',
|
|
||||||
'ZAR - South African Rand',
|
|
||||||
'KRW - South Korean Won',
|
|
||||||
'XDR - Special Drawing Rights',
|
|
||||||
'LKR - Sri Lankan Rupee',
|
|
||||||
'SDG - Sudanese Pound',
|
|
||||||
'SRD - Surinamese Dollar',
|
|
||||||
'SZL - Swazi Lilangeni',
|
|
||||||
'SEK - Swedish Krona',
|
|
||||||
'CHF - Swiss Franc',
|
|
||||||
'SYP - Syrian Pound',
|
|
||||||
'TJS - Tajikistani Somoni',
|
|
||||||
'TZS - Tanzanian Shilling',
|
|
||||||
'THB - Thai Baht',
|
|
||||||
'TTD - Trinidad and Tobago Dollar',
|
|
||||||
'TND - Tunisian Dinar',
|
|
||||||
'TRY - Turkish New Lira',
|
|
||||||
'TMT - Turkmenistan Manat',
|
|
||||||
'AED - UAE Dirham',
|
|
||||||
'UGX - Ugandan Shilling',
|
|
||||||
'UAH - Ukrainian Hryvnia',
|
|
||||||
'USD - United States Dollar',
|
|
||||||
'UYU - Uruguayan Peso',
|
|
||||||
'UZS - Uzbekistani Som',
|
|
||||||
'VUV - Vanuatu Vatu',
|
|
||||||
'VEF - Venezuelan Bolivar',
|
|
||||||
'VND - Vietnamese Dong',
|
|
||||||
'XOF - West African CFA Franc',
|
|
||||||
'YER - Yemeni Rial',
|
|
||||||
'ZMW - Zambian Kwacha'];
|
|
||||||
|
|
||||||
String convertInput(String? input, SelectionType type) {
|
String convertInput(String? input, SelectionType type) {
|
||||||
if (input == null || input.isEmpty) {
|
if (input == null || input.isEmpty) {
|
||||||
|
|||||||
@@ -6,4 +6,162 @@ const Color colourThree = Color(0xFF2978A0);
|
|||||||
const Color colourFour = Color(0xFF8549ff);
|
const Color colourFour = Color(0xFF8549ff);
|
||||||
const Color colourFive = Color(0xFFC6E0FF);
|
const Color colourFive = Color(0xFFC6E0FF);
|
||||||
|
|
||||||
const double PADDING_GLOBAL = 12;
|
const double paddingGlobal = 12;
|
||||||
|
|
||||||
|
final List<String> listOfCurrencies = <String>[
|
||||||
|
'ALL - Albanian Lek',
|
||||||
|
'AFN - Afghan Afghani',
|
||||||
|
'DZD - Algerian Dinar',
|
||||||
|
'AOA - Angolan Kwanza',
|
||||||
|
'ARS - Argentine Peso',
|
||||||
|
'AMD - Armenian Dram',
|
||||||
|
'AWG - Aruban Florin',
|
||||||
|
'AUD - Australian Dollar',
|
||||||
|
'AZN - Azerbaijani Manat',
|
||||||
|
'BSD - Bahamian Dollar',
|
||||||
|
'BHD - Bahraini Dinar',
|
||||||
|
'BDT - Bangladeshi Taka',
|
||||||
|
'BBD - Barbadian Dollar',
|
||||||
|
'BYR - Belarusian Ruble',
|
||||||
|
'BZD - Belize Dollar',
|
||||||
|
'BTN - Bhutanese Ngultrum',
|
||||||
|
'BTC - Bitcoin',
|
||||||
|
'BOB - Bolivian Boliviano',
|
||||||
|
'BAM - Bosnia And Herzegovina Konvertibilna Marka',
|
||||||
|
'BWP - Botswana Pula',
|
||||||
|
'BRL - Brazilian Real',
|
||||||
|
'GBP - British Pound',
|
||||||
|
'BND - Brunei Dollar',
|
||||||
|
'BGN - Bulgarian Lev',
|
||||||
|
'BIF - Burundi Franc',
|
||||||
|
'KHR - Cambodian Riel',
|
||||||
|
'CAD - Canadian Dollar',
|
||||||
|
'CVE - Cape Verdean Escudo',
|
||||||
|
'KYD - Cayman Islands Dollar',
|
||||||
|
'XAF - Central African CFA Franc',
|
||||||
|
'XPF - CFP Franc',
|
||||||
|
'CLP - Chilean Peso',
|
||||||
|
'CNY - Chinese Yuan',
|
||||||
|
'COP - Colombian Peso',
|
||||||
|
'KMF - Comorian Franc',
|
||||||
|
'CDF - Congolese Franc',
|
||||||
|
'CRC - Costa Rican Colon',
|
||||||
|
'HRK - Croatian Kuna',
|
||||||
|
'CUP - Cuban Peso',
|
||||||
|
'CZK - Czech Koruna',
|
||||||
|
'DKK - Danish Krone',
|
||||||
|
'DJF - Djiboutian Franc',
|
||||||
|
'DOP - Dominican Peso',
|
||||||
|
'XCD - East Caribbean Dollar',
|
||||||
|
'EGP - Egyptian Pound',
|
||||||
|
'ERN - Eritrean Nakfa',
|
||||||
|
'ETB - Ethiopian Birr',
|
||||||
|
'EUR - Euro',
|
||||||
|
'FKP - Falkland Islands Pound',
|
||||||
|
'FJD - Fijian Dollar',
|
||||||
|
'GMD - Gambian Dalasi',
|
||||||
|
'GEL - Georgian Lari',
|
||||||
|
'GHS - Ghanaian Cedi',
|
||||||
|
'GIP - Gibraltar Pound',
|
||||||
|
'GTQ - Guatemalan Quetzal',
|
||||||
|
'GNF - Guinean Franc',
|
||||||
|
'GYD - Guyanese Dollar',
|
||||||
|
'HTG - Haitian Gourde',
|
||||||
|
'HNL - Honduran Lempira',
|
||||||
|
'HKD - Hong Kong Dollar',
|
||||||
|
'HUF - Hungarian Forint',
|
||||||
|
'ISK - Icelandic Kr\u00f3na',
|
||||||
|
'INR - Indian Rupee',
|
||||||
|
'IDR - Indonesian Rupiah',
|
||||||
|
'IRR - Iranian Rial',
|
||||||
|
'IQD - Iraqi Dinar',
|
||||||
|
'ILS - Israeli New Sheqel',
|
||||||
|
'JMD - Jamaican Dollar',
|
||||||
|
'JPY - Japanese Yen',
|
||||||
|
'JOD - Jordanian Dinar',
|
||||||
|
'KZT - Kazakhstani Tenge',
|
||||||
|
'KES - Kenyan Shilling',
|
||||||
|
'KWD - Kuwaiti Dinar',
|
||||||
|
'KGS - Kyrgyzstani Som',
|
||||||
|
'LAK - Lao Kip',
|
||||||
|
'LVL - Latvian Lats',
|
||||||
|
'LBP - Lebanese Lira',
|
||||||
|
'LSL - Lesotho Loti',
|
||||||
|
'LRD - Liberian Dollar',
|
||||||
|
'LYD - Libyan Dinar',
|
||||||
|
'MOP - Macanese Pataca',
|
||||||
|
'MKD - Macedonian Denar',
|
||||||
|
'MGA - Malagasy Ariary',
|
||||||
|
'MWK - Malawian Kwacha',
|
||||||
|
'MYR - Malaysian Ringgit',
|
||||||
|
'MVR - Maldivian Rufiyaa',
|
||||||
|
'MRO - Mauritanian Ouguiya',
|
||||||
|
'MUR - Mauritian Rupee',
|
||||||
|
'MXN - Mexican Peso',
|
||||||
|
'MDL - Moldovan Leu',
|
||||||
|
'MNT - Mongolian Tugrik',
|
||||||
|
'MAD - Moroccan Dirham',
|
||||||
|
'MZN - Mozambican Metical',
|
||||||
|
'MMK - Myanma Kyat',
|
||||||
|
'NAD - Namibian Dollar',
|
||||||
|
'NPR - Nepalese Rupee',
|
||||||
|
'ANG - Netherlands Antillean Gulden',
|
||||||
|
'TWD - New Taiwan Dollar',
|
||||||
|
'NZD - New Zealand Dollar',
|
||||||
|
'NIO - Nicaraguan Cordoba',
|
||||||
|
'NGN - Nigerian Naira',
|
||||||
|
'KPW - North Korean Won',
|
||||||
|
'NOK - Norwegian Krone',
|
||||||
|
'OMR - Omani Rial',
|
||||||
|
'TOP - Paanga',
|
||||||
|
'PKR - Pakistani Rupee',
|
||||||
|
'PAB - Panamanian Balboa',
|
||||||
|
'PGK - Papua New Guinean Kina',
|
||||||
|
'PYG - Paraguayan Guarani',
|
||||||
|
'PEN - Peruvian Nuevo Sol',
|
||||||
|
'PHP - Philippine Peso',
|
||||||
|
'PLN - Polish Zloty',
|
||||||
|
'QAR - Qatari Riyal',
|
||||||
|
'RON - Romanian Leu',
|
||||||
|
'RUB - Russian Ruble',
|
||||||
|
'RWF - Rwandan Franc',
|
||||||
|
'SHP - Saint Helena Pound',
|
||||||
|
'WST - Samoan Tala',
|
||||||
|
'STD - Sao Tome And Principe Dobra',
|
||||||
|
'SAR - Saudi Riyal',
|
||||||
|
'RSD - Serbian Dinar',
|
||||||
|
'SCR - Seychellois Rupee',
|
||||||
|
'SLL - Sierra Leonean Leone',
|
||||||
|
'SGD - Singapore Dollar',
|
||||||
|
'SBD - Solomon Islands Dollar',
|
||||||
|
'SOS - Somali Shilling',
|
||||||
|
'ZAR - South African Rand',
|
||||||
|
'KRW - South Korean Won',
|
||||||
|
'XDR - Special Drawing Rights',
|
||||||
|
'LKR - Sri Lankan Rupee',
|
||||||
|
'SDG - Sudanese Pound',
|
||||||
|
'SRD - Surinamese Dollar',
|
||||||
|
'SZL - Swazi Lilangeni',
|
||||||
|
'SEK - Swedish Krona',
|
||||||
|
'CHF - Swiss Franc',
|
||||||
|
'SYP - Syrian Pound',
|
||||||
|
'TJS - Tajikistani Somoni',
|
||||||
|
'TZS - Tanzanian Shilling',
|
||||||
|
'THB - Thai Baht',
|
||||||
|
'TTD - Trinidad and Tobago Dollar',
|
||||||
|
'TND - Tunisian Dinar',
|
||||||
|
'TRY - Turkish New Lira',
|
||||||
|
'TMT - Turkmenistan Manat',
|
||||||
|
'AED - UAE Dirham',
|
||||||
|
'UGX - Ugandan Shilling',
|
||||||
|
'UAH - Ukrainian Hryvnia',
|
||||||
|
'USD - United States Dollar',
|
||||||
|
'UYU - Uruguayan Peso',
|
||||||
|
'UZS - Uzbekistani Som',
|
||||||
|
'VUV - Vanuatu Vatu',
|
||||||
|
'VEF - Venezuelan Bolivar',
|
||||||
|
'VND - Vietnamese Dong',
|
||||||
|
'XOF - West African CFA Franc',
|
||||||
|
'YER - Yemeni Rial',
|
||||||
|
'ZMW - Zambian Kwacha'
|
||||||
|
];
|
||||||
6
lib/data/prefs/CurrencyPair.dart
Normal file
6
lib/data/prefs/CurrencyPair.dart
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class CurrencyPair {
|
||||||
|
String? currencyOne;
|
||||||
|
String? currencyTwo;
|
||||||
|
|
||||||
|
CurrencyPair(this.currencyOne, this.currencyTwo);
|
||||||
|
}
|
||||||
27
lib/data/prefs/PreferenceProvider.dart
Normal file
27
lib/data/prefs/PreferenceProvider.dart
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'CurrencyPair.dart';
|
||||||
|
|
||||||
|
const String CURRENCY_ONE = "conversion_one";
|
||||||
|
const String CURRENCY_TWO = "conversion_two";
|
||||||
|
class PreferenceProvider {
|
||||||
|
late final SharedPreferences _prefs;
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
_prefs = await SharedPreferences.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveConversionPair(String s1, String s2) async {
|
||||||
|
await _prefs.setString(CURRENCY_ONE, s1);
|
||||||
|
await _prefs.setString(CURRENCY_TWO, s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrencyPair getConversionPair() {
|
||||||
|
String? s1 = _prefs.getString(CURRENCY_ONE);
|
||||||
|
String? s2 = _prefs.getString(CURRENCY_TWO);
|
||||||
|
|
||||||
|
return CurrencyPair(s1, s2);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
lib/data/repository/Repository.dart
Normal file
6
lib/data/repository/Repository.dart
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import '../prefs/CurrencyPair.dart';
|
||||||
|
|
||||||
|
abstract class Repository {
|
||||||
|
CurrencyPair getConversionPair();
|
||||||
|
Future<void> setConversionPair(String fromCurrency, String toCurrency);
|
||||||
|
}
|
||||||
20
lib/data/repository/RepositoryImpl.dart
Normal file
20
lib/data/repository/RepositoryImpl.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:easy_cc_flutter/data/prefs/CurrencyPair.dart';
|
||||||
|
import 'package:easy_cc_flutter/data/prefs/PreferenceProvider.dart';
|
||||||
|
|
||||||
|
import '../../locator.dart';
|
||||||
|
import 'Repository.dart';
|
||||||
|
|
||||||
|
class RepositoryImpl extends Repository {
|
||||||
|
final PreferenceProvider _prefs = locator<PreferenceProvider>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
CurrencyPair getConversionPair() {
|
||||||
|
return _prefs.getConversionPair();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> setConversionPair(String fromCurrency, String toCurrency) {
|
||||||
|
return _prefs.saveConversionPair(fromCurrency, toCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
lib/locator.dart
Normal file
14
lib/locator.dart
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import 'package:easy_cc_flutter/MainViewModel.dart';
|
||||||
|
import 'package:easy_cc_flutter/data/repository/RepositoryImpl.dart';
|
||||||
|
import 'package:get_it/get_it.dart';
|
||||||
|
|
||||||
|
import 'data/prefs/PreferenceProvider.dart';
|
||||||
|
|
||||||
|
GetIt locator = GetIt.instance;
|
||||||
|
|
||||||
|
void setupLocator() {
|
||||||
|
|
||||||
|
locator.registerLazySingleton(() => PreferenceProvider());
|
||||||
|
locator.registerLazySingleton(() => RepositoryImpl());
|
||||||
|
locator.registerFactory(() => MainViewModel());
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'Home.dart';
|
import 'Home.dart';
|
||||||
|
import 'data/prefs/PreferenceProvider.dart';
|
||||||
|
import 'locator.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
setupLocator();
|
||||||
|
await locator<PreferenceProvider>().init();
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import 'package:dropdown_search/dropdown_search.dart';
|
import 'package:dropdown_search/dropdown_search.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../Utils/Constants.dart';
|
import '../Utils/Constants.dart';
|
||||||
|
|
||||||
class DropDownBox extends StatelessWidget {
|
class DropDownBox extends StatelessWidget {
|
||||||
final List<String> _selection;
|
final List<String> _selection;
|
||||||
|
final String _hintText;
|
||||||
final Function(String?) _onChanged;
|
final Function(String?) _onChanged;
|
||||||
|
|
||||||
const DropDownBox(this._selection, this._onChanged, {super.key});
|
const DropDownBox(this._selection, this._hintText, this._onChanged,
|
||||||
|
{super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -18,20 +19,21 @@ class DropDownBox extends StatelessWidget {
|
|||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(22))),
|
borderRadius: BorderRadius.all(Radius.circular(22))),
|
||||||
child: DropdownSearch<String>(
|
child: DropdownSearch<String>(
|
||||||
popupProps: const PopupProps.dialog(showSearchBox: true),
|
popupProps: const PopupProps.dialog(
|
||||||
|
showSearchBox: true,
|
||||||
|
dialogProps: DialogProps(backgroundColor: colourThree)),
|
||||||
items: _selection,
|
items: _selection,
|
||||||
dropdownDecoratorProps: const DropDownDecoratorProps(
|
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||||
dropdownSearchDecoration: InputDecoration(
|
dropdownSearchDecoration: InputDecoration(
|
||||||
contentPadding: EdgeInsets.all(14),
|
contentPadding: const EdgeInsets.all(14),
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
filled: true,
|
filled: true,
|
||||||
fillColor: Colors.transparent,
|
fillColor: Colors.transparent,
|
||||||
hintText: "Select a currency",
|
hintText: _hintText,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: _onChanged,
|
onChanged: _onChanged,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
130
pubspec.lock
130
pubspec.lock
@@ -71,6 +71,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
|
ffi:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ffi
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
|
file:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: file
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.4"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -101,7 +115,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.6.5"
|
version: "4.6.5"
|
||||||
get_it:
|
get_it:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: get_it
|
name: get_it
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
@@ -163,6 +177,48 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.8.2"
|
||||||
|
path_provider_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_linux
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.7"
|
||||||
|
path_provider_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.4"
|
||||||
|
path_provider_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_windows
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
|
platform:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: platform
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.0"
|
||||||
|
plugin_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: plugin_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.2"
|
||||||
|
process:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: process
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.2.4"
|
||||||
provider:
|
provider:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -177,6 +233,62 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.13.0"
|
version: "1.13.0"
|
||||||
|
shared_preferences:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: shared_preferences
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.15"
|
||||||
|
shared_preferences_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_android
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.12"
|
||||||
|
shared_preferences_ios:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_ios
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
|
shared_preferences_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_linux
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
|
shared_preferences_macos:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_macos
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.4"
|
||||||
|
shared_preferences_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
|
shared_preferences_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.4"
|
||||||
|
shared_preferences_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_windows
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -280,6 +392,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.1.3"
|
||||||
|
win32:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.0"
|
||||||
|
xdg_directories:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xdg_directories
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.0+2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.18.0-190.0.dev <3.0.0"
|
dart: ">=2.18.0-190.0.dev <3.0.0"
|
||||||
flutter: ">=1.20.0"
|
flutter: ">=3.0.0"
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
|
shared_preferences: ^2.0.15
|
||||||
|
get_it: ^7.2.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user