title: Display error message outside build widget
body: <p>I am using a Model class to authenticate user before registering or logging.the problem is that i don't know a way to print error message to the user in snackbar,because no widget is defined in this class.</p>
  <p>How can i display error message to user from Model Class?</p>
  <p>Model class:</p>
  <pre><code>class FireAuth {
  
  
    static Future&lt;User&gt; registerUsingEmailPassword({
       String name,
       String email,
       String password,
    }) async {
      FirebaseAuth auth = FirebaseAuth.instance;
  
      User user;
  
      try {
        UserCredential userCredential = await auth.createUserWithEmailAndPassword(
          email: email,
          password: password,
        );
  
        user = userCredential.user;
        await user.updateDisplayName(name);
        await user.reload();
        user = auth.currentUser;
  
        //check if email is registered before
  
        //add user data to firestore
        CollectionReference users = FirebaseFirestore.instance.collection('users');
        users.doc(user.uid).set({
          'uid':user.uid,
          'img_url':'0',
          'name': name,  
          'phone': '',  
          'email': email, 
          'job_title':'',
          'university':'',
          'procedures':'',
          'expert_in':'',
  
        })
            .then((value) =&gt; print(&quot;User Added&quot;))
            .catchError(
                (error) =&gt; print(&quot;Failed to add user: $error&quot;));
  
  
      } on FirebaseAuthException catch (e) {
        if (e.code == 'weak-password') {
          print('The password provided is too weak.');
        } else if (e.code == 'email-already-in-use') {
          print('The account already exists for that email.');
  
  
        }
      } catch (e) {
        print(e);
      }
  
      return user;
    }
  }
  </code></pre>
  <p>I need <code>'The account already exists for that email.'</code>  error message to display to user,not only printing it in log.</p>