Kite docs

Data layer

One interface, three adapters. Screens never talk to HTTP.

The contract

typedef JsonMap = Map<String, Object?>;

abstract interface class DataProvider {
  Future<ListResult> getList(String resource, ListParams params);
  Future<JsonMap>   getOne (String resource, String id);
  Future<JsonMap>   create (String resource, JsonMap data);
  Future<JsonMap>   update (String resource, String id, JsonMap data);
  Future<void>      delete (String resource, String id);
}

Deliberately untyped at the boundary. The template cannot know your models, and forcing a codegen step on someone evaluating a template is how you lose them in the first ten minutes. Decode into your own types above this line.

ListParams and ListResult

const ListParams({
  int page = 1,
  int perPage = 25,
  SortSpec? sort,
  String search = '',
  Map<String, Object?> filters = const {},
});

class ListResult {
  final List<JsonMap> rows;   // this page
  final int total;            // across ALL pages
}

total is the count across every page, not the length of the page you were handed. Getting this wrong still renders a table — it just paginates wrongly, which is the kind of bug nobody notices until a customer reports missing records.

Switching backend

Backend selection lives in lib/core/data/data_source.dart. With no configuration, Kite uses seeded in-memory data. With Supabase Auth, it selects Supabase data automatically. To use authenticated REST:

flutter run -d chrome --dart-define-from-file=config/production.local.json --dart-define=KITE_API_URL=https://api.example.com

Resource CRUD, command search, and dashboard record lists use this provider. Dashboard metrics and app examples still include sample data. Authentication is configured through AuthRepository; see Authentication.

With Supabase Auth configured, no factory edit is needed: the data source selects Supabase automatically and reads the current token for each request. A configured REST API receives the same bearer token. Its server must verify JWTs and enforce permissions independently.

For your own adapter, implement DataProvider and retain the AuthorizedDataProvider wrapper in data_source.dart:

return AuthorizedDataProvider(
  MyDataProvider(),
  currentUser: () => ref.read(sessionProvider),
);

Build-time values are public. Never embed a service-role key. The included role migration enforces permissions through RLS. For cross-origin REST APIs, expose X-Total-Count through CORS so browser pagination can read the total. See Authentication and roles for setup.

MockDataProvider

The most important adapter, because it is what someone sees in the first sixty seconds. It does real work — search, filter, sort and paginate all execute against in-memory tables and return a page plus a total — so your screens exercise the same code paths a real backend will.

Seeded deterministically: 1,284 orders, 642 customers, 312 products. Latency is simulated at 180ms and configurable, so loading states are visible during development instead of flashing past.

MockDataProvider(latency: Duration.zero)   // for tests

RestDataProvider

Assumes the shape most JSON APIs already use:

GET    /orders?_page=1&_limit=25&_sort=total&_order=desc&q=ada&status=Paid
GET    /orders/10004
POST   /orders
PATCH  /orders/10004
DELETE /orders/10004

The row count comes from an X-Total-Count header, falling back to a total field on an envelope. Bodies may be a bare array or { "data": [...], "total": n } — both are unwrapped.

If your API spells any of that differently, rest_data_provider.dart is the one file to change. It is about 120 lines.

SupabaseDataProvider

Talks to PostgREST over http, using the current Supabase Auth token on every request. Token refresh does not leave a stale bearer token in the data adapter. Role-aware route and data guards mirror server policy; database RLS remains the security boundary.

// Count comes from Content-Range, requested with Prefer: count=exact
Range: 25-49
Content-Range: 25-49/1284

Search needs columns named explicitly — PostgREST has no "search everything". Edit SupabaseDataProvider.searchColumns for your tables.

Errors

Every adapter throws DataProviderException with a readable message. Screens render it through ErrorState, which offers a retry — a spinner that never resolves is worse than an error.

async.when(
  loading: () => const LoadingState(),
  error: (e, _) => ErrorState(
    message: e is DataProviderException ? e.message : '$e',
    onRetry: () => ref.invalidate(listProvider(resource)),
  ),
  data: (result) => …,
)

Writing your own

Implement the five methods. The tests in test/rest_provider_test.dart show the shape — a fake http.Client, then assertions on query construction, total parsing, and a 404 becoming an exception rather than a crash. Copy that file and point it at yours.