mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 23:42:00 +01:00
Pass keys to the individual forms
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -39,20 +40,22 @@ class AddExcerciseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
//Just to Debug Provider
|
||||
printValues() {
|
||||
print('Name $_name');
|
||||
print('alternate names : $_alternativeNames');
|
||||
print('target area : $_targetArea');
|
||||
print('primary mucsles');
|
||||
void printValues() {
|
||||
log('Collected exercise data');
|
||||
log('------------------------');
|
||||
log('Name $_name');
|
||||
log('alternate names : $_alternativeNames');
|
||||
log('target area : $_targetArea');
|
||||
log('primary muscles');
|
||||
if (_primaryMuscles != null) {
|
||||
for (final a in _primaryMuscles!) {
|
||||
print(a);
|
||||
log(a!);
|
||||
}
|
||||
}
|
||||
print('seconday mucsles');
|
||||
log('seconday mucsles');
|
||||
if (_secondaryMuscles != null) {
|
||||
for (final a in _secondaryMuscles!) {
|
||||
print(a);
|
||||
log(a!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -54,7 +56,9 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _addExercise() {}
|
||||
void _addExercise() {
|
||||
log('Adding exercise...');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -67,21 +71,19 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
steps: [
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context).baseData),
|
||||
content: _BasicStepContent(
|
||||
formkey: _keys[0],
|
||||
),
|
||||
content: _BasicStepContent(formkey: _keys[0]),
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context).variations),
|
||||
content: _DuplicatesAndVariationsStepContent(),
|
||||
content: _DuplicatesAndVariationsStepContent(formkey: _keys[1]),
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context).images),
|
||||
content: _ImagesStepContent(),
|
||||
content: _ImagesStepContent(formkey: _keys[2]),
|
||||
),
|
||||
Step(
|
||||
title: Text(AppLocalizations.of(context).description),
|
||||
content: _DescriptionStepContent(),
|
||||
content: _DescriptionStepContent(formkey: _keys[3]),
|
||||
)
|
||||
],
|
||||
currentStep: _currentStep,
|
||||
@@ -89,6 +91,8 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
if (_currentStep == lastStepIndex) {
|
||||
_addExercise();
|
||||
} else {
|
||||
log('Validation for step ${_currentStep}: ${_keys[_currentStep].currentState?.validate()}');
|
||||
|
||||
if (_keys[_currentStep].currentState?.validate() ?? false) {
|
||||
_keys[_currentStep].currentState?.save();
|
||||
context.read<AddExcerciseProvider>().printValues();
|
||||
@@ -107,9 +111,9 @@ class _AddExerciseScreenState extends State<AddExerciseScreen> {
|
||||
}
|
||||
|
||||
class _BasicStepContent extends StatelessWidget {
|
||||
// final GlobalKey<FormState> _basicStepFormKey = GlobalKey<FormState>();
|
||||
final GlobalKey<FormState> formkey;
|
||||
_BasicStepContent({required this.formkey});
|
||||
const _BasicStepContent({required this.formkey});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final addExercideProvider = context.read<AddExcerciseProvider>();
|
||||
@@ -160,11 +164,14 @@ class _BasicStepContent extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _DuplicatesAndVariationsStepContent extends StatelessWidget {
|
||||
final GlobalKey<FormState> _duplicatesAndVariationsFormKey = GlobalKey<FormState>();
|
||||
final GlobalKey<FormState> formkey;
|
||||
|
||||
const _DuplicatesAndVariationsStepContent({required this.formkey});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _duplicatesAndVariationsFormKey,
|
||||
key: formkey,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(AppLocalizations.of(context).whatVariationsExist),
|
||||
@@ -176,52 +183,59 @@ class _DuplicatesAndVariationsStepContent extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _ImagesStepContent extends StatefulWidget {
|
||||
final GlobalKey<FormState> formkey;
|
||||
const _ImagesStepContent({required this.formkey});
|
||||
|
||||
@override
|
||||
State<_ImagesStepContent> createState() => _ImagesStepContentState();
|
||||
}
|
||||
|
||||
class _ImagesStepContentState extends State<_ImagesStepContent> with ExcerciseImagePickerMixin {
|
||||
final GlobalKey<FormState> _imagesStepFormKey = GlobalKey<FormState>();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).add_exercise_image_license,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
),
|
||||
Consumer<AddExcerciseProvider>(
|
||||
builder: (ctx, provider, __) => provider.excerciseImages.isNotEmpty
|
||||
? PreviewExcercizeImages(
|
||||
selectedimages: provider.excerciseImages,
|
||||
)
|
||||
: ElevatedButton(
|
||||
onPressed: () => pickImages(context),
|
||||
child: const Text('BROWSE FOR FILES'),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) => Colors.black)),
|
||||
),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
return Form(
|
||||
key: widget.formkey,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
AppLocalizations.of(context).add_exercise_image_license,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
children: const <TextSpan>[
|
||||
TextSpan(text: 'Only JPEG, PNG and WEBP files below 20 MB are supported'),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
Consumer<AddExcerciseProvider>(
|
||||
builder: (ctx, provider, __) => provider.excerciseImages.isNotEmpty
|
||||
? PreviewExcercizeImages(
|
||||
selectedimages: provider.excerciseImages,
|
||||
)
|
||||
: ElevatedButton(
|
||||
onPressed: () => pickImages(context),
|
||||
child: const Text('BROWSE FOR FILES'),
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.resolveWith((states) => Colors.black)),
|
||||
),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
children: const <TextSpan>[
|
||||
TextSpan(text: 'Only JPEG, PNG and WEBP files below 20 MB are supported'),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DescriptionStepContent extends StatelessWidget {
|
||||
final GlobalKey<FormState> _descriptionStepFormKey = GlobalKey<FormState>();
|
||||
final GlobalKey<FormState> formkey;
|
||||
const _DescriptionStepContent({required this.formkey});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _descriptionStepFormKey,
|
||||
key: formkey,
|
||||
child: Column(
|
||||
children: [
|
||||
AddExerciseTextArea(
|
||||
|
||||
Reference in New Issue
Block a user