triple_pattern
triple_pattern copied to clipboard
Add a message when changing state
Project Name triple
Is your feature request related to a problem? Please describe.
Suggestion for assigning a message when the state changes. With this, it is possible to simply display a snackbar when the state changes.
my controller:
class PersonController extends Store<List<PersonEntity>> {
//....Use Cases
//....Constructor
//....Variables
Future insert() async {
//.....
//Insert person in list
setMessage('Person inserted successfully');
update(persons);
}
Future update() async {
//.....
//Update person list
setMessage('Person updateded successfully');
update(clientes);
}
Future delete() async {
//.....
//Remove person from list
setMessage('Person deleted successfully')
update(persons);
}
}
observer on my page:
controller.observer(
onLoading: (loading) => onLoading(loading),
onError: (error) => showError(error.message),
onState: (state, message) => onState(state, message)
);
void onState(state, message) {
//Implements;
showMessage(message),
}
A second suggestion:
- Deprecate onError and add onMessage Message can be used as error messages or success messages.
Exemplo:
Controller:
Future update() async {
setLoading(true);
final result = await _updatePersonUseCase(person: personEntity);
result.fold(
(success) {
persons.add(personEntity);
update(persons);
setMessage(PersonUpdatedEvent('Person updateded successfully'));
},
(failure) => setMessage(failure)
);
setLoading(false);
}
Page:
controller.observer(
onLoading: (loading) => onLoading(loading),
onMessage: (message) => onMessage(message),
onState: (state) => print(state)
);
void onMessage(message) {
if(message is PersonUpdatedEvent) {
showSucess(message.message);
}
if(message is PersonException) {
showError(message.message);
}
}
Note: It is possible to show error or success messages using the onError property, but it is conditioned more on errors.