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

Unified Flutter location SDK featuring Kalman filtering, adaptive battery optimization, motion detection, geofencing, mock detection, route compression, 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 MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AllInOne Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String _status = 'Idle';
  AllInOneLocation? _currentLocation;
  bool _isTracking = false;

  Future<void> _requestPermissions() async {
    setState(() => _status = 'Requesting permissions...');
    final results = await AllInOnePermission.requestAllPermissions();
    final bool anyGranted = results.values.any((status) => status.isGranted);
    setState(() {
      _status = anyGranted ? 'Permissions Granted' : 'Permissions Denied';
    });
  }

  Future<void> _getLocation() async {
    setState(() => _status = 'Fetching location...');
    try {
      final location = await AllInOneLocationService.getCurrentLocation();
      setState(() {
        _currentLocation = location;
        _status = 'Location obtained';
      });
    } catch (e) {
      setState(() => _status = 'Location Error: $e');
    }
  }

  Future<void> _toggleTracking() async {
    if (_isTracking) {
      await AllInOneBackground.stopTracking();
      setState(() {
        _isTracking = false;
        _status = 'Tracking Stopped';
      });
    } else {
      await AllInOneBackground.initializeService();
      await AllInOneBackground.startTracking();
      setState(() {
        _isTracking = true;
        _status = 'Tracking Started';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AllInOne Package Example'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  children: [
                    Text('Status: $_status', style: Theme.of(context).textTheme.titleMedium),
                    const SizedBox(height: 8),
                    if (_currentLocation != null) ...[
                      Text('Lat: ${_currentLocation!.latitude}'),
                      Text('Lng: ${_currentLocation!.longitude}'),
                      Text('Accuracy: ${_currentLocation!.accuracy} m'),
                    ],
                  ],
                ),
              ),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _requestPermissions,
              child: const Text('Request Permissions'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: _getLocation,
              child: const Text('Get Current Location'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: _toggleTracking,
              child: Text(_isTracking ? 'Stop Background Tracking' : 'Start Background Tracking'),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
160
points
675
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Unified Flutter location SDK featuring Kalman filtering, adaptive battery optimization, motion detection, geofencing, mock detection, route compression, 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