Trying to run Custom Function from Custom Action, and I'm not sure what's going wrong

I have a custom action that runs perfectly if I comment out the attempt to use the custom function. But if I uncomment it, the code just doesnt run, occasionally giving the error: "generateRandomPastel() isnt defined", even though I have "import '/flutter_flow/custom_functions.dart';" up top.

I'm very new to Flutterflow, so I imagine its a simple answer, but wow am I stumped, any help would be super appreciated!

Braeden

---

addCompartmentsAction (action):

// 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 'package:cloud_firestore/cloud_firestore.dart'; Future addCompartmentsAction( DocumentReference? user, DocumentReference? storageUnit, int? compartNum, String? storageName, ) async { // search collection "Storage" for a document where field 'name' is equal to argument "StorageName" QuerySnapshot snapshot = await FirebaseFirestore.instance .collection('Storage') .where('name', isEqualTo: storageName) .get(); if (snapshot.docs.isNotEmpty) { DocumentReference storageRef = snapshot.docs.first.reference; // Take int compartNum argument, and make that amount of new documents in the Compartments collection if (user == null || compartNum == null) { throw Exception('Invalid arguments'); } final compartmentsCollection = FirebaseFirestore.instance.collection('Compartments'); Color? theOne; for (int i = 1; i <= compartNum; i++) { theOne = generateRandomPastel(); final compartmentData = { 'name': 'Compartment ' + i.toString(), 'numberOfItems': 0, 'clothingItems': [], 'user': user, 'storageUnit': storageRef, 'cardColour': theOne, }; await compartmentsCollection.add(compartmentData); } } }

generateRandomPastel (function):

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'; import '/auth/firebase_auth/auth_util.dart'; Color? generateRandomPastel() { /// MODIFY CODE ONLY BELOW THIS LINE // generate a random pastel color and return the value final random = math.Random(); final r = (random.nextInt(256) + 256) ~/ 2; final g = (random.nextInt(256) + 256) ~/ 2; final b = (random.nextInt(256) + 256) ~/ 2; return Color.fromRGBO(r, g, b, 1.0); /// MODIFY CODE ONLY ABOVE THIS LINE }

1
3 replies