Help please ... how do I debug some custom code thats not working?

With the help of the AI I have the code below. Its meant to upload an image into the "sku/account/" folder.

I think my firestore permissions are ok as the inbuilt image upload widget works fine. But with this custom one there is no file uploaded. The picker part works - it pops up and I can select a file. But then nothing.

My no-coding skills are strongest in the "no" part rather than the coding part....

Any suggestions how to see why its not working and fix it?

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';

// Begin custom action code

// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:io';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:image_picker/image_picker.dart';

Future<String> customUploadImage(

String? sku,
String? account,

) async {

// Create an instance of Firebase Storage
final FirebaseStorage storage = FirebaseStorage.instance;

// Create an instance of ImagePicker
final ImagePicker _picker = ImagePicker();

// Pick an image from the gallery
final XFile? image = await _picker.pickImage(source: ImageSource.gallery);

// Check if an image was selected

if (image != null) {

// Create a reference to the image in Firebase Storage

final Reference ref = storage.ref().child(

'images/$sku/$account/${DateTime.now().millisecondsSinceEpoch}.jpg');

// Upload the image to Firebase Storage

final UploadTask uploadTask = ref.putFile(File(image.path));

// Get the download URL of the uploaded image

final TaskSnapshot downloadUrl = await uploadTask.whenComplete(() => null);

// Return the download URL as a string

return downloadUrl.ref.getDownloadURL();

}

}

1
7 replies