refactor(example): package specific examples instead of a single example
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
final mutationVariableKeyJob = MutationJob.withVariableKey<String, double>(
|
||||
task: (queryKey, variables) {
|
||||
return Future.value("$variables");
|
||||
},
|
||||
);
|
||||
|
||||
class MutationVariableKeyExample extends StatefulWidget {
|
||||
const MutationVariableKeyExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MutationVariableKeyExample> createState() =>
|
||||
_MutationVariableKeyExampleState();
|
||||
}
|
||||
|
||||
class _MutationVariableKeyExampleState
|
||||
extends State<MutationVariableKeyExample> {
|
||||
late double id;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
id = Random().nextDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"# Mutation Variable Key Example",
|
||||
style: Theme.of(context).textTheme.headline5,
|
||||
),
|
||||
MutationBuilder<String, double>(
|
||||
job: mutationVariableKeyJob("mutation-variable-key#$id"),
|
||||
builder: (context, mutation) {
|
||||
return Row(
|
||||
children: [
|
||||
Text("${mutation.mutationKey} Result: ${mutation.data}"),
|
||||
ElevatedButton(
|
||||
child: const Text("Generate Random Data"),
|
||||
onPressed: () {
|
||||
mutation.mutate(Random().nextDouble());
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text("New Mutation"),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
id = Random().nextDouble();
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user