mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Hide the translation fields, not all users will need this
This commit is contained in:
@@ -584,6 +584,7 @@
|
||||
"language": "Language",
|
||||
"addExercise": "Add exercise",
|
||||
"translation": "Translation",
|
||||
"translateExercise": "Translate this exercise now",
|
||||
"baseData": "Basics in English",
|
||||
"@baseData": {
|
||||
"description": "The base data for an exercise such as category, trained muscles, etc."
|
||||
|
||||
@@ -24,10 +24,10 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
String? _nameTranslation;
|
||||
String? _descriptionEn;
|
||||
String? _descriptionTranslation;
|
||||
Language? _language;
|
||||
late Language _language;
|
||||
List<String> _alternativeNamesEn = [];
|
||||
List<String> _alternativeNamesTranslation = [];
|
||||
ExerciseCategory? _category;
|
||||
late ExerciseCategory _category;
|
||||
List<ExerciseBase> _variations = [];
|
||||
List<Equipment> _equipment = [];
|
||||
List<Muscle> _primaryMuscles = [];
|
||||
@@ -44,10 +44,8 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
_nameTranslation = null;
|
||||
_descriptionEn = null;
|
||||
_descriptionTranslation = null;
|
||||
_language = null;
|
||||
_alternativeNamesEn = [];
|
||||
_alternativeNamesTranslation = [];
|
||||
_category = null;
|
||||
_variations = [];
|
||||
_equipment = [];
|
||||
_primaryMuscles = [];
|
||||
@@ -64,9 +62,9 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
set equipment(List<Equipment> equipment) => _equipment = equipment;
|
||||
List<Equipment> get equipment => [..._equipment];
|
||||
set category(ExerciseCategory category) => _category = category;
|
||||
ExerciseCategory get category => _category!;
|
||||
ExerciseCategory get category => _category;
|
||||
set language(Language language) => _language = language;
|
||||
Language get language => _language!;
|
||||
Language get language => _language;
|
||||
|
||||
ExerciseBase get base {
|
||||
return ExerciseBase(
|
||||
@@ -130,7 +128,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
|
||||
log('');
|
||||
log('Language specific...');
|
||||
log('Language: ${_language?.shortName}');
|
||||
log('Language: ${_language.shortName}');
|
||||
log('Name: en/$_nameEn translation/$_nameTranslation');
|
||||
log('Description: en/$_descriptionEn translation/$_descriptionTranslation');
|
||||
log('Alternate names: en/$_alternativeNamesEn translation/$_alternativeNamesTranslation');
|
||||
@@ -142,24 +140,31 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
// Create the base
|
||||
final base = await addExerciseBase();
|
||||
|
||||
// Set the variations
|
||||
// Create the variations
|
||||
// ...
|
||||
|
||||
// Create the translations
|
||||
// Create the base description in English
|
||||
Exercise exerciseTranslationEn = exerciseEn;
|
||||
exerciseTranslationEn.base = base;
|
||||
exerciseTranslationEn = await addExerciseTranslation(exerciseTranslationEn);
|
||||
for (final alias in _alternativeNamesEn) {
|
||||
exerciseTranslationEn.alias.add(await addExerciseAlias(alias, exerciseTranslationEn.id!));
|
||||
if (alias.isNotEmpty) {
|
||||
exerciseTranslationEn.alias.add(await addExerciseAlias(alias, exerciseTranslationEn.id!));
|
||||
}
|
||||
}
|
||||
|
||||
Exercise exerciseTranslationLang = exerciseTranslation;
|
||||
exerciseTranslationLang.base = base;
|
||||
exerciseTranslationLang = await addExerciseTranslation(exerciseTranslationLang);
|
||||
for (final alias in _alternativeNamesTranslation) {
|
||||
exerciseTranslationLang.alias.add(await addExerciseAlias(alias, exerciseTranslationLang.id!));
|
||||
// Create the translations
|
||||
if (_nameTranslation != null && _descriptionTranslation != null) {
|
||||
Exercise exerciseTranslationLang = exerciseTranslation;
|
||||
exerciseTranslationLang.base = base;
|
||||
exerciseTranslationLang = await addExerciseTranslation(exerciseTranslationLang);
|
||||
for (final alias in _alternativeNamesTranslation) {
|
||||
exerciseTranslationLang.alias.add(
|
||||
await addExerciseAlias(alias, exerciseTranslationLang.id!),
|
||||
);
|
||||
}
|
||||
await addExerciseTranslation(exerciseTranslationLang);
|
||||
}
|
||||
await addExerciseTranslation(exerciseTranslationLang);
|
||||
|
||||
// Create the images
|
||||
await addImages(base);
|
||||
|
||||
@@ -32,7 +32,7 @@ abstract class ValidateStep {
|
||||
}
|
||||
|
||||
/// The amount of characters an exercise description needs to have
|
||||
const MIN_CHARS_DESCRIPTION = 4;
|
||||
const MIN_CHARS_DESCRIPTION = 40;
|
||||
|
||||
/// The amount of characters an exercise name needs to have
|
||||
const MIN_CHARS_NAME = 5;
|
||||
@@ -75,6 +75,7 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
|
||||
Widget _controlsBuilder(BuildContext context, ControlsDetails details) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
if (_currentStep == lastStepIndex)
|
||||
ElevatedButton(
|
||||
@@ -82,11 +83,11 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
child: Text(AppLocalizations.of(context).save),
|
||||
)
|
||||
else
|
||||
TextButton(
|
||||
OutlinedButton(
|
||||
onPressed: details.onStepContinue,
|
||||
child: Text(AppLocalizations.of(context).next),
|
||||
),
|
||||
TextButton(
|
||||
OutlinedButton(
|
||||
onPressed: details.onStepCancel,
|
||||
child: Text(AppLocalizations.of(context).previous),
|
||||
),
|
||||
@@ -134,7 +135,6 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
|
||||
if (_keys[_currentStep].currentState?.validate() ?? false) {
|
||||
_keys[_currentStep].currentState?.save();
|
||||
context.read<AddExerciseProvider>().addExercise();
|
||||
|
||||
if (_currentStep != lastStepIndex) {
|
||||
setState(() {
|
||||
@@ -145,6 +145,7 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
|
||||
if (_currentStep == lastStepIndex) {
|
||||
_addExercise();
|
||||
context.read<AddExerciseProvider>().addExercise();
|
||||
}
|
||||
},
|
||||
onStepCancel: () => setState(() {
|
||||
@@ -183,13 +184,10 @@ class _BasicStepContent extends StatelessWidget {
|
||||
key: formkey,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).baseNameEnglish,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: '${AppLocalizations.of(context).name}*',
|
||||
helperText: AppLocalizations.of(context).baseNameEnglish,
|
||||
isRequired: true,
|
||||
validator: (name) => validateName(name, context),
|
||||
onSaved: (String? name) => addExerciseProvider.exerciseNameEn = name!,
|
||||
@@ -354,67 +352,90 @@ class _DescriptionStepContent extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _DescriptionTranslationStepContent extends StatelessWidget {
|
||||
class _DescriptionTranslationStepContent extends StatefulWidget {
|
||||
final GlobalKey<FormState> formkey;
|
||||
const _DescriptionTranslationStepContent({required this.formkey});
|
||||
|
||||
@override
|
||||
State<_DescriptionTranslationStepContent> createState() =>
|
||||
_DescriptionTranslationStepContentState();
|
||||
}
|
||||
|
||||
class _DescriptionTranslationStepContentState extends State<_DescriptionTranslationStepContent> {
|
||||
bool translate = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final addExerciseProvider = context.read<AddExerciseProvider>();
|
||||
final exerciseProvider = context.read<ExercisesProvider>();
|
||||
|
||||
final languages = exerciseProvider.languages;
|
||||
|
||||
return Form(
|
||||
key: formkey,
|
||||
key: widget.formkey,
|
||||
child: Column(
|
||||
children: [
|
||||
ExerciseCategoryInputWidget<Language>(
|
||||
categories: languages,
|
||||
title: AppLocalizations.of(context).language,
|
||||
displayName: (Language l) => l.fullName,
|
||||
callback: (Language newValue) {
|
||||
addExerciseProvider.language = newValue;
|
||||
SwitchListTile(
|
||||
title: Text(AppLocalizations.of(context).translation),
|
||||
subtitle: Text(AppLocalizations.of(context).translateExercise),
|
||||
value: translate,
|
||||
onChanged: (_) {
|
||||
setState(() {
|
||||
translate = !translate;
|
||||
});
|
||||
},
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: '${AppLocalizations.of(context).name}*',
|
||||
isRequired: true,
|
||||
validator: (name) => validateName(name, context),
|
||||
onSaved: (String? name) => addExerciseProvider.exerciseNameTrans = name!,
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: AppLocalizations.of(context).alternativeNames,
|
||||
isMultiline: true,
|
||||
helperText: AppLocalizations.of(context).oneNamePerLine,
|
||||
validator: (alternateNames) {
|
||||
// check that each line (name) is at least MIN_CHARACTERS_NAME long
|
||||
if (alternateNames?.isNotEmpty == true) {
|
||||
final names = alternateNames!.split('\n');
|
||||
for (final name in names) {
|
||||
if (name.length < MIN_CHARS_NAME || name.length > MAX_CHARS_NAME) {
|
||||
return AppLocalizations.of(context).enterCharacters(
|
||||
MIN_CHARS_NAME,
|
||||
MAX_CHARS_NAME,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (String? alternateName) =>
|
||||
addExerciseProvider.alternateNamesTrans = alternateName!.split('\n'),
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: '${AppLocalizations.of(context).description}*',
|
||||
isRequired: true,
|
||||
isMultiline: true,
|
||||
validator: (name) => validateDescription(name, context),
|
||||
onSaved: (String? description) => addExerciseProvider.descriptionTrans = description!,
|
||||
),
|
||||
if (translate)
|
||||
Column(
|
||||
children: [
|
||||
ExerciseCategoryInputWidget<Language>(
|
||||
categories: languages,
|
||||
title: AppLocalizations.of(context).language,
|
||||
displayName: (Language l) => l.fullName,
|
||||
callback: (Language newValue) {
|
||||
addExerciseProvider.language = newValue;
|
||||
},
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: '${AppLocalizations.of(context).name}*',
|
||||
isRequired: true,
|
||||
validator: (name) => validateName(name, context),
|
||||
onSaved: (String? name) => addExerciseProvider.exerciseNameTrans = name!,
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: AppLocalizations.of(context).alternativeNames,
|
||||
isMultiline: true,
|
||||
helperText: AppLocalizations.of(context).oneNamePerLine,
|
||||
validator: (alternateNames) {
|
||||
// check that each line (name) is at least MIN_CHARACTERS_NAME long
|
||||
if (alternateNames?.isNotEmpty == true) {
|
||||
final names = alternateNames!.split('\n');
|
||||
for (final name in names) {
|
||||
if (name.length < MIN_CHARS_NAME || name.length > MAX_CHARS_NAME) {
|
||||
return AppLocalizations.of(context).enterCharacters(
|
||||
MIN_CHARS_NAME,
|
||||
MAX_CHARS_NAME,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (String? alternateName) =>
|
||||
addExerciseProvider.alternateNamesTrans = alternateName!.split('\n'),
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: '${AppLocalizations.of(context).description}*',
|
||||
isRequired: true,
|
||||
isMultiline: true,
|
||||
validator: (name) => validateDescription(name, context),
|
||||
onSaved: (String? description) =>
|
||||
addExerciseProvider.descriptionTrans = description!,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user