Hi,
I am trying to add a custom function in order to read initially a supabase table, I need this function to read multiple table and create in output a json file for a listview, this is the starting point
Asking AI to create this function it looks quite simple BUT I am not able to find the Supabase client (I have seen that it should be fixed, it does not work for me) and the error is
Compilation error: Info: Compiling with sound null safety
lib/main.dart:18:20:
Error: Method not found: 'SupabaseClient'.
final supabase = SupabaseClient(
^^^^^^^^^^^^^^
lib/main.dart:36:18:
Error: 'await' can only be used in 'async' or 'async*' methods.
final myJson = await readSupabaseTable('my_table');
^^^^^
Error: Compilation failed.
I have seen this post but the error is still there for me
https://github.com/FlutterFlow/flutterflow-issues/issues/2002
Any ideas?
not only, in the code I have always the "await" error and if you try to fix the error it is going to change the call, so it invalidate the function,
of course I have changed it with my url, anon key, tables and so on ...
do you have some working example?
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/supabase/supabase.dart';
import '/auth/supabase_auth/auth_util.dart';
String? getAvailability(DateTime? myDate) {
/// MODIFY CODE ONLY BELOW THIS LINE
// write a function to read a supabase table and return a json
// Import necessary packages
// Define Supabase credentials
final supabase = SupabaseClient(
'https://<your-project-id>.supabase.co',
'<your-anon-key>',
);
// Define function to read Supabase table and return JSON
Future<String?> readSupabaseTable(String tableName) async {
final response = await supabase.from(tableName).select().execute();
if (response.error != null) {
print(response.error!.message);
return null;
}
final data = response.data;
final json = data != null ? jsonEncode(data) : null;
return json;
}
// Call function with table name as argument
final myJson = await readSupabaseTable('my_table');
print(
myJson); // This will print the JSON data from the 'my_table' table in Supabase.
/// MODIFY CODE ONLY ABOVE THIS LINE
}
Thanks a lot!