Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Flutter SDK

Add to pubspec.yaml:

dependencies:
bunbase_flutter: ^0.13.0

Then run:

Terminal window
flutter pub get

Required Flutter permissions (Android — AndroidManifest.xml):

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

No extra configuration is needed for iOS or Web.


Create a single BunBaseClient instance — typically in a dependency provider or a top-level singleton:

import 'package:bunbase_flutter/bunbase_flutter.dart';
final bunbase = BunBaseClient('https://api.example.com');
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Restore a persisted session from Keychain / Android Keystore.
await bunbase.auth.restoreSession();
// Start listening for connectivity changes to auto-flush the offline queue.
await bunbase.offlineQueue.startMonitoring();
runApp(const MyApp());
}

class Post {
final String id;
final String title;
Post({required this.id, required this.title});
factory Post.fromJson(Map<String, dynamic> j) =>
Post(id: j['id'], title: j['title']);
}
final posts = bunbase.collection('posts', Post.fromJson);

auth.currentUser is a ValueNotifier<AuthUser?> — wire it directly to ValueListenableBuilder:

ValueListenableBuilder<AuthUser?>(
valueListenable: bunbase.auth.currentUser,
builder: (context, user, _) {
if (user == null) return const LoginPage();
return HomeScreen(user: user);
},
)

All methods throw a subclass of BunBaseError:

TypeWhen
ServerErrorHTTP 4xx / 5xx — includes .status, .message, .code, .field
NetworkErrorNo connectivity or socket error
UnauthenticatedError401 after token refresh failed
DecodingErrorMalformed JSON response
TimeoutErrorPing / presence timeout
try {
await bunbase.auth.login(email, password);
} on ServerError catch (e) {
if (e.code == 'invalid_credentials') showSnack('Wrong email or password');
} on NetworkError catch (_) {
showSnack('No internet connection');
}

Tokens are automatically persisted to the platform secure store:

PlatformStore
iOS / macOSKeychain
AndroidEncryptedSharedPreferences (AES-256-GCM)
Linuxlibsecret
WindowsCredential Manager

Call auth.restoreSession() once on startup to load the persisted tokens without a network round-trip.

Pass enableTokenStore: false to BunBaseClient to disable persistence (useful for tests).