Skip to content

Commit

Permalink
Adding default option to lang
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoazvd17 committed Dec 6, 2023
1 parent 6478db2 commit 7adfee6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/src/core/data/enums/supported_languages.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

enum SupportedLanguages {
system,
english,
portuguese,
}

extension SupportedLanguagesExtension on SupportedLanguages {
Widget get icon {
return switch (this) {
SupportedLanguages.system => const Icon(CupertinoIcons.settings),
SupportedLanguages.english => Image.asset(
'assets/icons/languages/en.png',
width: 24,
Expand All @@ -23,13 +24,15 @@ extension SupportedLanguagesExtension on SupportedLanguages {

String title(BuildContext context) {
return switch (this) {
SupportedLanguages.system => AppLocalizations.of(context)!.system,
SupportedLanguages.english => AppLocalizations.of(context)!.english,
SupportedLanguages.portuguese => AppLocalizations.of(context)!.portuguese,
};
}

Locale get locale {
Locale? get locale {
return switch (this) {
SupportedLanguages.system => null,
SupportedLanguages.english => const Locale('en'),
SupportedLanguages.portuguese => const Locale('pt'),
};
Expand Down
9 changes: 7 additions & 2 deletions lib/src/core/presentation/controllers/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ abstract class AppControllerBase with Store {
SupportedLanguages? _selectedLanguage;
SupportedLanguages? get selectedLanguage => _selectedLanguage;
void changeLanguage(SupportedLanguages? language) {
_selectedLanguage = language;
_storage.saveLanguage(language);
if (language == SupportedLanguages.system) {
_selectedLanguage = null;
_storage.saveLanguage(null);
} else {
_selectedLanguage = language;
_storage.saveLanguage(language);
}
}

@observable
Expand Down

0 comments on commit 7adfee6

Please sign in to comment.