Files
syncrow-app/lib/helpers/localization_helpers.dart
Mohammad Salameh 84e142a099 initial commit
2024-02-14 10:58:43 +03:00

28 lines
935 B
Dart

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'constants.dart';
class LocalizationService {
static saveLocale(Locale locale) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("Locale Language Code", locale.languageCode);
if (locale.countryCode != null) {
await prefs.setString("Locale Country Code", locale.countryCode!);
}
}
static Future<Locale> savedLocale() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var savedLanguageCode = prefs.getString(KeyConstants.languageCode);
var savedCountryCode = prefs.getString(KeyConstants.countryCode);
var savedLocale = const Locale("ar", "JO");
if (savedCountryCode != null && savedLanguageCode != null) {
savedLocale = Locale(savedLanguageCode, savedCountryCode);
}
return savedLocale;
}
}