cache time & garbage collection support added
onData & onError callbacks WIP
This commit is contained in:
@@ -7,7 +7,11 @@ class AnotherComponent extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final lol = QueryBowl.of(context).getQuery<String, void>("greetings");
|
||||
final deadQuery =
|
||||
QueryBowl.of(context).getQuery<String, String>("external_data");
|
||||
if (lol?.data == null) return const CircularProgressIndicator();
|
||||
return Text("${lol!.data!} from AnotherComponent");
|
||||
return Text(
|
||||
"${lol!.data!} from AnotherComponent\nDeadQuery (It should be null after 10 seconds): ${deadQuery?.data}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,18 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
final successJob = QueryJob<String, void>(
|
||||
queryKey: "greetings",
|
||||
task: (queryKey, _) => Future.delayed(const Duration(seconds: 2),
|
||||
() => "Welcome ($queryKey) ${Random.secure().nextInt(100)}"));
|
||||
queryKey: "greetings",
|
||||
task: (queryKey, _) => Future.delayed(const Duration(seconds: 2),
|
||||
() => "Welcome ($queryKey) ${Random.secure().nextInt(100)}"),
|
||||
);
|
||||
|
||||
final failedJob = QueryJob<String, void>(
|
||||
queryKey: "failure",
|
||||
task: (queryKey, _) => Random().nextBool()
|
||||
? Future.error("[$queryKey] Failed for unknown reason")
|
||||
: Future.value("Success, you'll get slowly ${Random().nextInt(100)}!"),
|
||||
: Future.value(
|
||||
"Success, you'll get slowly ${Random().nextInt(100)}!",
|
||||
),
|
||||
);
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
@@ -97,7 +100,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
children: [
|
||||
if (query.hasError)
|
||||
Text(
|
||||
"${query.error}. Retrying: ${query.retryAttempts}"),
|
||||
"${query.error}. Retrying: ${query.retryAttempts}",
|
||||
),
|
||||
if (query.hasData)
|
||||
Text(
|
||||
"Success after ${query.retryAttempts}. Data: ${query.data}"),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
final jobWithExternalData = QueryJob<String, String>(
|
||||
queryKey: "external_data",
|
||||
cacheTime: const Duration(seconds: 10),
|
||||
task: (queryKey, data) {
|
||||
return Future.delayed(const Duration(milliseconds: 500),
|
||||
() => "Hello from $queryKey with $data");
|
||||
|
||||
Reference in New Issue
Block a user