Skip to content

Community Addition: Offline Supabase #1039

Closed
@tshedor

Description

@tshedor

Hey Supabase team, this isn't a bug report or a feature request. We've added offline functionality to the Supabase client in Brick, and I wanted to share it with the larger community.

Brick caches remote data locally so that apps always function the same offline as they do online. Models are defined in Dart while generated code handles the Supabase/SQLite querying under the hood; the application then uses a simple ORM to work with data (and even react to data). If a request is made offline, it's retried until the client comes back online.

The Brick Supabase integration adds this generation and querying capability for Supabase apps with a straightforward setup. But Supabase's client can still made offline without using Brick:

import 'package:brick_offline_first_with_rest/offline_queue.dart';
import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:http/http.dart' as http;

final client = RestOfflineQueueClient(
  http.Client(),
  RestRequestSqliteCacheManager(
    'brick_offline_queue.sqlite',
    databaseFactory: databaseFactory,
  ),
  // Don't retry auth or storage requests; optionally add '/functions/v1' to not retry functions
  ignorePaths: {'/auth/v1','/storage/v1'},
);
final queue = RestOfflineRequestQueue(client: client);
await Supabase.initialize(..., httpClient: client); // or SupabaseClient(..., httpClient: client)
await client.requestManager.migrate();
queue.start();

If this is useful, I'd be happy to write a blog or more thorough example app to illustrate using Supabase while offline.


Sorry for opening an issue if this was the wrong place; I don't have Twitter and didn't see a link/email in the Supa Update newsletter to submit community work (although it would be a great honor if Brick's Supabase integration was mentioned in September's update). cc @devj3ns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions