forked from escamoteur/flutter_command
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I discovered your package by following the Clean Architecture suggestions in the official Flutter documentation. The command-objects case study specifically recommended flutter_command, which led me to your work.
1. That official doc proposed a Command pattern implementation that works with the Result class pattern:
// in ViewModel
HomeViewModel({
required BookingRepository repo,
}) : _repo = repo {
loadCommand = Command0(_function)..execute();
late Command0 loadCommand;
Future<Result> _function() async {
final result = await _repo.getBookingsList();
switch (result) {
case Ok<SomeDataClass>():
....
case Error<SomeDataClass>():
....
}
return result;
}// in View
ListenableBuilder(
listenable: widget.viewModel.load,
builder: (context, child) {
if (widget.viewModel.loadCommand.running) {
return const CircularProgressIndicator();
}
if (widget.viewModel.loadCommand.error) {
...
}
if (widget.viewModel.loadCommand.completed) {
// here
}
return child!;
},
)- Command library here internally implements the Result class: https://github.com/flutter/samples/blob/main/compass_app/app/lib/utils/command.dart
2. The way I see result pattern works with command_it is by returning Sucess.value and throwing Failure.value:
HomeViewModel({
required BookingRepository repo,
}) : _repo = repo {
commandResult = Command.createAsyncNoParam(
_function,
initialValue: ,
);
}
Future<SomeDataClass> _function() async {
final Result<SomeDataClass> result = await _repo.getBookingsList();
switch (result) {
case Ok<SomeDataClass>():
....
return result.value; <---
case Error<SomeDataClass>():
....
throw '${result.error}' <---
}
}However, I'm quite skeptical about this workaround long-term viability. I'm hoping for some insight for robust design pattern (Command and Result).
Lastly, kudos on your work! I'm slowly adapting flutter-it
Metadata
Metadata
Assignees
Labels
No labels