setLanguage method

Future<void> setLanguage(
  1. BuildContext context, {
  2. required String language,
  3. bool restart = true,
})

changes active language

Implementation

Future<void> setLanguage(
  BuildContext context, {
  required String language,
  bool restart = true,
}) async {
  if (language == "") {
    language = _locale?.languageCode ?? _langList[0];
  }

  _locale = Locale(language, "");

  String filePath = "$_assetsDir$language.json";
  String content = await rootBundle.loadString(filePath);

  _values = json.decode(content);

  if (restart) {
    LocalizedApp.restart(context);
  }
}