feat: add initial support for InfiniteQuery

Added new infinite query class with it's own builder widget and integration with query_bowl
The `cast` method used in mutation and query are now a mixin instead of BasicOperation property
This commit is contained in:
Kingkor Roy Tirtho
2022-08-21 20:10:40 +06:00
parent 0c2eae1f11
commit 1452d7d79e
25 changed files with 563 additions and 32 deletions
@@ -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.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-08-07 10:27:39.110033","version":"3.0.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.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-08-21 19:29:44.415263","version":"3.0.5"}
@@ -1,2 +1,2 @@
sdk.dir=/opt/android-sdk
flutter.sdk=/opt/flutter
flutter.sdk=/home/krtirtho/fvm/versions/3.0.5
@@ -1,5 +1,5 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/opt/flutter
FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5
FLUTTER_APPLICATION_PATH=/home/krtirtho/dev/fl-query/packages/fl_query/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=lib/main.dart
@@ -1,6 +1,6 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/opt/flutter"
export "FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5"
export "FLUTTER_APPLICATION_PATH=/home/krtirtho/dev/fl-query/packages/fl_query/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
@@ -0,0 +1,62 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:fl_query/fl_query.dart';
import 'package:http/http.dart' as http;
final infiniteQueryJob = InfiniteQueryJob<Map, void, int>(
queryKey: "infinite-posts",
initialParam: 1,
task: (queryKey, pageParam, externalData) async {
return jsonDecode(
(await http.get(
Uri.parse("https://jsonplaceholder.typicode.com/posts/$pageParam"),
))
.body,
);
},
getNextPageParam: (lastPage, lastParam) {
return lastParam + 1;
},
getPreviousPageParam: (lastPage, lastParam) {
return lastParam - 1;
},
);
class BasicInfiniteQueryExample extends StatelessWidget {
const BasicInfiniteQueryExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: InfiniteQueryBuilder<Map, void, int>(
job: infiniteQueryJob,
externalData: null,
builder: (context, infiniteQuery) {
return Stack(
children: [
ListView.builder(
itemCount: infiniteQuery.pages.length,
itemBuilder: (context, index) {
final page = infiniteQuery.pages[index];
return ListTile(
title: Text(page?["title"] ?? ""),
subtitle: Text(page?["body"] ?? ""),
);
},
),
Align(
alignment: Alignment.bottomRight,
child: IconButton(
icon: const Icon(Icons.get_app_rounded),
onPressed: () => infiniteQuery.fetchNextPage(),
),
),
],
);
}),
);
}
}
+21 -9
View File
@@ -1,3 +1,4 @@
import 'package:fl_query_example/components/basic_infinite_query.dart';
import 'package:fl_query_example/components/basic_mutation.dart';
import 'package:fl_query_example/components/basic_query.dart';
import 'package:fl_query_example/components/lazy_query.dart';
@@ -49,15 +50,26 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: const [
BasicQueryExample(),
QueryExternalDataExample(),
LazyQueryExample(),
QueryVariableKeyExample(),
QueryPreviousDataExample(),
Divider(),
BasicMutationExample(),
MutationVariableKeyExample(),
children: [
const BasicQueryExample(),
const QueryExternalDataExample(),
const LazyQueryExample(),
const QueryVariableKeyExample(),
const QueryPreviousDataExample(),
ListTile(
title: const Text("Infinite Query Example"),
trailing: const Icon(Icons.open_in_new),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const BasicInfiniteQueryExample(),
),
);
},
),
const Divider(),
const BasicMutationExample(),
const MutationVariableKeyExample(),
],
),
)),
@@ -1,10 +1,10 @@
# Generated code do not commit.
file(TO_CMAKE_PATH "/opt/flutter" FLUTTER_ROOT)
file(TO_CMAKE_PATH "/home/krtirtho/fvm/versions/3.0.5" FLUTTER_ROOT)
file(TO_CMAKE_PATH "/home/krtirtho/dev/fl-query/packages/fl_query/example" PROJECT_DIR)
# Environment variables to pass to tool_backend.sh
list(APPEND FLUTTER_TOOL_ENVIRONMENT
"FLUTTER_ROOT=/opt/flutter"
"FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5"
"PROJECT_DIR=/home/krtirtho/dev/fl-query/packages/fl_query/example"
"DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
"DART_OBFUSCATION=false"
@@ -1,5 +1,5 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/opt/flutter
FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5
FLUTTER_APPLICATION_PATH=/home/krtirtho/dev/fl-query/packages/fl_query/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_BUILD_DIR=build
@@ -1,6 +1,6 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/opt/flutter"
export "FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5"
export "FLUTTER_APPLICATION_PATH=/home/krtirtho/dev/fl-query/packages/fl_query/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_BUILD_DIR=build"
+16 -2
View File
@@ -133,7 +133,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.0"
version: "0.2.0"
flutter:
dependency: "direct main"
description: flutter
@@ -170,6 +170,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1"
infinite_scroll_pagination:
dependency: "direct main"
description:
name: infinite_scroll_pagination
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
js:
dependency: transitive
description:
@@ -238,6 +245,13 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
sliver_tools:
dependency: transitive
description:
name: sliver_tools
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.7"
source_span:
dependency: transitive
description:
@@ -310,4 +324,4 @@ packages:
version: "6.1.0"
sdks:
dart: ">=2.17.1 <3.0.0"
flutter: ">=1.20.0"
flutter: ">=1.22.0"
+1
View File
@@ -36,6 +36,7 @@ dependencies:
cupertino_icons: ^1.0.2
fl_query: ^0.2.0
http: ^0.13.5
infinite_scroll_pagination: ^3.2.0
dev_dependencies:
flutter_test: