Skip to content

Problem localizing custom error messages at app level #479

@muratgorken

Description

@muratgorken

Environment

Package version:
^17.0.1

Describe your question

It works correctly when working with hardcoded strings as specified in the example.

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ReactiveFormConfig(
      validationMessages: {
        ValidationMessage.required: (error) => 'Field must not be empty',
        ValidationMessage.email: (error) => 'Must enter a valid email',
      },
      child: MaterialApp(
        home: Scaffold(
          body: const Center(
            child: Text('Hello Flutter Reactive Forms!'),
          ),
        ),
      ),
    );
  }
}

However, when I try to localize with the Intl package, I get an error because the related context has not been created yet.

     ValidationMessage.required: (error) => AppLocalizations.of(context)!.validation_required,
      ValidationMessage.email: (error) => AppLocalizations.of(context)!.validation_email,

it starts to give null because the context material has not yet been created by the app and your app will not load the translations. If you try to use ReactiveFormConfig under the material app, this time the validationMessages property will not be loaded properly and no translations will occur.

Am I doing something wrong or is this how it's supposed to work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions