Change over to shared prefs
This commit is contained in:
parent
1aeb1bf78a
commit
94149deeee
|
|
@ -29,8 +29,8 @@ android {
|
|||
applicationId "com.invoiceninja.flutter"
|
||||
minSdkVersion 18
|
||||
targetSdkVersion 27
|
||||
versionCode 19
|
||||
versionName "0.1.17"
|
||||
versionCode 20
|
||||
versionName "0.1.18"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1.17</string>
|
||||
<string>0.1.18</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>19</string>
|
||||
<string>20</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
// This version must be updated in tandem with the pubspec version.
|
||||
const String kAppVersion = '0.1.17';
|
||||
const String kAppVersion = '0.1.18';
|
||||
const String kAppUrl = 'https://app.invoiceninja.com';
|
||||
|
||||
const String kSharedPrefEmail = 'email';
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import 'dart:convert';
|
|||
import 'dart:core';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_keychain/flutter_keychain.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/auth/auth_state.dart';
|
||||
|
|
@ -12,6 +11,7 @@ import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
|
|||
import 'package:meta/meta.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
||||
import 'package:invoiceninja_flutter/data/file_storage.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class PersistenceRepository {
|
||||
final FileStorage fileStorage;
|
||||
|
|
@ -30,8 +30,8 @@ class PersistenceRepository {
|
|||
|
||||
Future<CompanyState> loadCompanyState(int index) async {
|
||||
final String data = await fileStorage.load();
|
||||
final token =
|
||||
await FlutterKeychain.get(key: getKeychainTokenKey(index - 1)) ?? '';
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final token = prefs.getString(getKeychainTokenKey(index - 1)) ?? '';
|
||||
final companyState =
|
||||
serializers.deserializeWith(CompanyState.serializer, json.decode(data));
|
||||
return companyState.rebuild((b) => b
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import 'package:invoiceninja_flutter/utils/platforms.dart';
|
|||
import 'package:redux/redux.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_keychain/flutter_keychain.dart';
|
||||
|
||||
List<Middleware<AppState>> createStorePersistenceMiddleware([
|
||||
PersistenceRepository authRepository = const PersistenceRepository(
|
||||
|
|
@ -185,8 +184,10 @@ Middleware<AppState> _createLoadState(
|
|||
}
|
||||
} catch (error) {
|
||||
print(error);
|
||||
final String token =
|
||||
await FlutterKeychain.get(key: getKeychainTokenKey()) ?? '';
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final token = prefs.getString(getKeychainTokenKey()) ?? '';
|
||||
|
||||
if (token.isNotEmpty) {
|
||||
final Completer<Null> completer = Completer<Null>();
|
||||
completer.future.then((_) {
|
||||
|
|
@ -281,8 +282,9 @@ Middleware<AppState> _createDataLoaded() {
|
|||
|
||||
for (int i = 0; i < data.accounts.length; i++) {
|
||||
final CompanyEntity company = data.accounts[i];
|
||||
await FlutterKeychain.put(
|
||||
key: getKeychainTokenKey(i), value: company.token);
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString(getKeychainTokenKey(i), company.token);
|
||||
|
||||
store.dispatch(SelectCompany(i + 1));
|
||||
store.dispatch(LoadCompanySuccess(company));
|
||||
|
|
@ -348,8 +350,10 @@ Middleware<AppState> _createDeleteState(
|
|||
company4Repository.delete();
|
||||
company5Repository.delete();
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
for (int i=0; i<5; i++) {
|
||||
await FlutterKeychain.put(key: getKeychainTokenKey(i), value: '');
|
||||
prefs.setString(getKeychainTokenKey(i), '');
|
||||
}
|
||||
|
||||
next(action);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_keychain/flutter_keychain.dart';
|
||||
import 'package:invoiceninja_flutter/.env.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||
|
|
@ -28,25 +27,22 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
|
|||
}
|
||||
|
||||
void _saveAuthLocal(dynamic action) async {
|
||||
await FlutterKeychain.put(key: kKeychainEmail, value: action.email);
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString(kKeychainEmail, action.email);
|
||||
|
||||
if (formatApiUrlReadable(action.url) != kAppUrl) {
|
||||
await FlutterKeychain.put(
|
||||
key: kKeychainUrl, value: formatApiUrlMachine(action.url));
|
||||
await FlutterKeychain.put(key: kKeychainSecret, value: action.secret);
|
||||
prefs.setString(kKeychainUrl, formatApiUrlMachine(action.url));
|
||||
prefs.setString(kKeychainSecret, action.secret);
|
||||
}
|
||||
}
|
||||
|
||||
void _loadAuthLocal(Store<AppState> store, dynamic action) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String email = await FlutterKeychain.get(key: kKeychainEmail) ??
|
||||
prefs.getString(kSharedPrefEmail) ??
|
||||
Config.LOGIN_EMAIL;
|
||||
final String url = await FlutterKeychain.get(key: kKeychainUrl) ??
|
||||
final String email = prefs.getString(kSharedPrefEmail) ?? Config.LOGIN_EMAIL;
|
||||
final String url =
|
||||
formatApiUrlMachine(prefs.getString(kSharedPrefUrl) ?? Config.LOGIN_URL);
|
||||
final String secret = await FlutterKeychain.get(key: kKeychainSecret) ??
|
||||
prefs.getString(kSharedPrefSecret) ??
|
||||
Config.LOGIN_SECRET;
|
||||
final String secret =
|
||||
prefs.getString(kSharedPrefSecret) ?? Config.LOGIN_SECRET;
|
||||
store.dispatch(UserLoginLoaded(email, url, secret));
|
||||
|
||||
final bool enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode) ?? false;
|
||||
|
|
@ -133,9 +129,9 @@ Middleware<AppState> _createRefreshRequest(AuthRepository repository) {
|
|||
_loadAuthLocal(store, action);
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String url = await FlutterKeychain.get(key: kKeychainUrl) ??
|
||||
formatApiUrlMachine(prefs.getString(kSharedPrefUrl) ?? Config.LOGIN_URL);
|
||||
final String token = await FlutterKeychain.get(key: getKeychainTokenKey());
|
||||
final String url = formatApiUrlMachine(
|
||||
prefs.getString(kSharedPrefUrl) ?? Config.LOGIN_URL);
|
||||
final String token = prefs.getString(getKeychainTokenKey());
|
||||
|
||||
repository
|
||||
.refresh(url: url, token: token, platform: action.platform)
|
||||
|
|
|
|||
19
pubspec.lock
19
pubspec.lock
|
|
@ -84,14 +84,14 @@ packages:
|
|||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.3"
|
||||
version: "6.1.4"
|
||||
built_value_generator:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: built_value_generator
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.3"
|
||||
version: "6.1.4"
|
||||
cached_network_image:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -200,13 +200,6 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_keychain:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_keychain
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
flutter_localizations:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
|
@ -258,7 +251,7 @@ packages:
|
|||
name: google_sign_in
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.5"
|
||||
version: "3.2.1"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -419,7 +412,7 @@ packages:
|
|||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.2.0"
|
||||
plugin:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -482,7 +475,7 @@ packages:
|
|||
name: shared_preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
version: "0.4.3"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -522,7 +515,7 @@ packages:
|
|||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.1+1"
|
||||
version: "0.9.1+2"
|
||||
source_map_stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
name: invoiceninja_flutter
|
||||
description: Mobile app for Invoice Ninja
|
||||
version: 0.1.17
|
||||
version: 0.1.18
|
||||
author: Hillel Coren
|
||||
homepage: https://www.invoiceninja.com
|
||||
documentation: http://docs.invoiceninja.com
|
||||
|
|
@ -25,7 +25,6 @@ dependencies:
|
|||
intl: ^0.15.7
|
||||
flutter_slidable: ^0.4.6
|
||||
charts_flutter: ^0.4.0
|
||||
flutter_keychain: ^0.0.5
|
||||
google_sign_in: ^3.0.5
|
||||
firebase_auth: ^0.5.20
|
||||
#quick_actions: ^0.2.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue