From 7bc84634068848635701767cfd8958da322cb37f Mon Sep 17 00:00:00 2001 From: Branislav Nohaj Date: Sat, 4 Oct 2025 11:13:10 +0200 Subject: [PATCH] dar format was performed --- lib/providers/add_exercise.dart | 28 +++--- .../add_exercise/image_details_form.dart | 87 +++++-------------- .../add_exercise/steps/step5images.dart | 43 +++------ .../add_exercise/steps/step6Overview.dart | 2 +- .../add_exercise_image_withDetail_test.dart | 18 +--- 5 files changed, 51 insertions(+), 127 deletions(-) diff --git a/lib/providers/add_exercise.dart b/lib/providers/add_exercise.dart index 99c0db8fb..5b8ef7295 100644 --- a/lib/providers/add_exercise.dart +++ b/lib/providers/add_exercise.dart @@ -150,21 +150,19 @@ class AddExerciseProvider with ChangeNotifier { /// [derivativeSourceUrl] - Derivative source URL /// [style] - Image style: 1=PHOTO, 2=3D, 3=LINE, 4=LOW-POLY, 5=OTHER void addExerciseImages( - List images, { - String? title, - String? author, - String? authorUrl, - String? sourceUrl, - String? derivativeSourceUrl, - String style = '1', - }) { + List images, { + String? title, + String? author, + String? authorUrl, + String? sourceUrl, + String? derivativeSourceUrl, + String style = '1', + }) { _exerciseImages.addAll(images); // Store metadata for each image for (final image in images) { - final details = { - 'style': style, - }; + final details = {'style': style}; // Only add non-empty fields if (title != null && title.isNotEmpty) { @@ -353,7 +351,8 @@ class AddExerciseProvider with ChangeNotifier { } if (details.containsKey('license_derivative_source_url') && - responseData['license_derivative_source_url'] != details['license_derivative_source_url']) { + responseData['license_derivative_source_url'] != + details['license_derivative_source_url']) { print('WARNING: license_derivative_source_url mismatch!'); allFieldsMatch = false; } @@ -364,7 +363,6 @@ class AddExerciseProvider with ChangeNotifier { print('SOME LICENSE FIELDS NOT SAVED CORRECTLY!'); } } - } else { log('Failed to upload image: ${response.statusCode}'); log('Response body: ${response.body}'); @@ -390,7 +388,7 @@ class AddExerciseProvider with ChangeNotifier { return false; } -/* + /* Note: all this logic is not needed now since we are using the /exercise-submission endpoint, however, if we ever want to implement editing of exercises, we will need basically all of it again, so this is kept here for reference. @@ -445,4 +443,4 @@ class AddExerciseProvider with ChangeNotifier { } */ -} \ No newline at end of file +} diff --git a/lib/widgets/add_exercise/image_details_form.dart b/lib/widgets/add_exercise/image_details_form.dart index a89850691..6479782b7 100644 --- a/lib/widgets/add_exercise/image_details_form.dart +++ b/lib/widgets/add_exercise/image_details_form.dart @@ -105,9 +105,9 @@ class _ImageDetailsFormState extends State { children: [ Text( 'Image details', - style: Theme.of(context).textTheme.titleLarge?.copyWith( - fontWeight: FontWeight.bold, - ), + style: Theme.of( + context, + ).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold), ), const SizedBox(height: 16), @@ -177,20 +177,14 @@ class _ImageDetailsFormState extends State { Widget _buildImagePreview() { return Center( child: Container( - constraints: const BoxConstraints( - maxWidth: 300, - maxHeight: 200, - ), + constraints: const BoxConstraints(maxWidth: 300, maxHeight: 200), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), border: Border.all(color: Colors.grey.shade300), ), child: ClipRRect( borderRadius: BorderRadius.circular(8), - child: Image.file( - widget.imageFile, - fit: BoxFit.contain, - ), + child: Image.file(widget.imageFile, fit: BoxFit.contain), ), ), ); @@ -205,26 +199,15 @@ class _ImageDetailsFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - label, - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - ), - ), + Text(label, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)), const SizedBox(height: 8), TextFormField( controller: controller, keyboardType: keyboardType, decoration: InputDecoration( hintText: hint, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(4), - ), - contentPadding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 12, - ), + border: OutlineInputBorder(borderRadius: BorderRadius.circular(4)), + contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12), ), ), ], @@ -246,19 +229,12 @@ class _ImageDetailsFormState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Icon( - Icons.info_outline, - size: 20, - color: Colors.blue.shade700, - ), + Icon(Icons.info_outline, size: 20, color: Colors.blue.shade700), const SizedBox(width: 8), Expanded( child: Text( 'Note that a derivative work is one which is not only based on a previous work, but which also contains sufficient new, creative content to entitle it to its own copyright.', - style: TextStyle( - fontSize: 12, - color: Colors.blue.shade900, - ), + style: TextStyle(fontSize: 12, color: Colors.blue.shade900), ), ), ], @@ -274,13 +250,7 @@ class _ImageDetailsFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text( - 'Image Type', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - ), - ), + const Text('Image Type', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500)), const SizedBox(height: 12), Wrap( spacing: 8, @@ -348,19 +318,12 @@ class _ImageDetailsFormState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Icon( - Icons.info_outline, - size: 20, - color: Colors.amber.shade900, - ), + Icon(Icons.info_outline, size: 20, color: Colors.amber.shade900), const SizedBox(width: 8), Expanded( child: RichText( text: TextSpan( - style: TextStyle( - fontSize: 12, - color: Colors.amber.shade900, - ), + style: TextStyle(fontSize: 12, color: Colors.amber.shade900), children: [ const TextSpan( text: 'By submitting this image, you agree to release it under the ', @@ -385,7 +348,8 @@ class _ImageDetailsFormState extends State { ), ), const TextSpan( - text: ' license. The image must be either your own work or the author must have released it under a license compatible with CC BY-SA 4.0.', + text: + ' license. The image must be either your own work or the author must have released it under a license compatible with CC BY-SA 4.0.', ), ], ), @@ -400,19 +364,14 @@ class _ImageDetailsFormState extends State { return Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - TextButton( - onPressed: widget.onCancel, - child: const Text('CANCEL'), - ), + TextButton(onPressed: widget.onCancel, child: const Text('CANCEL')), const SizedBox(width: 8), ElevatedButton( onPressed: () { if (_formKey.currentState!.validate()) { // Build details map with API field names // Style is always included, other fields only if non-empty - final details = { - 'style': _getStyleValue(), - }; + final details = {'style': _getStyleValue()}; // Add optional fields only if user provided values final title = _titleController.text.trim(); @@ -447,20 +406,14 @@ class _ImageDetailsFormState extends State { style: ElevatedButton.styleFrom( backgroundColor: Theme.of(context).primaryColor, foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric( - horizontal: 32, - vertical: 12, - ), + padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 12), ), child: const Text( 'ADD', - style: TextStyle( - fontWeight: FontWeight.bold, - color: Colors.white, - ), + style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), ), ), ], ); } -} \ No newline at end of file +} diff --git a/lib/widgets/add_exercise/steps/step5images.dart b/lib/widgets/add_exercise/steps/step5images.dart index 8ccaf83a0..179e05143 100644 --- a/lib/widgets/add_exercise/steps/step5images.dart +++ b/lib/widgets/add_exercise/steps/step5images.dart @@ -71,9 +71,7 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin if (!isFileValid) { if (context.mounted) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(errorMessage)), - ); + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(errorMessage))); } return; } @@ -161,9 +159,7 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin // Show preview of images that have been added with metadata return Column( children: [ - PreviewExerciseImages( - selectedImages: provider.exerciseImages, - ), + PreviewExerciseImages(selectedImages: provider.exerciseImages), const SizedBox(height: 16), ElevatedButton.icon( onPressed: () => _pickAndShowImageDetails(context), @@ -178,17 +174,13 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin return Column( children: [ const SizedBox(height: 20), - Icon( - Icons.add_photo_alternate, - size: 80, - color: Colors.grey.shade400, - ), + Icon(Icons.add_photo_alternate, size: 80, color: Colors.grey.shade400), const SizedBox(height: 16), Text( 'No images selected', - style: Theme.of(context).textTheme.titleMedium?.copyWith( - color: Colors.grey.shade600, - ), + style: Theme.of( + context, + ).textTheme.titleMedium?.copyWith(color: Colors.grey.shade600), ), const SizedBox(height: 24), // Camera and Gallery buttons @@ -196,17 +188,11 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton.icon( - onPressed: () => _pickAndShowImageDetails( - context, - pickFromCamera: true, - ), + onPressed: () => _pickAndShowImageDetails(context, pickFromCamera: true), icon: const Icon(Icons.camera_alt), label: const Text('Camera'), style: ElevatedButton.styleFrom( - padding: const EdgeInsets.symmetric( - horizontal: 20, - vertical: 12, - ), + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12), ), ), const SizedBox(width: 16), @@ -215,10 +201,7 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin icon: const Icon(Icons.collections), label: const Text('Gallery'), style: ElevatedButton.styleFrom( - padding: const EdgeInsets.symmetric( - horizontal: 20, - vertical: 12, - ), + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12), ), ), ], @@ -228,9 +211,9 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Text( 'Only JPEG, PNG and WEBP files below 20 MB are supported', - style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: Colors.grey.shade600, - ), + style: Theme.of( + context, + ).textTheme.bodySmall?.copyWith(color: Colors.grey.shade600), textAlign: TextAlign.center, ), ), @@ -242,4 +225,4 @@ class _Step5ImagesState extends State with ExerciseImagePickerMixin ), ); } -} \ No newline at end of file +} diff --git a/lib/widgets/add_exercise/steps/step6Overview.dart b/lib/widgets/add_exercise/steps/step6Overview.dart index 43f707d8c..fbe65664a 100644 --- a/lib/widgets/add_exercise/steps/step6Overview.dart +++ b/lib/widgets/add_exercise/steps/step6Overview.dart @@ -108,4 +108,4 @@ class Step6Overview extends StatelessWidget { ), ); } -} \ No newline at end of file +} diff --git a/test/exercises/add_exercise_image_withDetail_test.dart b/test/exercises/add_exercise_image_withDetail_test.dart index b7428085e..e56a36fb6 100644 --- a/test/exercises/add_exercise_image_withDetail_test.dart +++ b/test/exercises/add_exercise_image_withDetail_test.dart @@ -79,10 +79,7 @@ void main() { final styles = ['1', '2', '3', '4', '5']; for (var i = 0; i < styles.length; i++) { - provider.addExerciseImages( - [File('image_$i.jpg')], - style: styles[i], - ); + provider.addExerciseImages([File('image_$i.jpg')], style: styles[i]); } expect(provider.exerciseImages.length, 5); @@ -131,10 +128,7 @@ void main() { /// Attempting to remove a non-existent image should throw StateError /// (from firstWhere with no orElse) test('should handle removing non-existent image gracefully', () { - expect( - () => provider.removeExercise('nonexistent.jpg'), - throwsStateError, - ); + expect(() => provider.removeExercise('nonexistent.jpg'), throwsStateError); }); /// clear() should reset all state including images and metadata @@ -177,11 +171,7 @@ void main() { /// Multiple images can be added in a single call with shared metadata /// Useful for bulk uploads from the same source test('should handle batch adding multiple images at once', () { - final files = [ - File('batch1.jpg'), - File('batch2.jpg'), - File('batch3.jpg'), - ]; + final files = [File('batch1.jpg'), File('batch2.jpg'), File('batch3.jpg')]; provider.addExerciseImages(files, title: 'Batch Upload', style: '3'); @@ -254,4 +244,4 @@ void main() { expect(provider.descriptionEn, isNull); }); }); -} \ No newline at end of file +}