I have the function below, I want to access the context globally and I don't know if it's a good idea, I'm getting the context from the Application, I have TestAppliction in the test environment and I don't have access to the Application class, so I decided to add an optional context parameter to my function.
String getErrorMessage(DioError error, {BuildContext context}) {
String rawMessage = _getAnalyzedMessage(error);
GlobalKey navKey = Application.navKey;
if (navKey != null && navKey.currentContext != null)
context = Application.navKey.currentContext;
if (context != null)
return AppLocalizations.of(context).translate(rawMessage);
else
return rawMessage;
}
Is this a good idea?