import 'dart:developer'; import 'dart:io'; import 'package:dio/dio.dart'; class FileUpload { Future uploadFileAndJsonData( {required File empFace, required String empCode}) async { final url = 'My API URL'; try { var formData = FormData.fromMap({ "files": [ MultipartFile.fromFileSync("./example/upload.txt", filename: "upload.txt"), MultipartFile.fromFileSync("./example/upload.txt", filename: "upload.txt"), ] }); final response = await Dio().post( url, data: formData, ); if (response.statusCode == 200) { var map = response.data as Map; print('success'); if (map['status'] == 'Successfully registered') { return true; } else { return false; } } else if (response.statusCode == 200) { //BotToast is a package for toasts available on pub.dev // BotToast.showText(text: 'Validation Error Occurs'); return false; } } on DioException catch (error) { log(error.message!); throw 'Something Went Wrong'; } catch (_) { log(_.toString()); throw 'Something Went Wrong'; } return false; } }