tracelet_firebase 1.0.1 copy "tracelet_firebase: ^1.0.1" to clipboard
tracelet_firebase: ^1.0.1 copied to clipboard

Firebase adapter for Tracelet. Automatically configures native HTTP sync to push locations directly to the Firebase RTDB and manages background auth token refresh.

Tracelet Firebase Adapter #

The official Firebase adapter for Tracelet.

This adapter seamlessly connects Tracelet's battery-efficient native HTTP sync engine to the Firebase Realtime Database (RTDB) via its REST API. By pushing locations directly to the RTDB, you achieve 100% serverless, zero-cost (free tier) background location tracking without the need to deploy Cloud Functions.

Features #

  • Zero Cloud Functions: Syncs directly to RTDB via Firebase's REST API.
  • Auto Token Refresh: Automatically detects 401 errors in the background and refreshes the Firebase Auth ID token natively.
  • Batch Syncing: Compatible with Tracelet's batch engine out of the box.

Getting Started #

  1. Set up Firebase in your Flutter app using firebase_core and firebase_auth.
  2. Initialize Tracelet using TraceletFirebase.
import 'package:tracelet_firebase/tracelet_firebase.dart';
import 'package:firebase_auth/firebase_auth.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  // 1. Configure the auto-token refresher
  await TraceletFirebase.configureTokenRefresh();

  // 2. Build the HTTP Config pointing to your RTDB
  final user = FirebaseAuth.instance.currentUser;
  if (user != null) {
    final httpConfig = await TraceletFirebase.buildHttpConfig(
      databaseUrl: 'https://your-project-default-rtdb.firebaseio.com',
      path: 'locations/${user.uid}', // Secure this path in your RTDB rules
    );

    // 3. Start Tracelet
    await Tracelet.ready(Config(
      http: httpConfig,
    ));
  }
}

Security Rules #

Make sure to secure your RTDB to only allow authenticated users to write to their own location path:

{
  "rules": {
    "locations": {
      "$uid": {
        ".read": "auth != null && auth.uid === $uid",
        ".write": "auth != null && auth.uid === $uid"
      }
    }
  }
}
1
likes
160
points
1.66k
downloads

Documentation

API reference

Publisher

verified publisherikolvi.com

Weekly Downloads

Firebase adapter for Tracelet. Automatically configures native HTTP sync to push locations directly to the Firebase RTDB and manages background auth token refresh.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

Dependencies

firebase_auth, firebase_core, flutter, tracelet

More

Packages that depend on tracelet_firebase