An open API service indexing awesome lists of open source software.

https://github.com/thomasdevapps/flutter_supabase_macro

Macro greatly inspired by JsonCodable (from Dart), makes it easy to create a JSON format of a template for Supabase.
https://github.com/thomasdevapps/flutter_supabase_macro

flutter macro macros supabase

Last synced: about 2 months ago
JSON representation

Macro greatly inspired by JsonCodable (from Dart), makes it easy to create a JSON format of a template for Supabase.

Awesome Lists containing this project

README

          

# Flutter Supabase Macro

![testing workflow](https://github.com/ThomasDevApps/flutter_supabase_macro/actions/workflows/main.yml/badge.svg)

Package greatly inspired by `JsonCodable` (from Dart), makes it easy to create
a JSON format of a template for Supabase.

| Before | After |
|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| ![before](https://raw.githubusercontent.com/ThomasDevApps/flutter_supabase_macro/main/assets/before.png) | ![after](https://raw.githubusercontent.com/ThomasDevApps/flutter_supabase_macro/main/assets/after.png) |

- [What is a macro](#-what-is-a-macro)
- [Getting started](#-getting-started)
- [How it works](#-how-it-works)
- [Additional information](#-additional-information)

## ❔ What is a macro

A Dart macro is a user-definable piece of code that takes in other code as
parameters and operates on it in real-time to create, modify, or add declarations.

Find out more at https://dart.dev/language/macros

## 🚀 Getting started

Because the macros are still under development, you need to follow these
instructions to be able to test this package : https://dart.dev/language/macros#set-up-the-experiment

Then add in your `pubspec.yaml` :

```yaml
flutter_supabase_macro:
git:
url: https://github.com/ThomasDevApps/flutter_supabase_macro.git
```

## 🔎 How it works
Let's imagine the `User` class :

```dart
class User {
final String id;
final String name;
final int age;

const User({required this.id, required this.name, required this.age});
}
```
Let's assume that in your Supabase `users` table, the primary key is named `id`.

All you need to do is add the following :

```dart
@FlutterSupabaseMacro(primaryKey: 'id') // Add this (primaryKey is 'id' by default)
class User {
// ...
}
```
It will generate a `toJsonSupabase()` method that returns a `Map`.

## 📖 Additional information

This package is still undergoing experimentation, and is in no way intended for
use in production apps.

Not officially affiliated with Supabase.