Show Two Languages at once

Viewed 137

Fisrt of all i am following this guide for localization which is the official guideline of flutter but at

AppLocalizations.of(context)!.helloWorld

It gives error as null

I think this is maybe because I recently updated flutter to 2.10 please confirm if that is the case

I want to achieve this kind of results like English on right and Urdu Language of Left which i don't know how to do that because in samples and guides they just show how to change overall app language not just for some strings

enter image description here

Also for time being, I have used easy_localization: 3.0.0 but still the problem is how i support multiple language at once with this package

1 Answers
  1. Don't use localization for this part - drawer widget - text items
  2. wrap drawer widget with Directionality widget to prevent it from mirroring and make text in the same place.
  3. pop the drawer after using switch widget.

Example:

import 'package:flutter/material.dart' as ltr;


drawer: Directionality(
    textDirection: ltr.TextDirection.ltr,
    child: Container(
      color: Colors.lightGreen,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('English'),
              Text('عربي'),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('English'),
              Text('عربي'),
            ],
          ),
        ],
      ),
    ),
  ),
Related