allinone_location 4.2.0 copy "allinone_location: ^4.2.0" to clipboard
allinone_location: ^4.2.0 copied to clipboard

Enterprise Flutter location SDK featuring Fused Location, Kalman smoothing, adaptive engines, geofencing, background recovery, diagnostic UI, and offline sync.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:allinone_location/allinone_location.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const AllInOneExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AllInOne Location SDK Showcase',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: const Color(0xFF02569B),
          brightness: Brightness.light,
        ),
        useMaterial3: true,
      ),
      home: const MainShowcaseScreen(),
    );
  }
}

class MainShowcaseScreen extends StatefulWidget {
  const MainShowcaseScreen({super.key});

  @override
  State<MainShowcaseScreen> createState() => _MainShowcaseScreenState();
}

class _MainShowcaseScreenState extends State<MainShowcaseScreen> {
  int _selectedIndex = 0;
  String _statusMessage = 'SDK Ready';
  AllInOneLocation? _lastFix;
  bool _isBackgroundActive = false;
  final List<AllInOneLocation> _recordedRoute = [];

  @override
  void initState() {
    super.initState();
    _setupGeofences();
  }

  void _setupGeofences() {
    final geofenceManager = AllInOneLocationSDK.geofences;
    geofenceManager.addRegion(GeofenceRegion.circle(
      id: 'demo_circle',
      centerLatitude: 12.9716,
      centerLongitude: 77.5946,
      radiusMeters: 150.0,
    ));

    geofenceManager.onGeofenceEvent.listen((event) {
      if (mounted) {
        setState(() {
          _statusMessage = '🚩 Geofence [${event.geofenceId}] event: ${event.type.name}';
        });
      }
    });
  }

  Future<void> _requestPermissions() async {
    setState(() => _statusMessage = 'Requesting location permissions...');
    final result = await AllInOnePermission.requestAllPermissions();
    final anyGranted = result.values.any((status) => status.isGranted);
    if (mounted) {
      setState(() {
        _statusMessage = anyGranted
            ? '✅ All Location & Notification Permissions Granted'
            : '⚠️ Permission Request Incomplete';
      });
    }
  }

  Future<void> _fetchHighAccuracyFix() async {
    setState(() => _statusMessage = 'Averaging multi-sample GPS centroid...');
    try {
      final loc = await AllInOneLocationSDK.getCurrentLocation(
        config: const AllInOneConfig(
          sampleCount: 3,
          enableKalmanFilter: true,
          enableSpeedEngine: true,
          enableAltitudeFiltering: true,
        ),
      );
      setState(() {
        _lastFix = loc;
        _recordedRoute.add(loc);
        _statusMessage = '✅ Location fix ready (Accuracy: ${loc.accuracy.toStringAsFixed(1)}m)';
      });
    } catch (e) {
      setState(() => _statusMessage = '❌ Location error: $e');
    }
  }

  Future<void> _toggleBackgroundService() async {
    if (_isBackgroundActive) {
      await AllInOneBackgroundService.stopService();
      setState(() {
        _isBackgroundActive = false;
        _statusMessage = 'Background tracking stopped';
      });
    } else {
      await AllInOneBackgroundService.initialize(
        config: const BackgroundConfig(
          notificationTitle: 'AllInOne Showcase',
          notificationContent: 'Real-time location monitoring active',
          heartbeatIntervalSeconds: 10,
        ),
      );
      await AllInOneBackgroundService.startService();
      setState(() {
        _isBackgroundActive = true;
        _statusMessage = '🟢 Background location tracking active';
      });
    }
  }

