title: How to get CONTEXT for the provider to work? Flutter
body: <p>In the Future fetchStudentInfo() function, i would like to use the userId from my Auth class to do filtering. The userId is embedded in the URL and it will retrieve data from database. But, the issue is that the context is lacking in the function itself. However, I couldn't figure out a way to pass in the context. It would be great if any legend could help me. The solution which retrieve data from internet is found on the flutter documentation. And i wouldn't like to hard code the userId.</p>
  
  <pre><code>import 'dart:convert';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'package:provider/provider.dart';
  import '../model/student.dart';
  import '../provider/auth.dart';
  
  Future&lt;Student&gt; fetchStudentInfo() async {
    final auth = Provider.of&lt;Auth&gt;(context);
    final response = await http.post(
        'https://intermediary-sharpe.000webhostapp.com/Student/read_one.php?userId=$auth.userId');
  
    if (response.statusCode == 200) {
      return Student.fromJson(json.decode(response.body));
    } else {
      throw Exception('Failed');
    }
  }
  
  class ProfileScreen extends StatefulWidget {
    @override
    _ProfileScreenState createState() =&gt; _ProfileScreenState();
  }
  
  class _ProfileScreenState extends State&lt;ProfileScreen&gt; {
    Future&lt;Student&gt; student;
    @override
    void initState() {
      // TODO: implement initState
  
      super.initState();
      student = fetchStudentInfo();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: FutureBuilder&lt;Student&gt;(
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return Text(snapshot.data.studentId);
            } else if (snapshot.hasError) {
              return Text('${snapshot.error}');
            }
            return CircularProgressIndicator();
          },
          future: student,
        ),
      );
    }
  }
  </code></pre>
  
  <pre><code>import 'package:flutter/cupertino.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  import 'dart:async';
  import 'package:shared_preferences/shared_preferences.dart';
  import '../model/http_exception.dart';
  
  class Auth with ChangeNotifier {
    String _token;
    DateTime _expiryDate;
    String userId;
    Timer _authTimer;
  
    bool get isAuthenticated {
      return token != null;
    }
  
    String get token {
      if (_expiryDate != null &amp;&amp;
          _expiryDate.isAfter(DateTime.now()) &amp;&amp;
          _token != null) {
        return _token;
      }
      return null;
    }
  
    Future&lt;void&gt; _authenticate(
        String email, String password, String urlSegment) async {
      final url =
          'https://identitytoolkit.googleapis.com/v1/accounts:$urlSegment?key=AIzaSyCkNZysDY4PGpScw2jUlBpd0mvpGjgSEag';
      try {
        final response = await http.post(
          url,
          body: json.encode(
            {
              'email': email,
              'password': password,
              'returnSecureToken': true,
            },
          ),
        );
        final responseData = json.decode(response.body);
        if (responseData['error'] != null) {
          throw HttpException(responseData['error']['message']);
        }
        _token = responseData['idToken'];
        userId = responseData['localId'];
        _expiryDate = DateTime.now().add(
          Duration(
            seconds: int.parse(
              responseData['expiresIn'],
            ),
          ),
        );
        _autoLogout();
        notifyListeners();
        final prefs = await SharedPreferences.getInstance();
        final userData = json.encode({
          'token': _token,
          'userId': userId,
          'expiryDate': _expiryDate.toIso8601String(),
        });
        prefs.setString('userData', userData);
      } catch (error) {
        throw error;
      }
    }
  
    //Auto Login Function
    Future&lt;bool&gt; tryAutoLogin() async {
      final prefs = await SharedPreferences.getInstance();
      if (!prefs.containsKey('userData')) {
        return false;
      }
      final extractedUserData =
          json.decode(prefs.getString('userData')) as Map&lt;String, Object&gt;;
      final expiryDate = DateTime.parse(extractedUserData['expiryDate']);
      if (expiryDate.isBefore(DateTime.now())) {
        return false;
      }
      _token = extractedUserData['token'];
      userId = extractedUserData['userId'];
      _expiryDate = expiryDate;
      notifyListeners();
      _autoLogout();
      return true;
    }
  
    //SignUp function
    Future&lt;void&gt; signUp(String email, String password) async {
      return _authenticate(email, password, 'signUp');
    }
  
    //Login Function
    Future&lt;void&gt; login(String email, String password) async {
      return _authenticate(email, password, 'signInWithPassword');
    }
  
    //Logout Function
    Future&lt;void&gt; logout() async {
      _token = null;
      userId = null;
      _expiryDate = null;
      if (_authTimer != null) {
        _authTimer.cancel();
        _authTimer = null;
      }
      notifyListeners();
      final prefs = await SharedPreferences.getInstance();
      prefs.clear();
    }
  
    //Auto Logout function
    void _autoLogout() {
      if (_authTimer != null) {
        _authTimer.cancel();
      }
      final timeToExpiry = _expiryDate.difference(DateTime.now()).inSeconds;
      _authTimer = Timer(Duration(seconds: timeToExpiry), logout);
    }
  
    //PHP related functions
  
  }
  </code></pre>
  
  <p>Thank you in advance.</p>