28 lines
704 B
Dart
28 lines
704 B
Dart
import 'package:flutter/material.dart';
|
|
import 'app_locale.dart';
|
|
|
|
/// App-wide locale; persists selection and notifies [PrediqoApp] to rebuild.
|
|
class LocaleController extends ChangeNotifier {
|
|
Locale _locale = AppLocale.english;
|
|
|
|
Locale get locale => _locale;
|
|
|
|
Future<void> load() async {
|
|
_locale = await AppLocale.loadSaved();
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> setLocale(Locale locale) async {
|
|
if (_locale.languageCode == locale.languageCode) return;
|
|
_locale = locale;
|
|
await AppLocale.save(locale);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> toggleEnFr() async {
|
|
await setLocale(
|
|
_locale.languageCode == 'fr' ? AppLocale.english : AppLocale.french,
|
|
);
|
|
}
|
|
}
|