value_retriever

Creator: coderz1093

Last updated:

0 purchases

value_retriever Image
value_retriever Images

Languages

Categories

Add to Cart

Description:

value retriever

Value Retriever #



A package that creates a value controller that allows a value to be retrieved
Installation 💻 #
❗ In order to start using Value Retriever you must have the Dart SDK installed on your machine.
Add value_retriever to your pubspec.yaml:
dependencies:
value_retriever:
copied to clipboard
Install it:
dart pub get
copied to clipboard
Usage and motivation ❔ #
Value Retreiver works on a similar way that Value Notifier
in the way that it creates a controlled value, but unlike Valur Notifier, that allows users to
listen for changes, Value Retreiver allows a value to be requested, which will be provided by
any handlers that may be managing it.
An use case example. Imagine we are creating a Flutter app that edits text files, a simplified example would be:
class EditorScaffold extends StatefulWidget {
State createState() => _EditorScaffoldState();
}

class _EditorScaffoldState extends State<EditorScaffold> {
late final _textValue = ValueRetriever<String>();

Future<void> _save() async {
context.read<Repoisoty>().save(
await _textValue.retrieve(),
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Toolbar(
icons: [
SaveIcon(
onPressed: _save,
),
],
),
Expanded(child: EditorView(value: _textValue)),
],
),
);
}
}

class EditorView extends StatefulWidget {

EditorView({ super.key, required this.value });

final ValueRetriever<String> value;

State createState() => _EditorViewState();
}

class _EditorViewState extends State<EditorView> {

String value = '';

@override
void initState() {
super.initState();

widget.value.onRetrivement(_retrieveValue);
}

@override
void dispose() {
widget.value.removeHandler(_retrieveValue);

super.dispose();
}

bool _retrieveValue(Completer<String> completer) {
completer.complete(_value);
return true;
}

@override
Widget build(BuildContext context) {
// omitted
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.