Convert dynamic (JSON) data to Supabase Row data type

Custom Code

Hi everyone!
I created a postgres function in Supabase that returns a list (SETOF) Stores (Stores is a table in my database).

I need to call this function in flutterflow and get the query result data as List<StoresRow> data type.
I created a custom action like this:


So the action returns a list of Supabase Rows, like the postgres function does.
The "response" variable correctly gets the data from supabase (i used the debugPrint to log the response and i got the json with the correct content printed in the console).
The data type of "response" variable is List<dynamic>.

So everything works fine, until the code returns the response variable, because then the return array becomes empty.
I think the problem is that i returned a variable of type List<dynamic> and not List<StoresRow>, so when trying to return as List<dynamic> it becomes empty.

My question is:
I nedd to return a List<StoresRow> type, so is there a way before the retun statement to convert the List<dynamic> (JSON) array to a List<StoresRow> (Subabase row) array?

Thanks a lot in advance.

What have you tried so far?
 final List<StoresRow> data = responseData.map((item) {
      // Adjust field names based on the actual structure
      return StoresRow(
        id: item['id'] as String,
        name: item['name'] as String,
        // Map other fields as necessary
      );
    }).toList();

Error: field id / name not found in StoresRow


final List<StoresRow> data = (response.data as List)
        .map((item) => StoresRow(
              id: item['id'] as String,
              name: item['name'] as String,
              // Map other fields as necessary
            ))
        .toList();

Error: field id / name not found in StoresRow


// Factory method to create an instance from JSON
  factory StoresRow.fromJson(Map<String, dynamic> json) {
    return StoresRow(
      id: json['id'],
      name: json['name'],
      // Initialize other fields
    );
  }

No "fromJson" method or similar existing in StoresRow class


final response = await supabase.rpc('user_followed_stores',
      params: {'userid': '65c2ae92-8102-4143-9fdf-c32a304e1669'}).withConverter<List<StoresRow>>((data) =>
        List<Map<String, dynamic>>.from(data).map(StoresRow.fromJson).toList());

Nothing changed adding ".withConverter..."

Did you check FlutterFlow's Documentation for this topic?
Yes
4
11 replies