Skip to main content

Flutter / Dart SDK

The official CocoBase Dart/Flutter SDK — works in Flutter apps, Dart CLI tools, and any Dart runtime. Package: coco_base_flutter  ·  Version: 1.2.x  ·  pub.dev: pub.dev/packages/coco_base_flutter

Installation

Add to pubspec.yaml:
Then run:

Initialization

CocobaseConfig options


Documents — CRUD

listDocuments<T>(collection, ...)

getDocument<T>(collection, id)

createDocument<T>(collection, data)

updateDocument(collection, id, data)

Partial update — only fields you pass are changed. Other fields are preserved.

deleteDocument(collection, id)


Querying

Filter operators

QueryBuilder (fluent API)

For complex queries, use the fluent QueryBuilder:
Available QueryBuilder methods:

Count & aggregate


Type Safety

Register a converter once at startup, then all calls for that type are automatically converted:
Alternatively pass the converter inline:

Live Queries — onSnapshot

Subscribe to a collection. Fires immediately with current data, then again on every create/update/delete. Returns a VoidCallback to cancel in dispose().
onSnapshot signature:

Pagination Helper — paginate

Stateful pagination — tracks page position, detects hasMore, no backend changes needed.

Authentication

Register / Login / Logout

Restore session — initAuth

Call once at app startup. Returns true if session was restored. Network errors and server errors do not log the user out — only an explicit 401/403 does.

Reactive auth — onAuthStateChange

Auth lifecycle callbacks

Update user


Real-time

Watch a collection

Project broadcast

Room chat


Cloud Functions


Typed Errors

All API errors throw a typed subclass of CocobaseError. Use is to branch:
All errors expose statusCode, url, method, detail, suggestion.

Widgets (package:coco_base_flutter/widgets.dart)

Import the widget library:

CocobaseQuery<T> — fetch-once widget

Fetches a collection once and rebuilds when data arrives. Handles loading and error states automatically.

CocobaseLiveQuery<T> — real-time widget

Stays in sync via WebSocket. Auto-subscribes in initState, auto-unsubscribes in dispose.

CocobaseDocument<T> — single document widget

Fetches and displays one document by ID.

CocobasePaginatedList<T> — paginated list

Supports load-more and numbered page modes.

CocobaseInfiniteList<T> — infinite scroll

Auto-loads next page as the user scrolls near the bottom.

CocobaseAuthBuilder — auth-aware widget

Rebuilds on auth state change. Renders different widgets for authenticated, unauthenticated, and loading states.

CocobaseErrorWidget — typed error display

Shows an appropriate icon and message for each error type, with an optional retry button.

CocobaseFutureBuilder<T> — generic async wrapper

CocobaseUserAvatar — user avatar widget

Reads data['avatar'], data['avatar_url'], or data['profile_image'] from the user object. Falls back to computed initials if no image is found.

Next Steps