title: How to handle validation and navigation situation on Cubit right way?
body: <p>In my application I have <code>AddServerScreen</code> Page which allows me to add Servers to Cubit. The server object has two properties, alias and address. If the alias of the server to be added matches one of the servers kept in Cubit, I do not add the server and show an error message to the user. But if it's not already added, I add the server to Cubit and go back to the home page.</p>
  <p>My question is, Is Cubit supposed to do the validation and <code>Navigator.pop(context)</code> here? If I do all this in the UI Cubit will have to return <code>Future</code> from the function and that just doesn't feel right. I need to solve this problem the right way.</p>
  <p>I will share simplified <code>ServerState</code> and <code>ServerCubit</code> down below.</p>
  <p>ServerState:</p>
  <pre><code>class ServerState {
    final List&lt;Server&gt; servers;
    const ServerState(this.servers);
  }
  </code></pre>
  <p>ServerCubit:</p>
  <pre><code>class ServerCubit extends Cubit&lt;ServerState&gt; {
    ServerCubit() : super(const ServerState([]));
  
    void addServer(String address, String alias) {
      List&lt;Server&gt; same = state.servers.where((e) =&gt; e.alias == alias).toList();
      if (same.isEmpty) {
        Server server = Server(address, alias);
        emit(ServerState([...state.servers, server]));
      }
    }
  }
  </code></pre>