periodic staleData refetch functionality
+Query initialData support +Query manual update support +Query.reset support
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import 'package:fl_query/query_bowl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnotherComponent extends StatelessWidget {
|
||||
const AnotherComponent({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final lol = QueryBowl.of(context).getQuery<String>("greetings");
|
||||
if (lol?.data == null) return const CircularProgressIndicator();
|
||||
return Text("${lol!.data!} from AnotherComponent");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:example/another_component.dart';
|
||||
import 'package:fl_query/query_bowl.dart';
|
||||
import 'package:fl_query/query_builder.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -19,7 +20,10 @@ class MyApp extends StatelessWidget {
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: const QueryBowlScope(child: MyHomePage()),
|
||||
home: const QueryBowlScope(
|
||||
staleTime: Duration(seconds: 10),
|
||||
child: MyHomePage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -40,24 +44,38 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
QueryBuilder<String>(
|
||||
queryKey: "greetings",
|
||||
task: (queryKey) => Future.value(
|
||||
"Welcome ($queryKey) ${Random.secure().nextInt(100)}"),
|
||||
builder: (context, query) {
|
||||
if (query.isLoading) return const CircularProgressIndicator();
|
||||
return Row(
|
||||
children: [
|
||||
TextButton(
|
||||
Row(
|
||||
children: [
|
||||
QueryBuilder<String>(
|
||||
queryKey: "greetings",
|
||||
task: (queryKey) => Future.delayed(
|
||||
const Duration(seconds: 2),
|
||||
() =>
|
||||
"Welcome ($queryKey) ${Random.secure().nextInt(100)}"),
|
||||
builder: (context, query) {
|
||||
if (query.isLoading || query.isRefetching) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
return TextButton(
|
||||
child: Text(query.data!),
|
||||
onPressed: () async {
|
||||
await query.refetch();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
QueryBuilder(
|
||||
queryKey: "failure",
|
||||
task: (queryKey) =>
|
||||
Future.value("[$queryKey] Failed for unknown reason"),
|
||||
builder: (context, query) {
|
||||
if (query.hasError) return Text(query.error);
|
||||
return Text("Failure. You're a failure ${query.data}");
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const AnotherComponent(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user