I'm developing a Flutter application that utilizes Supabase to fetch data from the promotion table based on user information. The goal is to retrieve a single promotion entry that matches specific criteria:
I would like to know how to get a single row from a supabase in Custom Action.
Thank you in advance.
target_genders
includesuserGender
target_grades
includesuserGrade
answered_users
does not includeuserID
Limit the result to 1 entry
Here is the relevant portion of my current code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
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!
// Custom action code begins
Future<PromotionRow?> getZconnection(
String? userID,
String? userGrade,
String? userGender,
) async {
// Obtain Supabase client
final supabase = SupaFlow.client;
// Execute query
final response = await supabase
.from('promotion') // Table name
.select()
.contains('target_genders',
[userGender]) // Includes userGender in target_genders
.contains(
'target_grades', [userGrade]) // Includes userGrade in target_grades
.not('answered_users', 'cs',
'{"$userID"}') // Excludes userID from answered_users
.limit(1)
.maybeSingle(); // Replaced execute() with maybeSingle()
// Check if response or data is null
if (response == null || response.data == null) {
return null;
}
// Convert data to PromotionRow and return
return PromotionRow(response.data!);
}
current error:
The getter 'data' isn't defined for the type 'PostgrestMap'. Try importing the library that defines 'data', correcting the name to the name of an existing getter, or defining a getter or field named 'data'.
The getter 'data' isn't defined for the type 'PostgrestMap'. Try importing the library that defines 'data', correcting the name to the name of an existing getter, or defining a getter or field named 'data'.