I am working on a flutter application and I have an Inherited Widget class. There is a function in my InheritedWidget Class which needs to access BuildContext. Is it possible to access context(BuildContext) from widget object? If yes, what are the ways to access it.
class ApiClient extends InheritedWidget{
final String baseUrl;
ApiClient({
@required this.baseUrl,
@required Widget child
}):super(child:child);
static ApiClient of(BuildContext context) {
return context.inheritFromWidgetOfExactType(ApiClient);
}
Future<http.Response> login(String email, String password){
Map<String, String> body = {
"username":email,
"password":password,
"client_secret": //This I want to read from an EnvironmentConfig
//file which is also an InheritedWidget And In order to read that I need context,
};
return _network.post(baseUrl+ApiEndpoints.LOGIN, body:json.encode(body), headers: ApiHeaders.headers);
}
@override
bool updateShouldNotify(InheritedWidget oldWidget) => false;
}