From e0c3d7f4bab12e44a672693412758f1c9111bf62 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Thu, 22 Sep 2022 22:26:44 +0600 Subject: [PATCH] docs: update according to the new query bowl refactor --- docs/docs/basics/QueryBowlScope.md | 13 +++++++++---- docs/docs/getting-started/quick-start.md | 1 + packages/fl_query/README.md | 1 + packages/fl_query/lib/src/base_operation.dart | 3 ++- packages/fl_query/lib/src/query_bowl.dart | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/docs/basics/QueryBowlScope.md b/docs/docs/basics/QueryBowlScope.md index 00f48de..7f9dc63 100644 --- a/docs/docs/basics/QueryBowlScope.md +++ b/docs/docs/basics/QueryBowlScope.md @@ -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(), diff --git a/docs/docs/getting-started/quick-start.md b/docs/docs/getting-started/quick-start.md index 0ac1820..7ba62e5 100644 --- a/docs/docs/getting-started/quick-start.md +++ b/docs/docs/getting-started/quick-start.md @@ -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( diff --git a/packages/fl_query/README.md b/packages/fl_query/README.md index 2fbbaa9..8df7773 100644 --- a/packages/fl_query/README.md +++ b/packages/fl_query/README.md @@ -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( diff --git a/packages/fl_query/lib/src/base_operation.dart b/packages/fl_query/lib/src/base_operation.dart index f744dff..03978d8 100644 --- a/packages/fl_query/lib/src/base_operation.dart +++ b/packages/fl_query/lib/src/base_operation.dart @@ -1,3 +1,4 @@ +import 'package:fl_query/src/query_bowl.dart'; import 'package:flutter/widgets.dart'; abstract class BaseOperation extends ChangeNotifier { @@ -26,7 +27,7 @@ abstract class BaseOperation extends ChangeNotifier { /// storage/cache Set> _mounts = {}; - final queryBowl; + final QueryBowl queryBowl; BaseOperation({ required this.cacheTime, diff --git a/packages/fl_query/lib/src/query_bowl.dart b/packages/fl_query/lib/src/query_bowl.dart index 86a556e..b343deb 100644 --- a/packages/fl_query/lib/src/query_bowl.dart +++ b/packages/fl_query/lib/src/query_bowl.dart @@ -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.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.fromOptions( mutationJob, - queryBowl: this as dynamic, + queryBowl: this, ); if (onData != null) mutation.addDataListener(onData); if (onError != null) mutation.addErrorListener(onError);