diff --git a/lib/src/common/domain/language.dart b/lib/src/common/domain/language.dart index 0609ac5..b64de0f 100644 --- a/lib/src/common/domain/language.dart +++ b/lib/src/common/domain/language.dart @@ -1,4 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:portfolio/src/common/domain/icon.dart'; part 'language.freezed.dart'; part 'language.g.dart'; @@ -9,6 +10,7 @@ class Language with _$Language { String? code, String? name, String? nativeName, + IconModel? icon, }) = _Language; factory Language.fromJson(Map json) => diff --git a/lib/src/features/general/presentation/widgets/locale_button.dart b/lib/src/features/general/presentation/widgets/locale_button.dart index 4fcdeb7..73d94f4 100644 --- a/lib/src/features/general/presentation/widgets/locale_button.dart +++ b/lib/src/features/general/presentation/widgets/locale_button.dart @@ -3,6 +3,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:portfolio/src/common/data/language_repository.dart'; +import 'package:portfolio/src/common/widgets/icon.dart'; import 'package:portfolio/src/constants/sizes.dart'; import 'package:portfolio/src/localization/generated/locale_keys.g.dart'; import 'package:portfolio/src/common/domain/language.dart'; @@ -21,14 +22,18 @@ class LocaleButton extends ConsumerWidget { dropdownColor: Theme.of(context).colorScheme.primary, focusNode: FocusNode(canRequestFocus: false), focusColor: Colors.transparent, + underline: const SizedBox.shrink(), items: languages.mapIndexed((index, language) { return DropdownMenuItem( value: Locale(language.code ?? ""), child: Row( children: [ - const Icon(Icons.translate), + MyIcon( + icon: language.icon, + placeholder: const Icon(Icons.translate), + ), gapW8, - _buildLanguageNameText(language), + Text(_getLanguageName(language)), ], ), ); @@ -50,11 +55,11 @@ class LocaleButton extends ConsumerWidget { } } - Text _buildLanguageNameText(Language language) { + String _getLanguageName(Language language) { final languageName = language.name; final languageNativeName = language.nativeName; - if (languageNativeName != null) return Text(languageNativeName); - if (languageName != null) return Text(languageName); - return Text(tr(LocaleKeys.unknownLanguageError)); + if (languageNativeName != null) return languageNativeName; + if (languageName != null) return languageName; + return tr(LocaleKeys.unknownLanguageError); } } diff --git a/lib/src/features/personal_info/presentation/widgets/resume_language_dialog_tile.dart b/lib/src/features/personal_info/presentation/widgets/resume_language_dialog_tile.dart index b4a7107..5c4e980 100644 --- a/lib/src/features/personal_info/presentation/widgets/resume_language_dialog_tile.dart +++ b/lib/src/features/personal_info/presentation/widgets/resume_language_dialog_tile.dart @@ -2,6 +2,8 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:portfolio/src/common/data/language_repository.dart'; +import 'package:portfolio/src/common/widgets/icon.dart'; +import 'package:portfolio/src/constants/sizes.dart'; import 'package:portfolio/src/features/personal_info/domain/resume.dart'; import 'package:portfolio/src/localization/generated/locale_keys.g.dart'; import 'package:portfolio/src/utils/launch_url_helper.dart'; @@ -24,7 +26,11 @@ class ResumeLanguageDialogTile extends ConsumerWidget { children: [ Padding( padding: const EdgeInsets.symmetric(vertical: 16), - child: _buildResumeLanguageText(context, ref, resume: resume), + child: _buildResumeLanguageTileContent( + context, + ref, + resume: resume, + ), ), ], ), @@ -32,25 +38,34 @@ class ResumeLanguageDialogTile extends ConsumerWidget { } } -Text _buildResumeLanguageText( +Widget _buildResumeLanguageTileContent( BuildContext context, WidgetRef ref, { required Resume resume, }) { final languages = ref.watch(languageRepositoryProvider).getLanguages(); final resumeLanguageCode = resume.languageCode; - if (resumeLanguageCode != null) { - final language = languages.firstWhere((language) { - return language.code == resumeLanguageCode; - }); + if (resumeLanguageCode == null) { return Text( - language.name ?? tr(LocaleKeys.unknownLanguageError), + tr(LocaleKeys.unknownLanguageError), style: Theme.of(context).textTheme.titleMedium, ); } - return Text( - tr(LocaleKeys.unknownLanguageError), - style: Theme.of(context).textTheme.titleMedium, + final language = languages.firstWhere((language) { + return language.code == resumeLanguageCode; + }); + return Row( + children: [ + MyIcon( + icon: language.icon, + placeholder: const Icon(Icons.translate), + ), + gapW8, + Text( + language.name ?? tr(LocaleKeys.unknownLanguageError), + style: Theme.of(context).textTheme.titleMedium, + ) + ], ); }