Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed caching issues #158

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class MangaWithId extends _$MangaWithId {
),
);
ref.keepAlive();
state = result;
if (result.hasError) {
state = result.copyWithPrevious(state);
} else {
state = result;
}
}
}

Expand Down Expand Up @@ -73,7 +77,11 @@ class MangaChapterList extends _$MangaChapterList {
),
);
ref.keepAlive();
state = result;
if (result.hasError) {
state = result.copyWithPrevious(state);
} else {
state = result;
}
}

void updateChapter(int index, Chapter chapter) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ class MangaDetailsScreen extends HookConsumerWidget {
await mangaRefresh(onlineFetch);
await chapterListRefresh(onlineFetch);
if (context.mounted && onlineFetch) {
ref.read(toastProvider(context)).show(
context.l10n!.updateCompleted,
withMicrotask: true,
);
if (manga.hasError) {
ref.read(toastProvider(context)).show(
context.l10n!.updateCompleted,
withMicrotask: true,
);
} else {
ref.read(toastProvider(context)).showError(
context.l10n!.errorSomethingWentWrong,
);
}
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extension AsyncValueExtensions<T> on AsyncValue<T> {
}
return when(
data: data,
skipError: true,
error: (error, trace) => wrapper == null
? Emoticons(
text: showGenericError
Expand Down Expand Up @@ -76,6 +77,7 @@ extension AsyncValueExtensions<T> on AsyncValue<T> {
}

AsyncValue<U> copyWithData<U>(U Function(T) data) => when(
skipError: true,
data: (prev) => AsyncData(data(prev)),
error: (error, stackTrace) => AsyncError<U>(error, stackTrace),
loading: () => AsyncLoading<U>(),
Expand Down
5 changes: 3 additions & 2 deletions lib/src/utils/storage/dio/network_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class DioNetworkModule {
}) {
final cacheOptions = CacheOptions(
store: HiveCacheStore('dio_cache'),
policy: CachePolicy.forceCache,
policy: CachePolicy.refreshForceCache,
hitCacheOnErrorExcept: [401, 403],
priority: CachePriority.normal,
maxStale: const Duration(days: 14),
);
final dio = Dio();
(dio.transformer as BackgroundTransformer).jsonDecodeCallback = parseJson;
Expand All @@ -56,7 +57,7 @@ class DioNetworkModule {
);
} else {
if (kDebugMode) {
print('credential is null');
debugPrint('credential is null');
}
}
}
Expand Down