mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Some more polishing
This commit is contained in:
@@ -464,6 +464,7 @@
|
||||
"@enterValue": {
|
||||
"description": "Error message when the user hasn't entered a value on a required field"
|
||||
},
|
||||
"selectEntry": "Please select an entry",
|
||||
"selectExercise": "Please select an exercise",
|
||||
"@selectExercise": {
|
||||
"description": "Error message when the user hasn't selected an exercise in the form"
|
||||
|
||||
@@ -27,10 +27,10 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
String? _descriptionTranslation;
|
||||
int? _variationId;
|
||||
int? _newVariationForExercise;
|
||||
late Language language;
|
||||
Language? language;
|
||||
List<String> _alternativeNamesEn = [];
|
||||
List<String> _alternativeNamesTranslation = [];
|
||||
late ExerciseCategory category;
|
||||
ExerciseCategory? category;
|
||||
List<ExerciseBase> _variations = [];
|
||||
List<Equipment> _equipment = [];
|
||||
List<Muscle> _primaryMuscles = [];
|
||||
@@ -44,6 +44,8 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
|
||||
void clear() {
|
||||
_exerciseImages = [];
|
||||
language = null;
|
||||
category = null;
|
||||
_nameEn = null;
|
||||
_nameTranslation = null;
|
||||
_descriptionEn = null;
|
||||
@@ -149,7 +151,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');
|
||||
@@ -177,7 +179,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// Create the translations
|
||||
if (_nameTranslation != null && _descriptionTranslation != null) {
|
||||
if (language != null) {
|
||||
Exercise exerciseTranslationLang = exerciseTranslation;
|
||||
exerciseTranslationLang.base = base;
|
||||
exerciseTranslationLang = await addExerciseTranslation(exerciseTranslationLang);
|
||||
|
||||
@@ -121,11 +121,13 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
_currentStep -= 1;
|
||||
}
|
||||
}),
|
||||
/*
|
||||
onStepTapped: (int index) {
|
||||
//setState(() {
|
||||
// _currentStep = index;
|
||||
//});
|
||||
setState(() {
|
||||
_currentStep = index;
|
||||
});
|
||||
},
|
||||
*/
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
|
||||
class AddExerciseMultiselectButton<T> extends StatefulWidget {
|
||||
final List<T> items;
|
||||
List<T> initialItems = [];
|
||||
final List<T> initialItems;
|
||||
final String title;
|
||||
final ValueChanged<List<T?>> onChange;
|
||||
final FormFieldSetter<List<T?>?>? onSaved;
|
||||
|
||||
AddExerciseMultiselectButton({
|
||||
const AddExerciseMultiselectButton({
|
||||
Key? key,
|
||||
required this.items,
|
||||
required this.title,
|
||||
|
||||
@@ -23,11 +23,6 @@ class BasicStepContent extends StatelessWidget {
|
||||
final categories = exerciseProvider.categories;
|
||||
final muscles = exerciseProvider.muscles;
|
||||
final equipment = exerciseProvider.equipment;
|
||||
final languages = exerciseProvider.languages;
|
||||
|
||||
// Initialize some values
|
||||
addExerciseProvider.category = categories.first;
|
||||
addExerciseProvider.language = languages.first;
|
||||
|
||||
return Form(
|
||||
key: formkey,
|
||||
@@ -50,11 +45,16 @@ class BasicStepContent extends StatelessWidget {
|
||||
addExerciseProvider.alternateNamesEn = alternateName!.split('\n'),
|
||||
),
|
||||
ExerciseCategoryInputWidget<ExerciseCategory>(
|
||||
categories: categories,
|
||||
title: AppLocalizations.of(context).category,
|
||||
entries: categories,
|
||||
title: '${AppLocalizations.of(context).category}*',
|
||||
callback: (ExerciseCategory newValue) {
|
||||
addExerciseProvider.category = newValue;
|
||||
},
|
||||
validator: (ExerciseCategory? category) {
|
||||
if (category == null) {
|
||||
return AppLocalizations.of(context).selectEntry;
|
||||
}
|
||||
},
|
||||
displayName: (ExerciseCategory c) => c.name,
|
||||
),
|
||||
AddExerciseMultiselectButton<Equipment>(
|
||||
|
||||
@@ -44,12 +44,17 @@ class _DescriptionTranslationStepContentState extends State<DescriptionTranslati
|
||||
Column(
|
||||
children: [
|
||||
ExerciseCategoryInputWidget<Language>(
|
||||
categories: languages,
|
||||
title: AppLocalizations.of(context).language,
|
||||
entries: languages,
|
||||
title: '${AppLocalizations.of(context).language}*',
|
||||
displayName: (Language l) => l.fullName,
|
||||
callback: (Language newValue) {
|
||||
addExerciseProvider.language = newValue;
|
||||
},
|
||||
validator: (Language? language) {
|
||||
if (language == null) {
|
||||
return AppLocalizations.of(context).selectEntry;
|
||||
}
|
||||
},
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
|
||||
@@ -22,6 +22,7 @@ class DuplicatesAndVariationsStepContent extends StatelessWidget {
|
||||
AppLocalizations.of(context).whatVariationsExist,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
height: 400,
|
||||
child: SingleChildScrollView(
|
||||
|
||||
@@ -24,19 +24,21 @@ import 'package:flutter/material.dart';
|
||||
class ExerciseCategoryInputWidget<T> extends StatefulWidget {
|
||||
late final String _title;
|
||||
late final Function _callback;
|
||||
late final List<T> _categories;
|
||||
late final List<T> _entries;
|
||||
late final Function _getDisplayName;
|
||||
late final Function? _validator;
|
||||
|
||||
ExerciseCategoryInputWidget({
|
||||
required String title,
|
||||
required List<T> categories,
|
||||
required Function callback,
|
||||
required Function displayName,
|
||||
}) {
|
||||
_categories = categories;
|
||||
ExerciseCategoryInputWidget(
|
||||
{required String title,
|
||||
required List<T> entries,
|
||||
required Function callback,
|
||||
required Function displayName,
|
||||
Function? validator}) {
|
||||
_entries = entries;
|
||||
_title = title;
|
||||
_callback = callback;
|
||||
_getDisplayName = displayName;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -46,27 +48,32 @@ class ExerciseCategoryInputWidget<T> extends StatefulWidget {
|
||||
class _ExerciseCategoryInputWidgetState<T> extends State<ExerciseCategoryInputWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
T selectedWeightUnit = widget._categories.first;
|
||||
T? selectedEntry;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: DropdownButtonFormField(
|
||||
value: selectedWeightUnit,
|
||||
value: selectedEntry,
|
||||
decoration: InputDecoration(
|
||||
labelText: widget._title,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
contentPadding: const EdgeInsets.all(8.0),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
),
|
||||
isDense: true,
|
||||
onChanged: (T? newValue) {
|
||||
setState(() {
|
||||
selectedWeightUnit = newValue!;
|
||||
selectedEntry = newValue!;
|
||||
widget._callback(newValue);
|
||||
});
|
||||
},
|
||||
items: widget._categories.map<DropdownMenuItem<T>>((value) {
|
||||
validator: (T? value) {
|
||||
if (widget._validator != null) {
|
||||
return widget._validator!(value);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
items: widget._entries.map<DropdownMenuItem<T>>((value) {
|
||||
return DropdownMenuItem<T>(
|
||||
key: Key(value.id.toString()),
|
||||
value: value,
|
||||
|
||||
Reference in New Issue
Block a user