Aiman
Aiman

Reputation: 151

Flutter App Localization, using Provider without context

I have this provider with a data.

@riverpod
class OnboardPageData extends _$OnboardPageData {
  @override
  List<OnboardPageModel> build() {
    final introDataList = [
      OnboardPageModel(
        title: 'Book Your Load',
        description:
            "Learn, grow, and succeed with our app's diverse educational resources, interactive lessons, and personalized learning experiences.",
        image: Assets.pngs.ob2image.path,
      ),
      OnboardPageModel(
        title: 'Use AI To Boost Match',
        description:
            'Unlock your potential with interactive courses and expert instructors at your fingertips.',
        image: Assets.pngs.ob3image.path,
      ),
    ];

    return introDataList;
  }
}

What I want is to define the translation here, but there is no context here.

My arb file:

app_en.arb

{
  "useAIToBoostMatch": "Use AI To Boost Match",
  "earnAndSeeReports": "Earn & See Reports",
  "soloDriver": "You can own your vehicle and become a solo driver.",
  "learnGrowSucceed": "Learn, grow, and succeed with our app's diverse educational resources, interactive lessons, and personalized learning experiences.",
  "unlockPotential": "Unlock your potential with interactive courses and expert instructors at your fingertips.",
 "learnAnytimeAnywhere": "Learn anytime, anywhere, with a vast library of educational content and personalized study plans.",

}

Normally, we call the localization like this:

AppLocalizations.of(context)!.hello

I also modified the provider by following the keys like this:

  OnboardPageModel(
      title: 'joinIndividuallyOrFleet',
      description: 'soloDriver',
      image: Assets.pngs.ob1image.path,
  ),

But still it doesn't resolved.

Upvotes: 0

Views: 70

Answers (0)

Related Questions