mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2025-12-10 03:05:34 +00:00
Ability to cache currency selection (#5)
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user