I am currently trying my first Custom Function for FlutterFlow. What I want to do is simple: Convert an uploaded PDF into base64 and save it as a String variable. The code I am using for this is very straight forward:
import 'dart:convert';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
String? newCustomFunction(FFUploadedFile uploadedFile) {
/// MODIFY CODE ONLY BELOW THIS LINE
// Convert the uploaded PDF file into Base64
Uint8List fileBytes = uploadedFile.bytes!;
String base64String = base64Encode(fileBytes);
return base64String;
/// MODIFY CODE ONLY ABOVE THIS LINE
}
Without importing dart:typed_data I was able to save this custom function but now I get the following error message when I want to test my App:
"lib/flutter_flow/custom_functions.dart:16:3: Error: 'Uint8List' isn't a type. Uint8List fileBytes = uploadedFile.bytes!; ^^^^^^^^^ Waiting for connection from debug service on Web Server... 44.2s Failed to compile application."
I was confident this problem could have been solved by simply adding "import 'dart:typed_data';" to my code, but I am unable so save any changes outside of the main string function. Is there an easy solution that I am overlooking right now?
I highly appreciate any help :)