I want to upload file throw Monday.com API graphql. I am using dart and building Flutter App. I am stuck on uploading files (images) throw API. Can you help me, with providing codebase or anything.
Future<void> _pickImage(String imageType) async {
html.FileUploadInputElement uploadInput = html.FileUploadInputElement();
uploadInput.click();
uploadInput.onChange.listen((e) {
final files = uploadInput.files;
if (files!.isEmpty) return;
final file = files.first;
final reader = html.FileReader();
reader.readAsDataUrl(file);
reader.onLoadEnd.listen((e) {
setState(() {
_images[imageType] = reader.result as String?;
});
});
});
}
Widget _buildImageField(String label, String imageType) {
return Column(
children: [
Text(label),
SizedBox(height: 10),
_images[imageType] != null
? Image.network(_images[imageType]!)
: Text('No image selected.'),
ElevatedButton(
onPressed: () => _pickImage(imageType),
child: Text('Pick Image'),
),
],
);
}
final ImagePicker _picker = ImagePicker();
Map<String, String?> _images = {
'TruckFront': null,
'TruckLeft': null,
'TruckRight': null,
'TruckBack': null,
'LeftFrontTire': null,
'RightFrontTire': null,
'SideLeftTires': null,
'SideRightTires': null,
'LeftRearOutside': null,
'LeftRearInside': null,
'RightRearOutside': null,
'RightRearInside': null,
'TrailerLeft': null,
'TrailerRight': null,
};