Null returned from Supabase RPC Function to Flutterflow
Custom Code
I wanted to create a button in Flutterflow that triggers some actions to validate data among data tables in Supabase and create tables. From the online tutorials I learnt that I could set up SQL functions in SQL Editor (PostgreSQL) as well as a Custom Action in Flutterflow (not Custom Function). Those codes would allow Flutterflow to transfer values in the variables to Supabase as well as the opposite way. However, it returned Null every time I tried. I even restarted with a function which was supposed to return a true value, but it still returned Null. Is there something I missed, or I must use an API call?
Appreciate any help!
What have you tried so far?
Function created by SQL Editor:
create or replace function test_always_true()
returns boolean
language plpgsql
as $$
begin
return true;
end;
$$;
Custom Action in Flutterflow:
// Automatic FlutterFlow imports
import '/backend/supabase/supabase.dart';
import '/actions/actions.dart' as action_blocks;
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:supabase_flutter/supabase_flutter.dart' hide Provider;
Future<bool?> alwaysTrueDebug() async {
final response = await SupaFlow.client.rpc('test_always_true');
// Log the entire response object
print('Full response: ${response.toJson()}');
if (response.error != null) {
print('Error: ${response.error.message}');
return null; // Return null if there's an error
}
// Check the data type and structure
print('Test response: ${response.data}');
return response.data as bool?;
}
I made a button which triggers this custom action, naming "abc" as the Action Output Variable Name. I saw "Null" for this value in the Bebug Panel of the Test Mode.
I once set the RLS policy for all relevant tables in Supabase (per below), and tried again with RLS turned off, but it didn't make any change:
Behavior: Permissive Command: All (this means it applies to SELECT, INSERT, UPDATE, DELETE) Using Clause: true (this means that all users can access the rows in this table)
Access rights modified as suggested by the assistant chatbot (no change in results before and after):
grant execute on function test_always_true() to authenticated;
Did you check FlutterFlow's Documentation for this topic?