Reputation: 91
Hi everyone I am trying to display my data in my flutter project using Cache Provider from graphql_flutter package when a user doesn't have an internet connection but it seems to not be working, so I was wondering if there is something I am missing, I would need some help from you all, thanks for your consideration.
Here is my code in "main.dart"
HttpLink httpLink = HttpLink(
'http://104.131.161.92/graphql/',
defaultHeaders: <String, String>{
'accept-language': MyApp.language == 'es' ? 'rw' : 'en'
});
//webSocket link for chat
final WebSocketLink webSocketLink = WebSocketLink(
'ws://104.131.161.92:8002/graphql/',
config: SocketClientConfig(
initialPayload: () async => 'JWT ${MyApp.token}',
// config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(
minutes: 2
)
)
);
AuthLink authLink = AuthLink(
getToken: () async => 'JWT ${MyApp.token}',
);
Link link = authLink.concat(httpLink);
link = Link.split((request) => request.isSubscription, webSocketLink, link);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
link: link,
cache: GraphQLCache(store: HiveStore()),
),
);
return GraphQLProvider(
client: client,
child: CacheProvider(
child: MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => AppState(),
),
FutureProvider<EarnedMarks>(
initialData: EarnedMarks(0),
create: (context) async {
final prefs = await SharedPreferences.getInstance();
return EarnedMarks(prefs.getDouble('results'));
},
),
],
child: MaterialApp(...
and here below is my example file (all_posts.dart) that query data from back-end
Query(
options: QueryOptions(
document: gql(allPostsList),
variables: {'age': MyApp.age, 'gender': MyApp.gender, 'page': page},
// pollInterval: 10,
),
builder: (QueryResult result,
{VoidCallback refetch, FetchMore fetchMore}) {
_refetch = refetch;
if (result.hasException) {
print(result.exception.toString());
return
Text(result.exception.toString());
}
if (result.isLoading) {
return Center(child: CircularProgressIndicator());
}
List posts = result.data['publishedPosts']['objects'];
int pages = result.data['publishedPosts']['pages'];
return Container(
Upvotes: 4
Views: 709