I'm using flutter_localizations.dart package to Localize my App in different Languages. Usually, I use S.of(context).wordToLocalize
to call the String according to each language.
However, in the login process, I have no context, so I cannot use the same procedure. I I have the following error:
Undefined name 'context'. Try correcting the name to one that is defined, or defining the name.
The code where I need to use it, is as follows
import 'dart:async';
import 'package:aplians_fish/generated/l10n.dart';
class Validators {
final validarEmail = StreamTransformer<String, String>.fromHandlers(
handleData: (email, sink) {
Pattern pattern = r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regExp = new RegExp(pattern);
if (regExp.hasMatch(email)) {
sink.add(email);
} else {
sink.addError('It must be a valid e-mail');
// I would like to change the previous line for S.of(context).validEmail
}
}
);
How can I call Flutter Localization in this code?