There are various options to change a password through a localized app in a way like that:

MyTextFormField(
  controller: _passwordController,
  obscureText: true,
  labelText: S.of(context).label_newPassword,
  validatorFunction: Validators.validatePassword,
),

and there is a Validator class like that:

class Validators {
    static String validatePassword(String value) {
        if (value.isEmpty) {
          return S.of(MainApp.navKey.currentContext).hint_passwordMissing;
        } else if (value.length > 15 || value.length < 8) {
          return S.of(MainApp.navKey.currentContext).hint_wrongPasswordLength; 
        }
        return null;
      }
    }

That is working but is MainApp.navKey.currentContext the best way to access the context?


Solution 1: derChris

Okay... works this way:

MyTextFormField(
  controller: _passwordController,
  obscureText: true,
  labelText: S.of(context).label_newPassword,
  validatorFunction: (s) => Validators.validatePassword(s, context),
),