I used the copilot feature to write a custom functions doing some basic calculations on a Supabase table.
I would like to query all posts of a user that that are no older than 30 days (from table posts in Supabase) and count the amount of posts for each beverage.
Inside the editor I receive two function code errors:
The await expression can only be used in an async function. Try marking the function body with either 'async' or 'async*'
'PostgrestFilterBuilder'. Try correcting the name to the name of an existing method, or defining a method named 'group'.
Any ideas how I can fix this or where I can look for a solution?
I appreciate any help - thank you so much in advance.
Here is my 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 '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.dart';
import '/auth/supabase_auth/auth_util.dart';
List<dynamic> newCustomFunction(String user) {
/// MODIFY CODE ONLY BELOW THIS LINE
// // query a supabase table posts where user_id matches the argument "user" and created_at ist not older that 30 days ago and do not user firebase. Then count all rows with the same beverage_name_de and return a list of json objects where beverage_name_de, beverage_name_en and count of rows with that name
final thirtyDaysAgo = DateTime.now().subtract(Duration(days: 30));
//final supabaseClient = SupabaseClient('url', 'key');
final supabaseClient = SupaFlow.client;
final response = await supabaseClient
.from('posts')
.select('beverage_name_de,beverage_name_en,count(*)')
.eq('user_id', user)
.gte('created_at', thirtyDaysAgo.toIso8601String())
.group('beverage_name_de,beverage_name_en')
.execute();
final List<dynamic> result = response.data;
return result;
/// MODIFY CODE ONLY ABOVE THIS LINE
}