docs: update query client provider

This commit is contained in:
Kingkor Roy Tirtho
2023-10-06 22:32:22 +06:00
parent a1fa2cc4f8
commit cf6a99504e
2 changed files with 46 additions and 53 deletions
-53
View File
@@ -1,53 +0,0 @@
---
title: QueryBowl Scope
sidebar_position: 1
---
The first thing needed for storing any form of data is a store. QueryBowlScope is basically a `InheritedWidget` which wraps around the actual store `QueryBowl`. It is similar to `ProviderScope` in riverpod & `MultiProvider` provider. It just inject the instance of `QueryBowl` to the `BuildContext`
You must use wrap your `MaterialApp` or `CupertinoApp` or `FluentApp` or `MacosApp` with `QueryBowlScope` for using same `QueryBowl` across all screens/routes
Or, if you want you can use `QueryBowlScope` anywhere in the Widget Tree to provide the `QueryBowl` instance to the children.
```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return QueryBowlScope(
bowl: QueryBowl(),
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
),
);
}
}
```
`QueryBowl` has many properties that can be configured. You can configure refetch behaviors, thresholds, delays etc along with cache time
Here I'm increasing the staleTime to 10 seconds. This means that if the data is outdated after 10 seconds & will be refetched in the background smartly when needed. The default value is 1 seconds
```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return QueryBowlScope(
bowl: QueryBowl(
staleTime: Duration(seconds: 10),
),
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
),
);
}
}
```
For more information on how to use QueryBowlScope, please refer to the [QueryBowlScope](https://pub.dev/documentation/fl_query/latest/fl_query/QueryBowlScope-class.html) API Reference
+46
View File
@@ -0,0 +1,46 @@
---
sidebar_position: 1
---
The first thing needed for storing any form of data is a store. QueryClientProvider is basically a `InheritedWidget` which wraps around the actual store `QueryClient`. You must use wrap your `MaterialApp` or `CupertinoApp` with `QueryClientProvider` for using same `QueryClient` across all screens/routes. Or, if you want you can use `QueryClientProvider` anywhere in the Widget Tree to a different `QueryClient` to the descendant widgets
```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return QueryClientProvider(
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
),
);
}
}
```
`QueryClientProvider` has many properties that can be configured. You can configure refetch behaviors, staleDuration, retries etc
Here I'm increasing the staleTime to 10 seconds. This means that if the data is outdated after 10 seconds, it will be refetched in the background smartly when needed. The default value is _2 minutes 250 milliseconds_
```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return QueryClientProvider(
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
),
);
}
}
```
> If you provide `QueryClient` to `QueryClientProvider` then assign all the parameters to `QueryClient` itself
For more information on how to use QueryClientProvider, please refer to the [QueryClientProvider](https://pub.dev/documentation/fl_query/latest/fl_query/QueryClientProvider-class.html) API Reference