Skip to content

Commit

Permalink
feat: add country flags
Browse files Browse the repository at this point in the history
  • Loading branch information
AladdineDev committed Feb 11, 2024
1 parent 4cc5f9e commit 6c375b0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/src/common/domain/language.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,6 +10,7 @@ class Language with _$Language {
String? code,
String? name,
String? nativeName,
IconModel? icon,
}) = _Language;

factory Language.fromJson(Map<String, dynamic> json) =>
Expand Down
17 changes: 11 additions & 6 deletions lib/src/features/general/presentation/widgets/locale_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<Locale>(
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)),
],
),
);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,33 +26,46 @@ class ResumeLanguageDialogTile extends ConsumerWidget {
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: _buildResumeLanguageText(context, ref, resume: resume),
child: _buildResumeLanguageTileContent(
context,
ref,
resume: resume,
),
),
],
),
);
}
}

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,
)
],
);
}

Expand Down

0 comments on commit 6c375b0

Please sign in to comment.