I use the below custom action to pass a query data type with two fields (fieldName and fieldValue). When I add the action to the flow, I can't choose to add list items.
Could this work like when adding items to a state variable?
import 'package:supabase_flutter/supabase_flutter.dart';
Future<String> sbSubscribeToEventsQuery(
String table,
List<SupabaseFieldQueryStruct>? fieldsQuery, // Query conditions
Future Function()? insertCallback,
Future Function()? updateCallback,
Future Function()? deleteCallback,
) async {
try {
final client = Supabase.instance.client;
// Create a new channel specific to the table
final channel = client.channel('public:$table');
// Build the filters from fieldsQuery.fieldsQuery
final List<PostgresChangeFilter> filters = fieldsQuery
?.map((filter) => PostgresChangeFilter(
type: PostgresChangeFilterType.eq, // Equality filter
column: filter.fieldName, // Column name
value: filter.fieldContent, // Value to match
))
.toList() ??
[];
// Subscribe to INSERT events if the callback is provided
if (insertCallback != null) {
channel.onPostgresChanges(
event: PostgresChangeEvent.insert,
schema: 'public',
table: table,
filter:
filters.isNotEmpty ? filters.first : null, // Use the first filter
callback: (payload) async => await insertCallback(),
);
}
// Subscribe to UPDATE events if the callback is provided
if (updateCallback != null) {
channel.onPostgresChanges(
event: PostgresChangeEvent.update,
schema: 'public',
table: table,
filter:
filters.isNotEmpty ? filters.first : null, // Use the first filter
callback: (payload) async => await updateCallback(),
);
}
// Subscribe to DELETE events if the callback is provided
if (deleteCallback != null) {
channel.onPostgresChanges(
event: PostgresChangeEvent.delete,
schema: 'public',
table: table,
filter:
filters.isNotEmpty ? filters.first : null, // Use the first filter
callback: (payload) async => await deleteCallback(),
);
}
// Activate the channel
channel.subscribe();
final result =
"Subscribed to table: $table with specified query filters and callbacks";
return result;
} catch (e) {
// Catch and return any errors
final result = "Error: ${e.toString()}";
return result;
}
}