  void _runDistanceMatrixDemo() {
    final origins = [
      [12.9716, 77.5946],
      [12.9816, 77.6046]
    ];
    final destinations = [
      [13.0016, 77.6246],
      [13.0116, 77.6346]
    ];

    final matrix = DistanceMatrix.computeMatrix(origins: origins, destinations: destinations);
    final etaSeconds = DistanceMatrix.estimateTravelTimeSeconds(matrix[0][0], mode: 'driving');

    showDialog(
      context: context,
      builder: (ctx) => AlertDialog(
        title: const Text('Distance Matrix & ETA'),
        content: Text(
          'Distance O1->D1: ${matrix[0][0].toStringAsFixed(1)} meters\n'
          'Estimated Driving ETA: ${(etaSeconds / 60).toStringAsFixed(1)} mins',
        ),
        actions: [
          TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('Close')),
        ],
      ),
    );
  }

  void _exportRouteData() {
    if (_recordedRoute.isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Please fetch a location fix first!')),
      );
      return;
    }

    final gpxXml = GpxExporter.export(points: _recordedRoute, trackName: 'Showcase Route');
    showModalBottomSheet(
      context: context,
      builder: (ctx) => Padding(
        padding: const EdgeInsets.all(16.0),
        child: SingleChildScrollView(
          child: SelectableText(gpxXml, style: const TextStyle(fontFamily: 'monospace', fontSize: 12)),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AllInOne Location SDK'),
        actions: [
          IconButton(
            icon: const Icon(Icons.download),
            tooltip: 'Export GPX',
            onPressed: _exportRouteData,
          ),
        ],
      ),
      body: IndexedStack(
        index: _selectedIndex,
        children: [
          _buildLiveTelemetryTab(),
          const AllInOneDiagnosticDashboard(),
        ],
      ),
      bottomNavigationBar: NavigationBar(
        selectedIndex: _selectedIndex,
        onDestinationSelected: (idx) => setState(() => _selectedIndex = idx),
        destinations: const [
          NavigationDestination(icon: Icon(Icons.my_location), label: 'Telemetry'),
          NavigationDestination(icon: Icon(Icons.dashboard_customize), label: 'Diagnostics'),
        ],
      ),
    );
  }

  Widget _buildLiveTelemetryTab() {
    return SingleChildScrollView(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Card(
            color: Theme.of(context).colorScheme.primaryContainer,
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Text(
                _statusMessage,
                style: const TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
          ),
          const SizedBox(height: 12),
          Wrap(
            spacing: 8,
            runSpacing: 8,
            children: [
              ElevatedButton.icon(
                onPressed: _requestPermissions,
                icon: const Icon(Icons.security),
                label: const Text('Permissions'),
              ),
              ElevatedButton.icon(
                onPressed: _fetchHighAccuracyFix,
                icon: const Icon(Icons.gps_fixed),
                label: const Text('Get Fix'),
              ),
              ElevatedButton.icon(
                onPressed: _toggleBackgroundService,
                icon: Icon(_isBackgroundActive ? Icons.stop : Icons.play_arrow),
                label: Text(_isBackgroundActive ? 'Stop Service' : 'Start Service'),
              ),
              ElevatedButton.icon(
                onPressed: _runDistanceMatrixDemo,
                icon: const Icon(Icons.map),
                label: const Text('Distance Matrix'),
              ),
            ],
          ),
          const SizedBox(height: 16),
          if (_lastFix != null) ...[
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text('Location Telemetry', style: Theme.of(context).textTheme.titleMedium),
                    const Divider(),
                    Text('Coordinates: ${_lastFix!.latitude.toStringAsFixed(6)}, ${_lastFix!.longitude.toStringAsFixed(6)}'),
                    Text('Accuracy: ${_lastFix!.accuracy.toStringAsFixed(1)} meters'),
                    Text('Filtered Altitude: ${_lastFix!.filteredAltitude.toStringAsFixed(1)} meters'),
                    Text('Smoothed Speed: ${_lastFix!.smoothedSpeed.toStringAsFixed(2)} m/s'),
                    Text('Activity State: ${_lastFix!.activityType.name}'),
                    Text('Indoor/Outdoor: ${_lastFix!.indoorOutdoorState.name}'),
                    Text('Confidence Quality: ${_lastFix!.confidenceScore.toStringAsFixed(1)}%'),
                  ],
                ),
              ),
            ),
          ],
        ],
      ),
    );
  }
}
3
likes
150
points
675
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Enterprise Flutter location SDK featuring Fused Location, Kalman smoothing, adaptive engines, geofencing, background recovery, diagnostic UI, and offline sync.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

flutter, flutter_background_service, flutter_local_notifications, geolocator, permission_handler, shared_preferences

More

Packages that depend on allinone_location