This code below WAS compiling, until I made a change in the action. After re-compiling, I'm getting the dreaded 'Target of URI doesn't exist for FilePicker and Supabase packages'.
I recognise that I'm not a Flutter/Dart developer and I don't fully understand the pub dependencies etc, but the code editor behaviour is absolutely erratic. I find it unacceptable, especially because I'm paying the Pro subscription. Any help here?
By the way, unrelated to the issue, but the code is solving the problem of a Supabase storage upload with a random filename (also reported somewhere else in this forum). In the code, I'm composing the name myself, which I send to the AppState, to then be used somewhere else (to process the file uploaded)
// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.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 'package:file_picker/file_picker.dart';
Future uploadFile(String fileType) async {
// Add your function code here!
if (fileType != 'type_a' && fileType != 'tupe_a') {
throw ArgumentError('fileType must be either "type_a" or "type_b"');
}
final result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['csv'],
allowMultiple: false,
);
if (result != null) {
final file = result.files.first;
final timestamp = DateTime.now().millisecondsSinceEpoch;
final filename = '${fileType}_${timestamp}.csv';
final filepath = '${fileType}/${filename}';
FFAppState().uploadedFileName = filename;
final Uint8List fileBytes = file.bytes!;
final createdFilePath =
await Supabase.instance.client.storage.from('my_bucket').uploadBinary(
filepath,
fileBytes,
fileOptions: const FileOptions(upsert: true),
);
print('Generated path in Supabase: ' + createdFilePath);
} else {
throw Exception('No file selected');
}
}