From d10dbbffed6237afd72721aa6359e62eb02da581 Mon Sep 17 00:00:00 2001 From: Souradip Mookerjee Date: Mon, 15 Jul 2024 10:05:25 +0100 Subject: [PATCH] remove hive completely --- lib/data/web_client.dart | 119 ++++++++++++++++++--------------------- lib/main.dart | 2 - pubspec.lock | 16 ------ pubspec.yaml | 1 - 4 files changed, 54 insertions(+), 84 deletions(-) diff --git a/lib/data/web_client.dart b/lib/data/web_client.dart index dbf22a8272..8bb8367670 100644 --- a/lib/data/web_client.dart +++ b/lib/data/web_client.dart @@ -7,7 +7,6 @@ import 'package:flutter/foundation.dart'; //import 'package:flutter_redux/flutter_redux.dart'; // Package imports: -import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart' as http; import 'package:http/http.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; @@ -32,17 +31,6 @@ class WebClient { return connectionStatus.hasConnection; } - Future _cacheData(String key, dynamic data) async { - final box = await Hive.openBox('cachedResponses'); - await box.put(key, data); - } - - Future _getCachedData(String key) async { - final box = await Hive.openBox('cachedResponses'); - final data = box.get(key); - return data; - } - Future get( String url, String? token, { @@ -67,6 +55,8 @@ class WebClient { print('GET: $url'); final isOnline = await _isOnline(); + print("isOnline: $isOnline"); + if (isOnline) { final client = http.Client(); final http.Response response = await client.get( @@ -83,17 +73,9 @@ class WebClient { final dynamic jsonResponse = json.decode(response.body); - // Cache the response - await _cacheData(url, jsonResponse); - return jsonResponse; } else { - final cachedData = await _getCachedData(url); - if (cachedData != null) { - print('Returning cached data'); - return cachedData; - } - throw 'No internet connection available'; + return Future.error("No internet connection available."); } } @@ -121,6 +103,7 @@ class WebClient { final isOnline = await _isOnline(); print("isOnline: $isOnline"); + if (isOnline) { if (multipartFiles != null) { response = await _uploadFiles(url, token, multipartFiles, data: data); @@ -157,17 +140,9 @@ class WebClient { final dynamic jsonResponse = json.decode(response.body); - // Cache the response - await _cacheData(url + data, jsonResponse); - return jsonResponse; } else { - final cachedData = await _getCachedData(url + data); - if (cachedData != null) { - print('Returning cached data'); - return cachedData; - } - throw 'No internet connection available'; + return Future.error("No internet connection available."); } } @@ -191,27 +166,34 @@ class WebClient { } http.Response response; - if (multipartFile != null) { - response = await _uploadFiles(url, token, [multipartFile], - data: data, method: 'PUT'); - } else { - final client = http.Client(); - response = await client.put( - Uri.parse(url), - body: data, - headers: _getHeaders( - url, - token, - password: password, - idToken: idToken, - ), - ); - client.close(); - } + final isOnline = await _isOnline(); + print("isOnline: $isOnline"); + + if (isOnline) { + if (multipartFile != null) { + response = await _uploadFiles(url, token, [multipartFile], + data: data, method: 'PUT'); + } else { + final client = http.Client(); + response = await client.put( + Uri.parse(url), + body: data, + headers: _getHeaders( + url, + token, + password: password, + idToken: idToken, + ), + ); + client.close(); + } - _checkResponse(url, response); + _checkResponse(url, response); - return json.decode(response.body); + return json.decode(response.body); + } else { + return Future.error("No internet connection available."); + } } Future delete( @@ -229,22 +211,29 @@ class WebClient { print('Delete: $url'); - final client = http.Client(); - final http.Response response = await client.delete( - Uri.parse(url), - headers: _getHeaders( - url, - token, - password: password, - idToken: idToken, - ), - body: data, - ); - client.close(); - - _checkResponse(url, response); - - return json.decode(response.body); + final isOnline = await _isOnline(); + print("isOnline: $isOnline"); + + if (isOnline) { + final client = http.Client(); + final http.Response response = await client.delete( + Uri.parse(url), + headers: _getHeaders( + url, + token, + password: password, + idToken: idToken, + ), + body: data, + ); + client.close(); + + _checkResponse(url, response); + + return json.decode(response.body); + } else { + return Future.error("No internet connection available."); + } } } diff --git a/lib/main.dart b/lib/main.dart index 550d11b5c6..38ba727584 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,7 +13,6 @@ import 'package:redux_logging/redux_logging.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; -import 'package:hive_flutter/hive_flutter.dart'; // import 'package:bitsdojo_window/bitsdojo_window.dart'; // Project imports: @@ -101,7 +100,6 @@ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= '''; void main({bool isTesting = false}) async { - await Hive.initFlutter(); final ConnectionStatusSingleton connectionStatus = ConnectionStatusSingleton.getInstance(); connectionStatus.initialize(); diff --git a/pubspec.lock b/pubspec.lock index 35d9b65cbf..319bbb6b22 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -609,22 +609,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.1" - hive: - dependency: transitive - description: - name: hive - sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941" - url: "https://pub.dev" - source: hosted - version: "2.2.3" - hive_flutter: - dependency: "direct main" - description: - name: hive_flutter - sha256: dca1da446b1d808a51689fb5d0c6c9510c0a2ba01e22805d492c73b68e33eecc - url: "https://pub.dev" - source: hosted - version: "1.1.0" html: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a2113db307..d5ab4ba009 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -86,7 +86,6 @@ dependencies: device_info_plus: ^9.1.0 ios_open_subscriptions_settings: ^0.0.4 connectivity_plus: ^6.0.3 - hive_flutter: ^1.1.0 dependency_overrides: intl: any