Localization in Dart/Flutter

Firstly, you need to add flutter_localizations in your pubspec.yaml.

Secondly, create a directory in your flutter project contains json files for your languages like this

I chose English & Arabic

Inside every Json file, you need to have a key and value for every string that you will use in your project

For example, in ar.json I would do that

“Welcome”: “مرحبا”,

but in the en.json, it will have the same key but with different value

“Welcome”: “Welcome”,

Thirdly, you need to create a directory in your lib/flutter project with two files

AppLanguage :


Finally, in your main file, you need to add this

If you need to create a button to use it to change language you can use this code

Note, you need to replace every string in your project with this

You did a great job !!!!!!!!!!

If you like it, share it ❤ ❤ ❤

Flutter Mobile Developer