tracelet_supabase 3.8.7 copy "tracelet_supabase: ^3.8.7" to clipboard
tracelet_supabase: ^3.8.7 copied to clipboard

Supabase adapter for Tracelet. Automatically configures Tracelet's native HTTP sync to push locations to Supabase and manages background auth token refresh.

example/example.dart

import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:tracelet/tracelet.dart';
import 'package:tracelet_supabase/tracelet_supabase.dart';

// Replace these with your actual Supabase project credentials
const supabaseUrl = 'YOUR_SUPABASE_URL';
const supabaseAnonKey = 'YOUR_SUPABASE_ANON_KEY';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 1. Initialize Supabase
  await Supabase.initialize(url: supabaseUrl, anonKey: supabaseAnonKey);

  // 2. Configure Token Refresh (Crucial for background tracking)
  await TraceletSupabase.configureTokenRefresh(anonKey: supabaseAnonKey);

  // 3. Build the Native HTTP Config
  final httpConfig = TraceletSupabase.buildHttpConfig(
    supabaseUrl: supabaseUrl,
    anonKey: supabaseAnonKey,
    edgeFunction: 'tracelet-ingest',
  );

  // 4. Initialize Tracelet
  final baseConfig = Config.balanced();
  await Tracelet.ready(
    baseConfig.copyWith(
      geo: baseConfig.geo.copyWith(distanceFilter: 50),
      http: httpConfig,
      android: baseConfig.android.copyWith(
        foregroundService: baseConfig.android.foregroundService.copyWith(
          enabled: true, // Required for continuous tracking when terminated
          showNotificationOnPauseOnly:
              true, // Hides notification while app is in foreground
          notificationTitle: 'Tracelet Tracker',
          notificationText: 'Actively tracking your route',
          actions: ['Stop Tracking'],
        ),
      ),
    ),
  );

  // 5. Smart Functionality: Handle action buttons from the notification
  Tracelet.onNotificationAction((action) async {
    if (action == 'Stop Tracking') {
      await Tracelet.stop();
    }
  });

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Tracelet Supabase Adapter')),
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              // Sign in anonymously for testing
              await Supabase.instance.client.auth.signInAnonymously();

              // Request location permissions before starting
              await Tracelet.requestLocationAuthorization();

              // Request notification permissions (Required for Android 13+ foreground service)
              await Tracelet.requestNotificationAuthorization();

              // Start tracking!
              await Tracelet.start();
            },
            child: const Text('Start Tracking'),
          ),
        ),
      ),
    );
  }
}
2
likes
160
points
2.9k
downloads

Documentation

Documentation
API reference

Publisher

verified publisherikolvi.com

Weekly Downloads

Supabase adapter for Tracelet. Automatically configures Tracelet's native HTTP sync to push locations to Supabase and manages background auth token refresh.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#supabase #location #sync

Funding

Consider supporting this project:

github.com
www.buymeacoffee.com
thanks.dev
www.patreon.com

License

Apache-2.0 (license)

Dependencies

flutter, meta, supabase_flutter, tracelet, tracelet_sync

More

Packages that depend on tracelet_supabase