mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add image upload methods
We use the "manual" way as it was before, since there were some problems making this work and most of the errors were happening during the exercise creation itself.
This commit is contained in:
@@ -2,6 +2,8 @@ import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:wger/helpers/consts.dart';
|
||||
import 'package:wger/models/exercises/category.dart';
|
||||
import 'package:wger/models/exercises/equipment.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
@@ -36,6 +38,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
List<Muscle> _secondaryMuscles = [];
|
||||
|
||||
static const _exerciseSubmissionUrlPath = 'exercise-submission';
|
||||
static const _imagesUrlPath = 'exerciseimage';
|
||||
static const _checkLanguageUrlPath = 'check-language';
|
||||
|
||||
void clear() {
|
||||
@@ -190,6 +193,21 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
return result['id'];
|
||||
}
|
||||
|
||||
Future<void> addImages(int exerciseId) async {
|
||||
for (final image in _exerciseImages) {
|
||||
final request = http.MultipartRequest('POST', baseProvider.makeUrl(_imagesUrlPath));
|
||||
request.headers.addAll(baseProvider.getDefaultHeaders(includeAuth: true));
|
||||
|
||||
request.files.add(await http.MultipartFile.fromPath('image', image.path));
|
||||
request.fields['exercise'] = exerciseId.toString();
|
||||
request.fields['style'] = EXERCISE_IMAGE_ART_STYLE.PHOTO.index.toString();
|
||||
|
||||
await request.send();
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> validateLanguage(String input, String languageCode) async {
|
||||
final Map<String, dynamic> result = await baseProvider.post(
|
||||
{'input': input, 'language_code': languageCode},
|
||||
|
||||
Reference in New Issue
Block a user