feat: refresh on network state change and cancel retry when offline
This commit is contained in:
@@ -10,6 +10,7 @@ abstract class DefaultConstants {
|
||||
static const RetryConfig retryConfig = RetryConfig(
|
||||
maxRetries: 3,
|
||||
retryDelay: Duration(seconds: 1),
|
||||
cancelWhenOffline: true,
|
||||
);
|
||||
|
||||
static const RefreshConfig refreshConfig = RefreshConfig(
|
||||
@@ -17,6 +18,7 @@ abstract class DefaultConstants {
|
||||
refreshInterval: Duration.zero,
|
||||
refreshOnMount: false,
|
||||
refreshOnQueryFnChange: false,
|
||||
refreshOnNetworkStateChange: true,
|
||||
);
|
||||
|
||||
static const Duration cacheDuration = Duration(minutes: 5);
|
||||
|
||||
@@ -7,12 +7,14 @@ class RefreshConfig {
|
||||
final Duration refreshInterval;
|
||||
final bool refreshOnMount;
|
||||
final bool refreshOnQueryFnChange;
|
||||
final bool refreshOnNetworkStateChange;
|
||||
|
||||
const RefreshConfig({
|
||||
required this.staleDuration,
|
||||
required this.refreshInterval,
|
||||
required this.refreshOnMount,
|
||||
required this.refreshOnQueryFnChange,
|
||||
required this.refreshOnNetworkStateChange,
|
||||
});
|
||||
|
||||
factory RefreshConfig.withDefaults(
|
||||
@@ -49,6 +51,7 @@ class RefreshConfig {
|
||||
Duration? refreshInterval,
|
||||
bool? refreshOnMount,
|
||||
bool? refreshOnQueryFnChange,
|
||||
bool? refreshOnNetworkStateChange,
|
||||
}) {
|
||||
return RefreshConfig(
|
||||
staleDuration: staleDuration ?? this.staleDuration,
|
||||
@@ -56,6 +59,8 @@ class RefreshConfig {
|
||||
refreshOnMount: refreshOnMount ?? this.refreshOnMount,
|
||||
refreshOnQueryFnChange:
|
||||
refreshOnQueryFnChange ?? this.refreshOnQueryFnChange,
|
||||
refreshOnNetworkStateChange:
|
||||
refreshOnNetworkStateChange ?? this.refreshOnNetworkStateChange,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,13 @@ import 'package:flutter/material.dart';
|
||||
class RetryConfig {
|
||||
final int maxRetries;
|
||||
final Duration retryDelay;
|
||||
final bool cancelWhenOffline;
|
||||
|
||||
const RetryConfig({required this.maxRetries, required this.retryDelay});
|
||||
const RetryConfig({
|
||||
required this.maxRetries,
|
||||
required this.retryDelay,
|
||||
required this.cancelWhenOffline,
|
||||
});
|
||||
|
||||
factory RetryConfig.withDefaults(
|
||||
BuildContext context, {
|
||||
@@ -32,10 +37,12 @@ class RetryConfig {
|
||||
RetryConfig copyWith({
|
||||
int? maxRetries,
|
||||
Duration? retryDelay,
|
||||
bool? cancelWhenOffline,
|
||||
}) {
|
||||
return RetryConfig(
|
||||
maxRetries: maxRetries ?? this.maxRetries,
|
||||
retryDelay: retryDelay ?? this.retryDelay,
|
||||
cancelWhenOffline: cancelWhenOffline ?? this.cancelWhenOffline,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user