A Flutter plugin for interacting with the Traccar API. This plugin allows you to authenticate with a Traccar server, fetch device information, and retrieve current and historical position data. It supports visualizing device locations and travel paths on a map using flutter_map.
- Authenticate with a Traccar server using email and password.
- Retrieve a list of registered devices.
- Fetch current positions for a specific device.
- Fetch historical positions within a specified date range.
- Display current positions on a map with markers.
- Visualize historical travel paths as polylines.
Add the following to your pubspec.yaml file:
dependencies:
traccar_api: ^1.0.0
flutter_map: ^6.0.0
latlong2: ^0.9.0
syncfusion_flutter_datepicker: ^20.0.0Then, run:
flutter pub getCreate an instance of TraccarApi with your Traccar server URL:
import 'package:traccar_api/traccar_api.dart';
final traccar = TraccarApi(baseUrl: 'http://demo.traccar.org:5055');Use your Traccar credentials to authenticate:
bool success = await traccar.authenticate(
email: 'admin@traccar.org',
password: 'admin',
);
if (success) {
print('Authentication successful');
} else {
print('Authentication failed');
}Retrieve a list of devices registered on the server:
List<TraccarDevice> devices = await traccar.getDevices();
print('Found ${devices.length} devices');Get the latest positions for a specific device:
final positions = await traccar.getPositions(deviceId: devices[0].id);
if (positions.isNotEmpty) {
print('Latest position: ${positions[0].latitude}, ${positions[0].longitude}');
}Retrieve positions for a device within a date range:
final positions = await traccar.getPositions(
deviceId: devices[0].id,
from: DateTime(2025, 7, 1),
to: DateTime(2025, 7, 16),
);
print('Found ${positions.length} historical positions');The example/ directory contains a complete Flutter app demonstrating how to:
- Authenticate with a Traccar server.
- Display a list of devices.
- Show current device positions on a map with markers.
- Visualize historical travel paths as polylines using a date range picker.
To run the example:
cd example
flutter runThis plugin requires the following dependencies:
flutter_map: For rendering maps.latlong2: For handling latitude and longitude coordinates.syncfusion_flutter_datepicker: For selecting date ranges in the example app.
Ensure these are included in your pubspec.yaml if you use the example or similar functionality.
- Replace
http://demo.traccar.org:5055with your Traccar server URL if you are using a private instance. - Ensure a stable internet connection to fetch data from the Traccar server and load OpenStreetMap tiles.
- For private servers, verify that your server supports the Traccar API and that your credentials are valid.
Contributions are welcome! Please submit issues or pull requests to the GitHub repository.
This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.