0

I want to display a list of actions a user has to do daily. If a user marks an action as completed, this is recorded in a log collection.

For displaying the list of actions, I only want to show actions the user has not yet completed today. So, I want to set conditional visibility on the actions list based on values in the log collection.

I'm thinking of implementing via custom function, with this logic:

  1. Parameter: Action (one of the actions of the list)
  2. Take the Log collection. Iterate through this collection to check if any entries are matching the action. If yes, set boolean to True. If not, keep as False.
  3. Conditional visibility: Only display actions where this function results in "False".

I've now tried for a while creating this custom function with the Code Copilot, see code below. However, the suggested code throws errors I don't know how to fix. I was wondering if someone could help me figure out what I'm doing wrong?

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';

bool? checkLogs(String? action) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  // iterate through field in a collection, check if it matches argument
  bool completedToday = false;

  FirebaseFirestore.instance
      .collection('checklistLogs')
      .get()
      .then((QuerySnapshot querySnapshot) {
    querySnapshot.docs.forEach((doc) {
      if (doc.get('action') == action) {
        completedToday = true;
      }
    });
  });
  return completedToday;
  /// MODIFY CODE ONLY ABOVE THIS LINE
} 

Error screenshot

0 Answers0