forked from lichess-org/mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use user defined locale instead of default locale
- Loading branch information
1 parent
c1ddc11
commit 82063f6
Showing
7 changed files
with
61 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:lichess_mobile/src/model/settings/general_preferences.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'current_locale.g.dart'; | ||
|
||
@riverpod | ||
String currentLocale(CurrentLocaleRef ref) { | ||
return ref.watch(generalPreferencesProvider).locale?.languageCode ?? | ||
Intl.getCurrentLocale(); | ||
} | ||
|
||
extension LocaleWidgetRefExtension on WidgetRef { | ||
/// Runs [fn] with the current locale. | ||
T withLocale<T>(T Function(String) fn) { | ||
final currentLocale = watch(currentLocaleProvider); | ||
return fn(currentLocale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters