docs: update according to the new query bowl refactor

This commit is contained in:
Kingkor Roy Tirtho
2022-09-22 22:26:44 +06:00
parent 33f716a165
commit e0c3d7f4ba
5 changed files with 16 additions and 8 deletions
+9 -4
View File
@@ -3,9 +3,11 @@ title: QueryBowl Scope
sidebar_position: 1
---
The first thing needed for storing any form of data is a store. QueryBowlScope is basically a `StatefulWidget` which wraps around the actual store `QueryBowl`. It is similar to `ProviderScope` in riverpod & `MultiProvider` provider. But it can be used only once at the very top level of the application
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`
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 {
@@ -14,6 +16,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return QueryBowlScope(
bowl: QueryBowl(),
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
@@ -24,7 +27,7 @@ class MyApp extends StatelessWidget {
```
`QueryBowlScope` has many properties that can be configured. You can configure refetch behaviors, thresholds, delays etc along with cache time
`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
@@ -35,7 +38,9 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return QueryBowlScope(
staleTime: Duration(seconds: 10),
bowl: QueryBowl(
staleTime: Duration(seconds: 10),
),
child: MaterialApp(
title: 'Fl-Query Example',
home: const MyHomePage(),
+1
View File
@@ -39,6 +39,7 @@ class MyApp extends StatelessWidget {
// QueryBowlScope creates a Bowl (metaphor for Collection/Store)
// for all the Queries & Mutations
return QueryBowlScope(
bowl: QueryBowl(),
child: MaterialApp(
title: 'Fl-Query Quick Start',
theme: ThemeData(
+1
View File
@@ -45,6 +45,7 @@ First wrap your `MaterialApp` with with `QueryBowlScope` widget
```dart
Widget build(BuildContext context) {
return QueryBowlScope(
bowl: QueryBowl(),
child: MaterialApp(
title: 'Fl-Query Example App',
theme: ThemeData(
@@ -1,3 +1,4 @@
import 'package:fl_query/src/query_bowl.dart';
import 'package:flutter/widgets.dart';
abstract class BaseOperation<Data, Error> extends ChangeNotifier {
@@ -26,7 +27,7 @@ abstract class BaseOperation<Data, Error> extends ChangeNotifier {
/// storage/cache
Set<ValueKey<String>> _mounts = {};
final queryBowl;
final QueryBowl queryBowl;
BaseOperation({
required this.cacheTime,
+3 -3
View File
@@ -264,7 +264,7 @@ class QueryBowl {
options,
externalData: externalData,
previousData: previousData,
queryBowl: this as dynamic,
queryBowl: this,
);
query.updateDefaultOptions(
cacheTime: cache.cacheTime,
@@ -284,7 +284,7 @@ class QueryBowl {
final infiniteQuery = InfiniteQuery<T, Outside, PageParam>.fromOptions(
options,
externalData: externalData,
queryBowl: this as dynamic,
queryBowl: this,
);
infiniteQuery.updateDefaultOptions(
cacheTime: cache.cacheTime,
@@ -400,7 +400,7 @@ class QueryBowl {
} else {
final mutation = Mutation<T, V>.fromOptions(
mutationJob,
queryBowl: this as dynamic,
queryBowl: this,
);
if (onData != null) mutation.addDataListener(onData);
if (onError != null) mutation.addErrorListener(onError);