Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a message when changing state #120

Open
rodrigodittrich opened this issue Jun 7, 2024 · 0 comments
Open

Add a message when changing state #120

rodrigodittrich opened this issue Jun 7, 2024 · 0 comments

Comments

@rodrigodittrich
Copy link

rodrigodittrich commented Jun 7, 2024

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.

@rodrigodittrich rodrigodittrich changed the title Adicionar uma mensagem ao mudar o estado Add a message when changing status Jun 7, 2024
@rodrigodittrich rodrigodittrich changed the title Add a message when changing status Add a message when changing state Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant