Previously, I got null errors when trying to use Flutterflow actions so I wanted to try custom code to bypass this.
When I use the code below, I get this error when trying to test it "lib/custom_code/actions/getlastfewcards.dart:32:31: Error: Member not found: 'FlashcardsRecord.fromJson'. return FlashcardsRecord.fromJson(querySnapshot.docs.first.data()); ^^^^^^^^"
Future<FlashcardsRecord> getlastfewcards(
List<int>? integerlistofcardsremoved) async {
final random = Random();
int? randomNumber;
do {
randomNumber = random.nextInt(10) + 1;
} while (randomNumber != null &&
integerlistofcardsremoved?.contains(randomNumber) == true);
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection('Flashcards')
.where('Card_number', isEqualTo: randomNumber)
.limit(1)
.get();
if (querySnapshot.docs.isNotEmpty) {
return FlashcardsRecord.fromJson(
querySnapshot.docs.first.data() as Map<String, dynamic>);
} else {
throw Exception('No matching documents found');
}
}
When I add this code below to try to fix it, the code cannot be parsed. Help please!!
class FlashcardsRecord {
final int? cardNumber;
final int? descriptor;
final String? answer;
final String? answerimageurl1;
final String? answerimageurl2;
final int? displayedcardnumber;
final String? explanation;
final String? hint;
final String? imageurl1;
final String? imageurl2;
final String? question;
FlashcardsRecord({this.cardNumber,
this.answer,
this.answerimageurl1,
this.answerimageurl2,
this.descriptor,
this.displayedcardnumber,
this.explanation,
this.hint,
this.imageurl1,
this.imageurl2,
this.question});}