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 topubspec.yaml:
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 fluentQueryBuilder:
Count & aggregate
Type Safety
Register a converter once at startup, then all calls for that type are automatically converted: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 ofCocobaseError. 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
- JavaScript SDK — JS/TS equivalent
- MCP Server — AI assistant integration
- Authentication guide
- Querying guide
- Real-time guide
