diff --git a/android/app/build.gradle b/android/app/build.gradle index 662ef74..cee600c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -21,6 +21,11 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } +def relStorePassword = System.getenv("storePassword") +def relKeyPassword = System.getenv("keyPassword") +def relKeyAlias = System.getenv("keyAlias") +def relStoreFile = System.getenv("storeFile") + apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" @@ -43,7 +48,6 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.appttude.h_mal.easycc" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. @@ -53,11 +57,22 @@ android { versionName flutterVersionName } + signingConfigs { + release { + storePassword relStorePassword + keyPassword relKeyPassword + keyAlias relKeyAlias + storeFile file(relStoreFile) + } + } + buildTypes { release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig signingConfigs.release + minifyEnabled true + shrinkResources true + useProguard true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 581ca1d..24ec3e3 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,57 +1,73 @@ - + + + android:icon="@mipmap/launcher_icon" + android:label="easycc"> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> - - + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + - + + - - - - - - - - - - - - - - + diff --git a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt index 20f59c8..2e063e4 100644 --- a/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt +++ b/android/app/src/main/kotlin/com/appttude/h_mal/easycc/AppWidgetProvider.kt @@ -1,20 +1,17 @@ package com.appttude.h_mal.easycc import android.appwidget.AppWidgetManager -import android.content.ComponentName import android.content.Context -import android.content.Intent import android.content.SharedPreferences import android.net.Uri import android.widget.RemoteViews import android.widget.Toast import es.antonborri.home_widget.HomeWidgetBackgroundIntent import es.antonborri.home_widget.HomeWidgetLaunchIntent -import es.antonborri.home_widget.HomeWidgetPlugin import es.antonborri.home_widget.HomeWidgetProvider -class AppWidgetProvider : HomeWidgetProvider(){ +class AppWidgetProvider : HomeWidgetProvider() { override fun onUpdate( context: Context, appWidgetManager: AppWidgetManager, @@ -23,54 +20,46 @@ class AppWidgetProvider : HomeWidgetProvider(){ ) { appWidgetIds.forEach { widgetId -> val views = RemoteViews(context.packageName, R.layout.currency_app_widget).apply { - // Data from background operation received + val uri = createUpdateUri(widgetId) + val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context, uri) + // checks if forced update or period update + val forcedUpdate: Boolean = + widgetData.getBoolean("${widgetId}_forced_update", false) + + if (!forcedUpdate) { + widgetData.edit().putBoolean("${widgetId}_forced_update", true).apply() + backgroundIntent.send() + return@apply + } + val from: String? = widgetData.getString("${widgetId}_from", null) val to: String? = widgetData.getString("${widgetId}_to", null) val rate: String? = widgetData.getString("${widgetId}_rate", null) if (from.isNullOrBlank() or to.isNullOrBlank() or rate.isNullOrBlank()) { - Toast.makeText(context, "Unable to review data for widget", Toast.LENGTH_SHORT).show() + Toast.makeText(context, "Unable to review data for widget", Toast.LENGTH_SHORT) + .show() return@apply } val titleString = "${from}${to}" setTextViewText(R.id.exchangeName, titleString) setTextViewText(R.id.exchangeRate, rate.toString()) - - val uri = Uri.parse("myAppWidget://updatewidget").buildUpon() - .appendQueryParameter("id", widgetId.toString()) - .build() - setImageViewResource(R.id.refresh_icon, R.drawable.ic_refresh_white_24dp) - val backgroundIntent = HomeWidgetBackgroundIntent.getBroadcast(context, uri) setOnClickPendingIntent(R.id.refresh_icon, backgroundIntent) - val pendingIntent = HomeWidgetLaunchIntent.getActivity(context, - MainActivity::class.java) + val pendingIntent = HomeWidgetLaunchIntent.getActivity( + context, + MainActivity::class.java + ) + widgetData.edit().putBoolean("${widgetId}_forced_update", false).apply() setOnClickPendingIntent(R.id.widget_view, pendingIntent) } appWidgetManager.updateAppWidget(widgetId, views) } } - override fun onReceive(context: Context?, intent: Intent?) { - super.onReceive(context, intent) - - when (intent?.action) { - - } - val appWidgetManager = AppWidgetManager.getInstance(context); - val appWidgetIds = appWidgetManager.getAppWidgetIds( - context?.let { ComponentName(it, this::class.java) }) - val widgetDate = context?.let { HomeWidgetPlugin.getData(it) } - - appWidgetIds.forEach { widgetId -> - - - } - } - override fun onDeleted(context: Context?, appWidgetIds: IntArray?) { super.onDeleted(context, appWidgetIds) @@ -85,4 +74,11 @@ class AppWidgetProvider : HomeWidgetProvider(){ } } } + + // Send update broadcast to widget app class + private fun createUpdateUri(widgetId: Int): Uri? { + return Uri.parse("myAppWidget://updatewidget").buildUpon() + .appendQueryParameter("id", widgetId.toString()) + .build() + } } \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 4d866f8..2ae28e7 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -2,160 +2,43 @@ - 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 + USD - US Dollar \ No newline at end of file diff --git a/android/app/src/main/res/xml/currency_app_widget_info.xml b/android/app/src/main/res/xml/currency_app_widget_info.xml index 1e0409c..af77191 100644 --- a/android/app/src/main/res/xml/currency_app_widget_info.xml +++ b/android/app/src/main/res/xml/currency_app_widget_info.xml @@ -1,5 +1,6 @@ \ No newline at end of file + android:updatePeriodMillis="14400000" + android:widgetCategory="home_screen|keyguard" + tools:targetApi="jelly_bean_mr1" /> \ No newline at end of file diff --git a/lib/Utils/constants.dart b/lib/Utils/constants.dart index 4b54b68..c09ba0a 100644 --- a/lib/Utils/constants.dart +++ b/lib/Utils/constants.dart @@ -9,159 +9,42 @@ const Color colourFive = Color(0xFFC6E0FF); const double paddingGlobal = 12; final List listOfCurrencies = [ - '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' + 'USD - US Dollar' ]; \ No newline at end of file diff --git a/lib/data/network/currency_api.dart b/lib/data/network/currency_api.dart index 71ebda4..3fbe42b 100644 --- a/lib/data/network/currency_api.dart +++ b/lib/data/network/currency_api.dart @@ -1,4 +1,5 @@ -// ignore: depend_on_referenced_packages +// ignore_for_file: non_constant_identifier_names, depend_on_referenced_packages + import 'package:dio/dio.dart'; import 'package:easy_cc_flutter/data/network/app_dio.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -8,57 +9,52 @@ import '../model/currency.dart'; part 'currency_api.g.dart'; -@RestApi(baseUrl: "https://free.currencyconverterapi.com/api/v3/") +@RestApi(baseUrl: "https://exchange-rates.abstractapi.com/v1/") abstract class CurrencyApi { factory CurrencyApi(Dio dio, {String baseUrl}) = _CurrencyApi; + static const api = String.fromEnvironment('currencyApiKey'); - + static CurrencyApi create() { final dio = AppDio.createDio(); - dio.options.queryParameters.addAll({"apiKey": api}); + dio.options.queryParameters.addAll({"api_key": api}); return _CurrencyApi(dio); } - @GET("/convert?") - Future> getConversion(@Query("q") String currency); + @GET("/live?") + Future> getConversion( + @Query("base") String from, @Query("target") String to); } @JsonSerializable() -class ResponseObject implements CurrencyMapper{ - dynamic query; - Map? results; +class ResponseObject implements CurrencyMapper { + String base; + int last_updated; + Map? exchange_rates; - ResponseObject({ - this.query, - this.results - }); + ResponseObject(this.base, this.last_updated, this.exchange_rates); - factory ResponseObject.fromJson(Map json) => _$ResponseObjectFromJson(json); + factory ResponseObject.fromJson(Map json) => + _$ResponseObjectFromJson(json); Map toJson() => _$ResponseObjectToJson(this); @override Currency convert() { - CurrencyObject? cur = results?.entries.elementAt(0).value; - return Currency(cur?.fr, cur?.to, cur?.val); + return Currency(base, exchange_rates?.keys.first, exchange_rates?.values.first); } - } @JsonSerializable() -class CurrencyObject{ +class CurrencyObject { String? id; String? fr; String? to; double? val; - CurrencyObject({ - this.id, - this.fr, - this.to, - this.val - }); + CurrencyObject({this.id, this.fr, this.to, this.val}); - factory CurrencyObject.fromJson(Map json) => _$CurrencyObjectFromJson(json); + factory CurrencyObject.fromJson(Map json) => + _$CurrencyObjectFromJson(json); Map toJson() => _$CurrencyObjectToJson(this); -} \ No newline at end of file +} diff --git a/lib/data/network/safe_api_call.dart b/lib/data/network/safe_api_call.dart index 73647a9..38b9f46 100644 --- a/lib/data/network/safe_api_call.dart +++ b/lib/data/network/safe_api_call.dart @@ -15,14 +15,14 @@ mixin SafeApiCall { Map? errorResponse = dioError.response?.data?["error"]; String error; - if (errorResponse?["error"] != null){ - error = errorResponse!["error"]; - } else if (dioError.error != null){ - error = dioError.error; + if (errorResponse?["message"] != null){ + error = errorResponse!["message"]; + } else if (dioError.message.isNotEmpty){ + error = dioError.message; } else { error = "Failed to retrieve data from api"; } - logger.e(dioError.error); + logger.e(error); throw HttpException(error); } diff --git a/lib/data/repository/repository_impl.dart b/lib/data/repository/repository_impl.dart index 5d6f3ba..bc32da7 100644 --- a/lib/data/repository/repository_impl.dart +++ b/lib/data/repository/repository_impl.dart @@ -33,10 +33,8 @@ class RepositoryImpl extends Repository with SafeApiCall { String from = fromCurrency.getCurrencyCode(); String to = toCurrency.getCurrencyCode(); - String currency = "${from}_$to"; - try { - ResponseObject responseObject = await getDataFromApiCall(_api.getConversion(currency)); + ResponseObject responseObject = await getDataFromApiCall(_api.getConversion(from, to)); return responseObject.convert(); } on HttpException catch(error) { logger.e(error); diff --git a/lib/locator.dart b/lib/locator.dart index 8ba82fb..b0e1cbc 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -3,6 +3,7 @@ import 'package:easy_cc_flutter/data/network/currency_api.dart'; import 'package:easy_cc_flutter/data/repository/repository_impl.dart'; import 'package:easy_cc_flutter/main_view_model.dart'; import 'package:get_it/get_it.dart'; + import 'data/prefs/preference_provider.dart'; import 'data/repository/repository.dart'; diff --git a/lib/main.dart b/lib/main.dart index c4a6e3d..c412aa0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,6 +62,7 @@ Future updateWidget(String? widgetId, Repository repository) async { await HomeWidget.saveWidgetData("${widgetId}_from", from); await HomeWidget.saveWidgetData("${widgetId}_to", to); await HomeWidget.saveWidgetData("${widgetId}_rate", currency.rate.toString()); + await HomeWidget.saveWidgetData("${widgetId}_forced_update", true); await HomeWidget.updateWidget(name: 'AppWidgetProvider', iOSName: 'AppWidgetProvider'); } @@ -74,6 +75,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', + debugShowCheckedModeBanner: false, theme: ThemeData( // This is the theme of your application. // diff --git a/lib/main_view_model.dart b/lib/main_view_model.dart index 98e522f..6ab030c 100644 --- a/lib/main_view_model.dart +++ b/lib/main_view_model.dart @@ -40,8 +40,8 @@ class MainViewModel extends BaseViewmodel { (value) { conversionRate = value.rate != null ? value.rate! : 0.00; onSuccess(value); - }, onError: (exception, _) { - onError(exception.message); + }).catchError((e) { + onError(e.message); }); } diff --git a/pubspec.yaml b/pubspec.yaml index 5fa8453..2e911a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 6.1.1+8 environment: sdk: '>=2.18.0-190.0.dev <3.0.0' diff --git a/test/resources/success_call_api.json b/test/resources/success_call_api.json index aff2cb9..7bd5fd7 100644 --- a/test/resources/success_call_api.json +++ b/test/resources/success_call_api.json @@ -1,13 +1,7 @@ { - "query": { - "count": 1 - }, - "results": { - "AUD_GBP": { - "id": "AUD_GBP", - "fr": "AUD", - "to": "GBP", - "val": 0.601188 - } + "base": "AUD", + "last_updated": 1675689300, + "exchange_rates": { + "GBP": 0.601188 } } \ No newline at end of file diff --git a/test/unit_test/repository_test.dart b/test/unit_test/repository_test.dart index cc3c59a..935b2d0 100644 --- a/test/unit_test/repository_test.dart +++ b/test/unit_test/repository_test.dart @@ -25,6 +25,7 @@ import 'repository_test.mocks.dart'; onMissingStub: OnMissingStub.returnDefault), MockSpec>( as: #MockCurrencyResponse, onMissingStub: OnMissingStub.returnDefault), + MockSpec(onMissingStub: OnMissingStub.returnDefault), MockSpec(onMissingStub: OnMissingStub.returnDefault) ]) void main() { @@ -64,11 +65,10 @@ void main() { ResponseObject responseObject = ResponseObject.fromJson( await readJson("test/resources/success_call_api")); Currency currencyObject = Currency("AUD", "GBP", 0.601188); - String currency = "AUD_GBP"; // When when(mockResponse.data).thenReturn(responseObject); - when(currencyApi.getConversion(currency)) + when(currencyApi.getConversion("AUD", "GBP")) .thenAnswer((_) async => mockResponse); // Then @@ -83,11 +83,10 @@ void main() { CurrencyResponse currencyResponse = CurrencyResponse.fromJson( await readJson("test/resources/success_call_backup_api")); Currency currencyObject = Currency("AUD", "GBP", 0.601188); - String currency = "AUD_GBP"; // When - when(currencyApi.getConversion(currency)) - .thenAnswer((_) async => Future.error(MockDioError())); + when(currencyApi.getConversion("AUD", "GBP")) + .thenAnswer((_) async => Future.error(MockHttpException())); when(mockResponse.data).thenReturn(currencyResponse); when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) .thenAnswer((_) async => mockResponse); @@ -100,20 +99,20 @@ void main() { test('unable to retrieve rate from both APIs', () async { // Given - String currency = "AUD_GBP"; - DioError backUpError = MockDioError(); + MockDioError backUpError = MockDioError(); // When - when(backUpError.error).thenReturn("Error message"); - when(currencyApi.getConversion(currency)) + when(backUpError.message).thenReturn("Error message"); + when(currencyApi.getConversion("AUD", "GBP")) .thenAnswer((_) async => Future.error(MockDioError())); when(backupCurrencyApi.getCurrencyRate("AUD", "GBP")) .thenAnswer((_) async => Future.error(backUpError)); // Then - expect(() async => await sut.getConversationRateFromApi(fromCurrency, toCurrency), - throwsA(predicate((e) => - e is HttpException && - e.message == 'Error message'))); + expect( + () async => + await sut.getConversationRateFromApi(fromCurrency, toCurrency), + throwsA(predicate( + (e) => e is HttpException && e.message == 'Error message'))); }); } diff --git a/test/unit_test/viewmodel_test.dart b/test/unit_test/viewmodel_test.dart index 9e11ef7..2f47dc4 100644 --- a/test/unit_test/viewmodel_test.dart +++ b/test/unit_test/viewmodel_test.dart @@ -55,8 +55,8 @@ void main() { // Then String fromSelection = mainViewModel.getConversionPair(SelectionType.conversionFrom); String toSelection = mainViewModel.getConversionPair(SelectionType.conversionTo); - expect(fromSelection, "ALL - Albanian Lek"); - expect(toSelection, "ALL - Albanian Lek"); + expect(fromSelection, "DZD - Algerian Dinar"); + expect(toSelection, "DZD - Algerian Dinar"); }); test('set the currency rate from API', () async{