title: Flutter throws error when context is passed to a Provider from the init method
body: <p>I have a MainScreen (stateful) with the following method:</p>
  
  <pre><code>@override
    void initState() {
      super.initState();
      WidgetsBinding.instance
          .addPostFrameCallback((_)  async {
            loadFirebaseUser(context);
          });
    }
  </code></pre>
  
  <p>My 'loadFirebaseUser' method is in another file called Constants.dart which can be used from any screen.
  The function is as follows:</p>
  
  <pre><code>Future&lt;bool&gt; loadFirebaseUser(BuildContext context) async {
    Auth _auth = Auth();
    FirebaseUser cUser = await _auth.currentUser();
    if (cUser.isEmailVerified) {
      DocumentSnapshot snapshot = await Firestore.instance
          .collection('Profile')
          .document(cUser.uid)
          .get();
      if (snapshot.data != null) {
        User user = Provider.of&lt;UserData&gt;(context).getUser();
        user = User.fromMap(snapshot);
        Provider.of&lt;UserData&gt;(context).setUser(user);
        return true;
      } else {
        return false;
      }
    }
    return false;
  }
  </code></pre>
  
  <p>I am getting the follwing error when this code is executed:</p>
  
  <pre><code>Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
  </code></pre>
  
  <p>Needless to say that as result of this the user is not getting loaded. The error points to the following line:</p>
  
  <pre><code>User user = Provider.of&lt;UserData&gt;(context).getUser();
  </code></pre>
  
  <p>I want the 'loadFirebaseUSer' function to execute automatically and not on any button click, so this is the only place I know to place this code. Is there a way to achieve this differently? Thanks</p>