Using Supabase in Custom Actions

Posting this because I couldn't find it in the forum or on the repository.

Here is an example for using supabase in a custom action

// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/backend/supabase/supabase.dart';
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!

Future<SubcategoriesRow> getSubCategory(
  int categoryId,
  int? subCategoryId,
) async {
  final supabase = SupaFlow.client;

  final response = await supabase
      .from('subcategories')
      .select('*')
      .eq('category_id', categoryId)
      .eq('subcategory_id', subCategoryId)
      .execute();

  return SubcategoriesRow(response.data![0]);
}
11
6 replies