I am trying to retrieve all AMOUNT values for a particular category for current month from EXPENSE collection and return the sum of values using a custom function but I am getting the error Target of URI doesn't exist: 'package:cloud_firestore/cloud_firestore.dart'.
Later while compiling and running the function it is not able to recognize package function FirebaseFirestore and querySnapshot. Here's the code
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';
List<double> getMonthlySumByCategory(String? category) {
/// MODIFY CODE ONLY BELOW THIS LINE
// Retieve all AMOUNT values for a particular category for current month from EXPENSE collection and return the list
List<double> amounts = [];
// Get the current month and year
DateTime now = DateTime.now();
int currentMonth = now.month;
int currentYear = now.year;
// Query the EXPENSE collection for the current month and category
// Assuming expense collection is a Firestore collection
FirebaseFirestore.instance
.collection('EXPENSE')
.where('category', isEqualTo: category)
.where('month', isEqualTo: currentMonth)
.where('year', isEqualTo: currentYear)
.get()
.then((QuerySnapshot querySnapshot) {
querySnapshot.docs.forEach((doc) {
// Get the amount value and add it to the list
double amount = doc['amount'] ?? 0.0;
amounts.add(amount);
});
});
return amounts;
/// MODIFY CODE ONLY ABOVE THIS LINE
}