Frontend first draft
This commit is contained in:
29
frontend/pshared/lib/provider/locale.dart
Normal file
29
frontend/pshared/lib/provider/locale.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/config/constants.dart';
|
||||
|
||||
|
||||
class LocaleProvider with ChangeNotifier {
|
||||
Locale _locale = Constants.defaultLocale;
|
||||
|
||||
Locale stringToLocale(String localeString) {
|
||||
var parts = localeString.split(RegExp(r'[-_]'));
|
||||
return (parts.length > 1) ? Locale(parts[0], parts[1]) : Locale(parts[0]);
|
||||
}
|
||||
|
||||
LocaleProvider(String? localeCode) {
|
||||
if (localeCode != null) {
|
||||
_locale = stringToLocale(localeCode);
|
||||
}
|
||||
}
|
||||
|
||||
Locale get locale => _locale;
|
||||
|
||||
void setLocale(Locale locale) {
|
||||
if (_locale == locale) return;
|
||||
|
||||
_locale = locale;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user