fquery
fquery copied to clipboard
Retry count: 0 not working
Version: v1.5.0-beta.1
When I only want to fetch data once, I set it like this
void main() {
runApp(QueryClientProvider(
queryClient: QueryClient(
defaultQueryOptions: DefaultQueryOptions(
cacheDuration: const Duration(minutes: 20),
refetchInterval: const Duration(minutes: 5),
refetchOnMount: RefetchOnMount.always,
staleDuration: const Duration(minutes: 3),
retryCount: 0,
),
),
child: const MyApp()));
}
or
Future<List<Post>> getPosts() async {
final res =
await Dio().get('https://jsonplaceholder.typicode.com/postss?_limit=3');
return (res.data as List)
.map((e) => Post.fromJson(e as Map<String, dynamic>))
.toList();
}
final posts = useQuery(['posts'], getPosts, retryCount: 0);
but the api is not called
if set to retry count: 1 then api will be called twice if an error occurs (as I understand it is 1 default + 1 retry)
so if set is 0, it must be called once right?
Full example code
import 'package:dio/dio.dart';
import 'package:fl_starter/core/models/post_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:fquery/fquery.dart';
Future<List<Post>> getPosts() async {
final res =
await Dio().get('https://jsonplaceholder.typicode.com/postss?_limit=3');
return (res.data as List)
.map((e) => Post.fromJson(e as Map<String, dynamic>))
.toList();
}
void main() {
runApp(QueryClientProvider(
queryClient: QueryClient(
defaultQueryOptions: DefaultQueryOptions(
cacheDuration: const Duration(minutes: 20),
refetchInterval: const Duration(minutes: 5),
refetchOnMount: RefetchOnMount.always,
staleDuration: const Duration(minutes: 3),
retryCount: 0,
),
),
child: const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends HookWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
Widget build(BuildContext context) {
final posts = useQuery(['posts'], getPosts);
if (posts.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (posts.isError) {
return Center(child: Text(posts.error!.toString()));
}
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(title),
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Will look into this soon
resolved in commit a6eb68f