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 {
  _locale = Locale(language, "");

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

  if (restart) {
    // ignore: use_build_context_synchronously
    LocalizedApp.restart(context);
  }
}