-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor streamline source language selection #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1e174f
feat(dependencies): add language_picker and update pubspec.lock
fulleni 71c334f
feat(shared): add language adapter for picker integration
fulleni 84b229b
feat(shared): create language picker and export shared components
fulleni 3a67f49
feat(content): adapt create source bloc for language picker
fulleni a84b878
feat(content): integrate language picker into create source page
fulleni 832bf5c
feat(content): adapt edit source bloc for language picke
fulleni 2548e74
feat(content): integrate language picker into edit source page
fulleni a5afe50
fix(shared): implement correct LanguagePickerFormField using showDialog
fulleni e117965
fix(content): finalize language picker integration
fulleni 0ffd856
fix(content_management): add missing import for MaterialApp
fulleni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
import 'package:language_picker/languages.dart'; | ||
|
||
/// Adapts a [Language] object from the `language_picker` package to a | ||
/// language code string (e.g., 'en', 'ar'). | ||
/// | ||
/// This is used to convert the selected language from the UI picker into the | ||
/// format expected by the `Source` model in the core package. | ||
String adaptPackageLanguageToLanguageCode(Language language) { | ||
return language.isoCode; | ||
} | ||
|
||
/// Adapts a language code string (e.g., 'en', 'ar') to a [Language] object | ||
/// from the `language_picker` package. | ||
/// | ||
/// This is used to convert the language code from a `Source` model into an | ||
/// object that can be used to set the initial value of the language picker. | ||
/// | ||
/// Returns `null` if the language code is not found. | ||
Language? adaptLanguageCodeToPackageLanguage(String languageCode) { | ||
try { | ||
return Languages.defaultLanguages.firstWhere( | ||
(lang) => lang.isoCode.toLowerCase() == languageCode.toLowerCase(), | ||
); | ||
} catch (_) { | ||
// Return null if no matching language is found | ||
return null; | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'country_adapter.dart'; | ||
export 'language_adapter.dart'; |
This file contains hidden or 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,73 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:language_picker/language_picker.dart'; | ||
import 'package:language_picker/languages.dart'; | ||
|
||
/// A form field for selecting a language using the `language_picker` package. | ||
/// | ||
/// This widget wraps the language picker functionality in a standard | ||
/// [FormField], making it easy to integrate into forms for validation | ||
/// and state management. It presents as a read-only [TextFormField] that, | ||
/// when tapped, opens a language selection dialog. | ||
class LanguagePickerFormField extends FormField<Language> { | ||
/// Creates a [LanguagePickerFormField]. | ||
/// | ||
/// The [onSaved], [validator], [initialValue], and [autovalidateMode] are | ||
/// standard [FormField] properties. | ||
/// | ||
/// The [labelText] is displayed as the input field's label. | ||
/// The [onChanged] callback is invoked when a new language is selected. | ||
LanguagePickerFormField({ | ||
super.key, | ||
super.onSaved, | ||
super.validator, | ||
super.initialValue, | ||
super.autovalidateMode, | ||
String? labelText, | ||
void Function(Language)? onChanged, | ||
}) : super( | ||
builder: (FormFieldState<Language> state) { | ||
// This controller is just for displaying the text. The actual | ||
// value is managed by the FormField's state. | ||
final controller = TextEditingController( | ||
text: state.value?.name, | ||
); | ||
|
||
// Helper to build a simple list item for the dialog. | ||
Widget buildDialogItem(Language language) => Row( | ||
children: <Widget>[ | ||
Text(language.name), | ||
const SizedBox(width: 8), | ||
Flexible(child: Text('(${language.isoCode})')), | ||
], | ||
); | ||
|
||
void openLanguagePickerDialog() { | ||
showDialog<void>( | ||
context: state.context, | ||
builder: (context) => LanguagePickerDialog( | ||
isSearchable: true, | ||
title: const Text('Select your language'), | ||
onValuePicked: (Language language) { | ||
state.didChange(language); | ||
onChanged?.call(language); | ||
controller.text = language.name; | ||
}, | ||
itemBuilder: buildDialogItem, | ||
), | ||
); | ||
} | ||
|
||
return TextFormField( | ||
controller: controller, | ||
readOnly: true, | ||
decoration: InputDecoration( | ||
labelText: labelText ?? 'Language', | ||
border: const OutlineInputBorder(), | ||
errorText: state.errorText, | ||
suffixIcon: const Icon(Icons.arrow_drop_down), | ||
), | ||
onTap: openLanguagePickerDialog, | ||
); | ||
}, | ||
); | ||
} | ||
fulleni marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'country_picker_form_field.dart'; | ||
export 'language_picker_form_field.dart'; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.