title: Provider: How to notify listeners of A from B
body: <p>I have two controllers using the changenotifiers in my app and I want to notify listeners of A from B. I have be trying two different methods for the same.</p>
  <p><strong>Method 1</strong></p>
  <p>(Controller A):</p>
  <pre><code>class DrawController extends ChangeNotifier {
  
     void clearCanvas() {
     selectedText = '';
     shouldClearCanvas = true;
     currentDrawPoints.initialPoint = null;
     currentDrawPoints.endPoint = null;
     print(currentDrawPoints.initialPoint);
     notifyListeners();
     }
  }
  </code></pre>
  <p>Calling it from (Controller B):</p>
  <pre><code>class GameController extends ChangeNotifier {
  
    DrawController drawController = DrawController();
  
    void someFunction(){
  
       drawController.clearCanvas();
       notifyListeners();
  
     }
  
  }
  </code></pre>
  <p><strong>The above method doesn't work.</strong> It does execute the function and changes the value but it does not change the UI (does not rebuild the widget).</p>
  <p><strong>Method 2:</strong></p>
  <p>(Controller A):</p>
  <pre><code>class DrawController extends ChangeNotifier {
  
     void clearCanvas() {
     selectedText = '';
     shouldClearCanvas = true;
     currentDrawPoints.initialPoint = null;
     currentDrawPoints.endPoint = null;
     print(currentDrawPoints.initialPoint);
     notifyListeners();
     }
  }
  </code></pre>
  <p>Calling it from (Controller B):</p>
  <pre><code>class GameController extends ChangeNotifier {
  
    DrawController drawController = DrawController();
  
    void someFunction(BuildContext context){
  
       Provider.of&lt;DrawController&gt;(context, listen: false).clearCanvas();
  
     }
  
  }
  </code></pre>
  <p>This second method works and it updates the UI too but I think this is the wrong method of doing it.</p>
  <p>As using it after async await gives the warning &quot;Do not use BuildContexts across async gaps.&quot;</p>
  <pre><code>  class GameController extends ChangeNotifier {
  
    DrawController drawController = DrawController();
  
    void someFunction(BuildContext context) async {
  
       User? userData = await localStorage.getUserData();   
  
       Provider.of&lt;DrawController&gt;(context, listen: false)
        .clearCanvas(); //Gives warning &quot;Do not use BuildContexts across async gaps.&quot;
  
     }
  
  }
  </code></pre>
  <p>Can anyone tell me the correct way of doing it.</p>