diff --git a/packages/fl_query/.flutter-plugins-dependencies b/packages/fl_query/.flutter-plugins-dependencies index 168460a..2c1d65f 100644 --- a/packages/fl_query/.flutter-plugins-dependencies +++ b/packages/fl_query/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-07-18 18:16:02.735188","version":"3.0.1"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-07-20 12:20:16.617434","version":"3.0.1"} \ No newline at end of file diff --git a/packages/fl_query/lib/src/base_operation.dart b/packages/fl_query/lib/src/base_operation.dart index 0683b25..20d532f 100644 --- a/packages/fl_query/lib/src/base_operation.dart +++ b/packages/fl_query/lib/src/base_operation.dart @@ -1,7 +1,7 @@ import 'package:fl_query/src/query_bowl.dart'; import 'package:flutter/widgets.dart'; -abstract class BaseOperation extends ChangeNotifier { +abstract class BaseOperation extends ChangeNotifier { /// The number of times the query should refetch in the time of error /// before giving up final int retries; @@ -14,7 +14,6 @@ abstract class BaseOperation extends ChangeNotifier { // all properties Data? data; dynamic error; - StatusType status; /// total count of how many times the query retried to get a successful /// result @@ -34,7 +33,6 @@ abstract class BaseOperation extends ChangeNotifier { required this.cacheTime, required this.retries, required this.retryDelay, - required this.status, required this.queryBowl, this.data, }) : updatedAt = DateTime.now(); @@ -58,10 +56,6 @@ abstract class BaseOperation extends ChangeNotifier { Set> get mounts => _mounts; - bool get isSuccess; - bool get isError; - bool get isLoading; - bool get isIdle; bool get isInactive => mounts.isEmpty; bool get hasData => data != null; bool get hasError => error != null; diff --git a/packages/fl_query/lib/src/models/query_job.dart b/packages/fl_query/lib/src/models/query_job.dart index 677dbe0..b746c32 100644 --- a/packages/fl_query/lib/src/models/query_job.dart +++ b/packages/fl_query/lib/src/models/query_job.dart @@ -1,22 +1,5 @@ import 'package:fl_query/src/query.dart'; -/// How to make dependent Queries? -/// -/// Pass a [QueryBowl] class/object to [task] that contains a method -/// [QueryBowl.dependOnQuery] that takes a [QueryJob] and uses that to get -/// the appropriate query for it or if it doesn't exist creates a new -/// instance. It listens to the changes of [Query] of the passed -/// [QueryJob] & calls the [notifyListener] method of running [Query] -/// -/// If shown briefly -/// -/// ```data -/// task: (queryKey, external, queryBowl){ -/// final dependentQuery = queryBowl.dependOnQuery(dependentQueryJob); -/// return someAsyncTask(); -/// } -/// ``` - class QueryJob { // all params String _queryKey; diff --git a/packages/fl_query/lib/src/mutation.dart b/packages/fl_query/lib/src/mutation.dart index 5e87fd0..f017827 100644 --- a/packages/fl_query/lib/src/mutation.dart +++ b/packages/fl_query/lib/src/mutation.dart @@ -16,11 +16,13 @@ typedef MutationListener = FutureOr Function(T); typedef MutationTaskFunction = FutureOr Function( String queryKey, V variables); -class Mutation extends BaseOperation { +class Mutation extends BaseOperation { // all params final String mutationKey; MutationTaskFunction task; + MutationStatus status; + @protected final Set> onDataListeners = {}; @protected @@ -38,7 +40,8 @@ class Mutation extends BaseOperation { MutationListener? onData, MutationListener? onError, MutationListener? onMutate, - }) : super(cacheTime: cacheTime, status: MutationStatus.idle) { + }) : status = MutationStatus.idle, + super(cacheTime: cacheTime) { if (onData != null) onDataListeners.add(onData); if (onError != null) onErrorListeners.add(onError); if (onMutate != null) onMutateListeners.add(onMutate); @@ -52,11 +55,11 @@ class Mutation extends BaseOperation { required super.queryBowl, }) : mutationKey = options.mutationKey, task = options.task, + status = MutationStatus.idle, super( retries: options.retries ?? 3, retryDelay: options.retryDelay ?? const Duration(milliseconds: 200), cacheTime: options.cacheTime ?? const Duration(minutes: 5), - status: MutationStatus.idle, ) { if (onData != null) onDataListeners.add(onData); if (onError != null) onErrorListeners.add(onError); @@ -160,13 +163,9 @@ class Mutation extends BaseOperation { A? cast() => this is A ? this as A : null; - @override bool get isError => status == MutationStatus.error; - @override bool get isIdle => status == MutationStatus.idle; - @override bool get isLoading => status == MutationStatus.loading; - @override bool get isSuccess => status == MutationStatus.success; @override diff --git a/packages/fl_query/lib/src/query.dart b/packages/fl_query/lib/src/query.dart index b01fe01..655b9cf 100644 --- a/packages/fl_query/lib/src/query.dart +++ b/packages/fl_query/lib/src/query.dart @@ -36,7 +36,7 @@ typedef ListenerUnsubscriber = void Function(); typedef QueryUpdateFunction = FutureOr Function(T? oldData); -class Query extends BaseOperation { +class Query extends BaseOperation { // all params final String queryKey; QueryTaskFunction task; @@ -54,6 +54,8 @@ class Query extends BaseOperation { int refetchCount = 0; bool enabled; + QueryStatus status; + @protected final Set> onDataListeners = Set>(); @protected @@ -89,10 +91,8 @@ class Query extends BaseOperation { }) : _staleTime = staleTime, _initialData = initialData, _externalData = externalData, - super( - status: QueryStatus.idle, - data: initialData, - ) { + status = QueryStatus.idle, + super(data: initialData) { if (onData != null) onDataListeners.add(onData); if (onError != null) onErrorListeners.add(onError); @@ -116,8 +116,8 @@ class Query extends BaseOperation { refetchInterval = options.refetchInterval, refetchOnMount = options.refetchOnMount, refetchOnReconnect = options.refetchOnReconnect, + status = QueryStatus.idle, super( - status: QueryStatus.idle, cacheTime: options.cacheTime ?? const Duration(minutes: 5), retries: options.retries ?? 3, retryDelay: options.retryDelay ?? const Duration(milliseconds: 200), @@ -193,6 +193,7 @@ class Query extends BaseOperation { await onError(error); } notifyListeners(); + break; } retryAttempts++; } @@ -219,7 +220,7 @@ class Query extends BaseOperation { /// if isLoading/isRefetching is true that means its already fetching/ /// refetching. So [_execute] again can create a race condition if (isRefetching || isLoading) return data; - if (enabled && !fetched) await fetch(); + if (enabled && !fetched) return await fetch(); status = QueryStatus.refetching; refetchCount++; // disabling the lazy query bound when query was actually called @@ -245,7 +246,7 @@ class Query extends BaseOperation { notifyListeners(); } - setExternalData(Outside externalData) { + void setExternalData(Outside externalData) { _prevUsedExternalData = _externalData; _externalData = externalData; } @@ -289,10 +290,6 @@ class Query extends BaseOperation { notifyListeners(); } - Future _internalRefetch(X dataOrError) { - return refetch(); - } - bool get isStale { /// when [_staleTime] is [Duration.zero], the query will always be /// stale & will never refetch in the background. But can be inactive @@ -304,20 +301,28 @@ class Query extends BaseOperation { return DateTime.now().isAfter(updatedAt.add(_staleTime)); } - @override bool get isError => status == QueryStatus.error; - @override bool get isIdle => status == QueryStatus.idle; - @override bool get isLoading => status == QueryStatus.loading; bool get isRefetching => status == QueryStatus.refetching; - @override bool get isSuccess => status == QueryStatus.success; A? cast() => this is A ? this as A : null; String get debugLabel => "Query($queryKey)"; + @override + void mount(ValueKey uKey) { + super.mount(uKey); + if (refetchOnMount == true && isStale) { + Connectivity().checkConnectivity().then((status) async { + if (isConnectedToInternet(status)) { + await refetch(); + } + }); + } + } + @override String toString() { return debugLabel; diff --git a/packages/fl_query/lib/src/query_builder.dart b/packages/fl_query/lib/src/query_builder.dart index e8e8323..5528560 100644 --- a/packages/fl_query/lib/src/query_builder.dart +++ b/packages/fl_query/lib/src/query_builder.dart @@ -55,9 +55,11 @@ class _QueryBuilderState final hasExternalDataChanged = query!.externalData != null && query!.prevUsedExternalData != null && !isShallowEqual(query!.externalData!, query!.prevUsedExternalData!); - (query!.fetched && query!.refetchOnMount == true) || hasExternalDataChanged - ? await query!.refetch() - : await query!.fetch(); + if (query!.fetched && hasExternalDataChanged) { + await query!.refetch(); + } else if (!query!.fetched) { + await query!.fetch(); + } } @override diff --git a/packages/fl_query/pubspec.yaml b/packages/fl_query/pubspec.yaml index 3e15a47..5a82cd2 100644 --- a/packages/fl_query/pubspec.yaml +++ b/packages/fl_query/pubspec.yaml @@ -23,5 +23,5 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.0 - mocktail: ^0.3.0 - flutter_hooks: ^0.18.5 \ No newline at end of file + mockito: ^5.2.0 + build_runner: ^2.2.0 diff --git a/packages/fl_query/test/query_test.dart b/packages/fl_query/test/query_test.dart index 12567be..5184bf5 100644 --- a/packages/fl_query/test/query_test.dart +++ b/packages/fl_query/test/query_test.dart @@ -2,23 +2,38 @@ import 'dart:math'; import 'package:fl_query/src/models/query_job.dart'; import 'package:fl_query/src/query.dart'; +import 'package:fl_query/src/query_bowl.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; - -class MockQueryJob extends Mock implements QueryJob {} +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'query_test.mocks.dart'; +@GenerateMocks( + [QueryBowl], + customMocks: [ + MockSpec>( + as: #MockQueryJobVoidObject, + returnNullOnMissingStub: true, + ), + ], +) void main() { // for testing query without external data late Query query; - late QueryJob queryJob; + late MockQueryJobVoidObject queryJob; + late MockQueryBowl queryBowl; setUp(() { - queryJob = MockQueryJob(); - when(() => queryJob.queryKey).thenReturn("test"); - when(() => queryJob.task("test", null)) - .thenAnswer((_) => (_, __) => "test"); + queryJob = MockQueryJobVoidObject(); + queryBowl = MockQueryBowl(); + when(queryJob.queryKey).thenReturn("test"); + when(queryJob.task).thenAnswer( + (_) => + (_, __) => Future.delayed(Duration(milliseconds: 300), () => "test"), + ); query = Query.fromOptions( queryJob, externalData: null, + queryBowl: queryBowl, ); }); @@ -30,11 +45,11 @@ void main() { expect(query.retryAttempts, 0); expect(query.fetched, isFalse); expect(query.retryDelay, Duration(milliseconds: 200)); - expect(query.status, QueryStatus.loading); + expect(query.status, QueryStatus.idle); expect(query.isStale, isFalse); - expect(query.isIdle, isFalse); + expect(query.isIdle, true); expect(query.isInactive, isTrue); - expect(query.isLoading, isTrue); + expect(query.isLoading, isFalse); expect(query.isSuccess, isFalse); expect(query.hasError, isFalse); expect(query.hasData, isFalse); @@ -42,10 +57,9 @@ void main() { test("calling fetch for the first time runs the _execute method", () async { final data = await query.fetch(); - expect(data, "test"); expect(query.fetched, isTrue); - verify(() => queryJob.task("test", null)).called(1); + verify(queryJob.task).called(1); }); test( @@ -57,21 +71,87 @@ void main() { await query.fetch(); await query.fetch(); expect(data1, data2); - verify(() => queryJob.task("test", null)).called(1); + verify(queryJob.task).called(1); }); test('calling refetch should return new data', () async { reset(queryJob); - when(() => queryJob.queryKey).thenReturn("test-1"); - when(() => queryJob.task("test-1", null)).thenAnswer((_) => (_, __) { - return Future.value(Random().nextInt(100).toString()); - }); - final data = await query.fetch(); - await Future.delayed(Duration(milliseconds: 100)); - final refetchData = await query.refetch(); + when(queryJob.queryKey).thenReturn("test"); + when(queryJob.task).thenAnswer( + (_) => (_, __) => Future.value(Random().nextInt(100)), + ); + query = Query.fromOptions( + queryJob, + externalData: null, + queryBowl: queryBowl, + ); - expect(data, isNot(equals(refetchData))); - verify(() => queryJob.task("test-1", null)).called(2); + await Future.delayed(Duration(milliseconds: 100)); + await query.fetch().then((data) async { + final refetchData = await query.refetch(); + expect(data, isNot(equals(refetchData))); + }); }); + + test( + "refetch should not run When another refetch is already running", + () async { + await query.fetch(); + await Future.delayed(Duration(milliseconds: 100)); + await Future.wait([ + query.refetch(), + query.refetch(), + ]); + expect(query.refetchCount, 1); + }, + ); + test( + "failing task should be retried the amount of times passed as retries parameter", + () async { + reset(queryJob); + when(queryJob.queryKey).thenReturn("test"); + when(queryJob.task).thenAnswer( + (_) => (_, __) => Future.error("Error"), + ); + query = Query.fromOptions( + queryJob, + externalData: null, + queryBowl: queryBowl, + ); + + await query.fetch(); + + expect(query.retryAttempts, 3); + expect(query.isError, true); + }, + ); + test( + "onData listeners are called When new data is fetched and set", + () async { + int count = 0; + query.onDataListeners.add((_) { + count++; + }); + await query.fetch(); + expect(count, 1); + }, + ); + test( + "onError listeners are called When any error occurs", + () {}, + ); + test("query should become stale after defined amount time", () {}); + test( + "query should refetch in interval When refetchInterval is specified", + () {}, + ); + test( + "query should revalidate When a new caller gets mounted", + () {}, + ); + test( + "query should not revalidate When there's no Internet Connectivity and a new caller gets mounted", + () {}, + ); }); } diff --git a/packages/fl_query/test/query_test.mocks.dart b/packages/fl_query/test/query_test.mocks.dart new file mode 100644 index 0000000..b5a38b5 --- /dev/null +++ b/packages/fl_query/test/query_test.mocks.dart @@ -0,0 +1,277 @@ +// Mocks generated by Mockito 5.2.0 from annotations +// in fl_query/test/query_test.dart. +// Do not manually edit this file. + +import 'dart:async' as _i7; + +import 'package:fl_query/src/models/mutation_job.dart' as _i9; +import 'package:fl_query/src/models/query_job.dart' as _i8; +import 'package:fl_query/src/mutation.dart' as _i4; +import 'package:fl_query/src/query.dart' as _i3; +import 'package:fl_query/src/query_bowl.dart' as _i6; +import 'package:flutter/foundation.dart' as _i5; +import 'package:flutter/rendering.dart' as _i10; +import 'package:flutter/widgets.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types + +class _FakeDuration_0 extends _i1.Fake implements Duration {} + +class _FakeWidget_1 extends _i1.Fake implements _i2.Widget { + @override + String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) => + super.toString(); +} + +class _FakeQuery_2 extends _i1.Fake + implements _i3.Query {} + +class _FakeMutation_3 extends _i1.Fake + implements _i4.Mutation {} + +class _FakeInheritedElement_4 extends _i1.Fake implements _i2.InheritedElement { + @override + String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) => + super.toString(); +} + +class _FakeDiagnosticsNode_5 extends _i1.Fake implements _i2.DiagnosticsNode { + @override + String toString( + {_i5.TextTreeConfiguration? parentConfiguration, + _i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) => + super.toString(); +} + +class _FakeObject_6 extends _i1.Fake implements Object {} + +/// A class which mocks [QueryBowl]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockQueryBowl extends _i1.Mock implements _i6.QueryBowl { + MockQueryBowl() { + _i1.throwOnMissingStub(this); + } + + @override + Duration get staleTime => (super.noSuchMethod(Invocation.getter(#staleTime), + returnValue: _FakeDuration_0()) as Duration); + @override + Duration get cacheTime => (super.noSuchMethod(Invocation.getter(#cacheTime), + returnValue: _FakeDuration_0()) as Duration); + @override + bool get refetchOnMount => (super + .noSuchMethod(Invocation.getter(#refetchOnMount), returnValue: false) + as bool); + @override + bool get refetchOnReconnect => + (super.noSuchMethod(Invocation.getter(#refetchOnReconnect), + returnValue: false) as bool); + @override + bool get refetchOnExternalDataChange => + (super.noSuchMethod(Invocation.getter(#refetchOnExternalDataChange), + returnValue: false) as bool); + @override + int Function(List) get removeQueries => + (super.noSuchMethod(Invocation.getter(#removeQueries), + returnValue: (List __p0) => 0) as int Function(List)); + @override + void Function() get clear => + (super.noSuchMethod(Invocation.getter(#clear), returnValue: () {}) as void + Function()); + @override + int get isFetching => + (super.noSuchMethod(Invocation.getter(#isFetching), returnValue: 0) + as int); + @override + int get isMutating => + (super.noSuchMethod(Invocation.getter(#isMutating), returnValue: 0) + as int); + @override + _i2.Widget get child => (super.noSuchMethod(Invocation.getter(#child), + returnValue: _FakeWidget_1()) as _i2.Widget); + @override + _i7.Future fetchQuery( + _i8.QueryJob? options, + {Outside? externalData, + _i3.QueryListener? onData, + _i3.QueryListener? onError, + _i2.ValueKey? key}) => + (super.noSuchMethod( + Invocation.method(#fetchQuery, [ + options + ], { + #externalData: externalData, + #onData: onData, + #onError: onError, + #key: key + }), + returnValue: Future.value()) as _i7.Future); + @override + _i3.Query addQuery( + _i8.QueryJob? queryJob, + {Outside? externalData, + _i2.ValueKey? key, + _i3.QueryListener? onData, + _i3.QueryListener? onError}) => + (super.noSuchMethod( + Invocation.method(#addQuery, [ + queryJob + ], { + #externalData: externalData, + #key: key, + #onData: onData, + #onError: onError + }), + returnValue: _FakeQuery_2()) as _i3.Query); + @override + _i4.Mutation addMutation( + _i9.MutationJob? mutationJob, + {_i4.MutationListener? onData, + _i4.MutationListener? onError, + _i4.MutationListener? onMutate, + _i2.ValueKey? key}) => + (super.noSuchMethod( + Invocation.method(#addMutation, [ + mutationJob + ], { + #onData: onData, + #onError: onError, + #onMutate: onMutate, + #key: key + }), + returnValue: _FakeMutation_3()) as _i4.Mutation); + @override + _i3.Query? getQuery( + String? queryKey) => + (super.noSuchMethod(Invocation.method(#getQuery, [queryKey])) + as _i3.Query?); + @override + _i4.Mutation? getMutation(String? mutationKey) => + (super.noSuchMethod(Invocation.method(#getMutation, [mutationKey])) + as _i4.Mutation?); + @override + void setQueryData( + String? queryKey, _i3.QueryUpdateFunction? updateCb) => + super.noSuchMethod(Invocation.method(#setQueryData, [queryKey, updateCb]), + returnValueForMissingStub: null); + @override + void resetQueries(List? queryKeys) => + super.noSuchMethod(Invocation.method(#resetQueries, [queryKeys]), + returnValueForMissingStub: null); + @override + void invalidateQueries(List? queryKeys) => + super.noSuchMethod(Invocation.method(#invalidateQueries, [queryKeys]), + returnValueForMissingStub: null); + @override + _i7.Future refetchQueries(List? queryKeys) => + (super.noSuchMethod(Invocation.method(#refetchQueries, [queryKeys]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i7.Future); + @override + bool updateShouldNotify(_i2.InheritedWidget? oldWidget) => + (super.noSuchMethod(Invocation.method(#updateShouldNotify, [oldWidget]), + returnValue: false) as bool); + @override + _i2.InheritedElement createElement() => + (super.noSuchMethod(Invocation.method(#createElement, []), + returnValue: _FakeInheritedElement_4()) as _i2.InheritedElement); + @override + String toStringShort() => (super + .noSuchMethod(Invocation.method(#toStringShort, []), returnValue: '') + as String); + @override + void debugFillProperties(_i10.DiagnosticPropertiesBuilder? properties) => + super.noSuchMethod(Invocation.method(#debugFillProperties, [properties]), + returnValueForMissingStub: null); + @override + String toStringShallow( + {String? joiner = r', ', + _i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) => + (super.noSuchMethod( + Invocation.method( + #toStringShallow, [], {#joiner: joiner, #minLevel: minLevel}), + returnValue: '') as String); + @override + String toStringDeep( + {String? prefixLineOne = r'', + String? prefixOtherLines, + _i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) => + (super.noSuchMethod( + Invocation.method(#toStringDeep, [], { + #prefixLineOne: prefixLineOne, + #prefixOtherLines: prefixOtherLines, + #minLevel: minLevel + }), + returnValue: '') as String); + @override + _i2.DiagnosticsNode toDiagnosticsNode( + {String? name, _i5.DiagnosticsTreeStyle? style}) => + (super.noSuchMethod( + Invocation.method( + #toDiagnosticsNode, [], {#name: name, #style: style}), + returnValue: _FakeDiagnosticsNode_5()) as _i2.DiagnosticsNode); + @override + List<_i2.DiagnosticsNode> debugDescribeChildren() => + (super.noSuchMethod(Invocation.method(#debugDescribeChildren, []), + returnValue: <_i2.DiagnosticsNode>[]) as List<_i2.DiagnosticsNode>); + @override + String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) => + super.toString(); +} + +/// A class which mocks [QueryJob]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockQueryJobVoidObject extends _i1.Mock + implements _i8.QueryJob { + @override + _i3.QueryTaskFunction get task => + (super.noSuchMethod(Invocation.getter(#task), + returnValue: (String queryKey, void externalData) => + Future.value(_FakeObject_6())) + as _i3.QueryTaskFunction); + @override + set task(_i3.QueryTaskFunction? _task) => + super.noSuchMethod(Invocation.setter(#task, _task), + returnValueForMissingStub: null); + @override + set refetchOnMount(bool? _refetchOnMount) => + super.noSuchMethod(Invocation.setter(#refetchOnMount, _refetchOnMount), + returnValueForMissingStub: null); + @override + set refetchOnReconnect(bool? _refetchOnReconnect) => super.noSuchMethod( + Invocation.setter(#refetchOnReconnect, _refetchOnReconnect), + returnValueForMissingStub: null); + @override + set refetchOnExternalDataChange(bool? _refetchOnExternalDataChange) => + super.noSuchMethod( + Invocation.setter( + #refetchOnExternalDataChange, _refetchOnExternalDataChange), + returnValueForMissingStub: null); + @override + set staleTime(Duration? _staleTime) => + super.noSuchMethod(Invocation.setter(#staleTime, _staleTime), + returnValueForMissingStub: null); + @override + set cacheTime(Duration? _cacheTime) => + super.noSuchMethod(Invocation.setter(#cacheTime, _cacheTime), + returnValueForMissingStub: null); + @override + set refetchInterval(Duration? _refetchInterval) => + super.noSuchMethod(Invocation.setter(#refetchInterval, _refetchInterval), + returnValueForMissingStub: null); + @override + String get queryKey => + (super.noSuchMethod(Invocation.getter(#queryKey), returnValue: '') + as String); +} diff --git a/packages/fl_query_hooks/.flutter-plugins b/packages/fl_query_hooks/.flutter-plugins index a59874f..c789221 100644 --- a/packages/fl_query_hooks/.flutter-plugins +++ b/packages/fl_query_hooks/.flutter-plugins @@ -1,6 +1,6 @@ # This is a generated file; do not edit or check into version control. -connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/ +connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/ connectivity_plus_linux=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/ connectivity_plus_macos=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/ -connectivity_plus_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/ +connectivity_plus_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.3/ connectivity_plus_windows=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/ diff --git a/packages/fl_query_hooks/.flutter-plugins-dependencies b/packages/fl_query_hooks/.flutter-plugins-dependencies index fa3c9a0..f0993c2 100644 --- a/packages/fl_query_hooks/.flutter-plugins-dependencies +++ b/packages/fl_query_hooks/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-07-18 18:16:00.627101","version":"3.0.1"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.3/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-07-19 23:08:04.911997","version":"3.0.1"} \ No newline at end of file diff --git a/packages/fl_query_hooks/lib/src/use_query.dart b/packages/fl_query_hooks/lib/src/use_query.dart index 4461d49..9ff102e 100644 --- a/packages/fl_query_hooks/lib/src/use_query.dart +++ b/packages/fl_query_hooks/lib/src/use_query.dart @@ -43,10 +43,11 @@ Query useQuery({ query.value.prevUsedExternalData != null && !isShallowEqual( query.value.externalData!, query.value.prevUsedExternalData!); - (query.value.fetched && query.value.refetchOnMount == true) || - hasExternalDataChanged - ? query.value.refetch() - : query.value.fetch(); + if (query.value.fetched && hasExternalDataChanged) { + query.value.refetch(); + } else if (!query.value.fetched) { + query.value.fetch(); + } }, [queryBowl, query.value, uKey, onData, onError, job, externalData]); final disposeQuery = useCallback(() {