upload_request.dart 662 B

123456789101112131415161718192021222324252627
  1. import 'dart:io';
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:json_annotation/json_annotation.dart';
  5. import '../../../base/app_base_request.dart';
  6. part 'upload_request.g.dart';
  7. @JsonSerializable()
  8. class UploadRequest extends AppBaseRequest {
  9. @JsonKey(ignore: true)
  10. File? file;
  11. UploadRequest({this.file});
  12. @override
  13. Map<String, dynamic> toJson() {
  14. final json = _$UploadRequestToJson(this);
  15. debugPrint('file path: ${file?.path}');
  16. if (file != null) {
  17. json['file'] = MultipartFile.fromFileSync(file!.path,
  18. contentType: DioMediaType('image', 'jpeg'));
  19. }
  20. return json;
  21. }
  22. }