Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Leptopoda committed Apr 7, 2023
1 parent 97b44d8 commit 37ddddf
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/src/screens/category/category_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_cache_manager_dio/flutter_cache_manager_dio.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:nc_cookbook_api/nc_cookbook_api.dart';
Expand Down Expand Up @@ -106,7 +106,7 @@ class MainScreen extends StatelessWidget {
icon: const Icon(Icons.refresh_outlined),
tooltip: translate('app_bar.refresh'),
onPressed: () {
DefaultCacheManager().emptyCache();
DioCacheManager.instance.emptyCache();
BlocProvider.of<CategoriesBloc>(context)
.add(const CategoriesLoaded());
},
Expand Down Expand Up @@ -177,7 +177,7 @@ class CategoryScreen extends StatelessWidget {

return RefreshIndicator(
onRefresh: () {
DefaultCacheManager().emptyCache();
DioCacheManager.instance.emptyCache();
BlocProvider.of<CategoriesBloc>(context)
.add(const CategoriesLoaded());
return Future.value();
Expand Down
6 changes: 3 additions & 3 deletions lib/src/screens/recipes_list_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_cache_manager_dio/flutter_cache_manager_dio.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:intl/intl.dart';
import 'package:nc_cookbook_api/nc_cookbook_api.dart';
Expand Down Expand Up @@ -34,7 +34,7 @@ class RecipesListScreen extends StatelessWidget {
icon: const Icon(Icons.refresh_outlined),
tooltip: translate('app_bar.refresh'),
onPressed: () {
DefaultCacheManager().emptyCache();
DioCacheManager.instance.emptyCache();
BlocProvider.of<RecipesShortBloc>(context)
.add(RecipesShortLoaded(category: category));
},
Expand All @@ -43,7 +43,7 @@ class RecipesListScreen extends StatelessWidget {
),
body: RefreshIndicator(
onRefresh: () {
DefaultCacheManager().emptyCache();
DioCacheManager.instance.emptyCache();
BlocProvider.of<RecipesShortBloc>(context)
.add(RecipesShortLoaded(category: category));
return Future.value();
Expand Down
40 changes: 38 additions & 2 deletions lib/src/services/api_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,48 @@ part of 'services.dart';

class ApiProvider {
factory ApiProvider() => _apiProvider;
ApiProvider._() {
ApiProvider._();
static final ApiProvider _apiProvider = ApiProvider._();

Future<void> initialize() async {
final auth = UserRepository().currentAppAuthentication;

final documentsDir = await getApplicationDocumentsDirectory();

// Global options
final options = CacheOptions(
// A default store is required for interceptor.
store: SembastCacheStore(storePath: documentsDir.path),

// All subsequent fields are optional.

// Default.
policy: CachePolicy.noCache,
// Returns a cached response on error but for statuses 401 & 403.
// Also allows to return a cached response on network errors (e.g. offline usage).
// Defaults to [null].
hitCacheOnErrorExcept: [401, 403],
// Overrides any HTTP directive to delete entry past this duration.
// Useful only when origin server has no cache config or custom behaviour is desired.
// Defaults to [null].
maxStale: const Duration(days: 7),
// Default. Allows 3 cache sets and ease cleanup.
priority: CachePriority.normal,
// Default. Body and headers encryption with your own algorithm.
cipher: null,
// Default. Key builder to retrieve requests.
keyBuilder: CacheOptions.defaultCacheKeyBuilder,
// Default. Allows to cache POST requests.
// Overriding [keyBuilder] is strongly recommended when [true].
allowPostMethod: false,
);

ncCookbookApi = NcCookbookApi(
basePathOverride: '${auth.server}/apps/cookbook',
interceptors: [
BasicAuthInterceptor(),
DioCacheInterceptor(options: options),
],
);

ncCookbookApi.setBasicAuth(
Expand All @@ -19,7 +56,6 @@ class ApiProvider {
miscApi = ncCookbookApi.getMiscApi();
tagsApi = ncCookbookApi.getTagsApi();
}
static final ApiProvider _apiProvider = ApiProvider._();

late NcCookbookApi ncCookbookApi;
late RecipesApi recipeApi;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/services/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'dart:developer';
import 'package:dio/dio.dart' as dio;
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_sembast_storage/dio_cache_interceptor_sembast_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Expand All @@ -16,6 +18,7 @@ import 'package:nextcloud_cookbook_flutter/src/models/image_response.dart';
import 'package:nextcloud_cookbook_flutter/src/models/timer.dart';
import 'package:nextcloud_cookbook_flutter/src/screens/recipe_import_screen.dart';
import 'package:nextcloud_cookbook_flutter/src/util/url_validator.dart';
import 'package:path_provider/path_provider.dart';
import 'package:timezone/data/latest_10y.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:xml/xml.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/src/services/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class UserRepository {
}

Future<APIVersion> fetchApiVersion() async {
await ApiProvider().initialize();
final response = await ApiProvider().miscApi.version();

return response.data!.apiVersion;
Expand Down
9 changes: 8 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ dependencies:
timezone: ^0.9.1

cached_network_image: ^3.0.0
flutter_cache_manager: ^3.3.0
#flutter_cache_manager: ^3.3.0
flutter_cache_manager_dio:
git:
url: https://github.com/josh-burton/flutter_cache_manager_dio.git
ref: dio-5.x
dio_cache_interceptor_sembast_storage: ^0.1.0
dio_cache_interceptor: ^3.4.1
path_provider: ^2.0.14

flutter_typeahead: ^4.3.7

Expand Down

0 comments on commit 37ddddf

Please sign in to comment.