flutter_google_track_and_trace/lib/src/controller.dart

75 lines
1.5 KiB
Dart
Raw Normal View History

2021-09-28 08:18:14 +02:00
part of google_track_trace;
2021-09-29 10:07:56 +02:00
class TrackTraceController extends ChangeNotifier {
2021-09-29 12:18:53 +02:00
GoogleMapController? _mapController;
Marker _startPosition;
Marker _destinationPosition;
TrackTraceRoute? _route;
2021-09-28 08:18:14 +02:00
2021-09-29 10:07:56 +02:00
TrackTraceController(Marker start, Marker destination)
2021-09-29 12:18:53 +02:00
: _startPosition = start,
_destinationPosition = destination;
2021-09-28 08:18:14 +02:00
2021-09-29 10:07:56 +02:00
set start(Marker start) {
2021-09-29 12:18:53 +02:00
_startPosition = start;
2021-09-29 10:07:56 +02:00
notifyListeners();
}
2021-09-28 08:18:14 +02:00
2021-09-29 10:07:56 +02:00
set end(Marker end) {
2021-09-29 12:18:53 +02:00
_destinationPosition = end;
2021-09-29 10:07:56 +02:00
notifyListeners();
}
2021-09-28 08:18:14 +02:00
2021-09-29 12:18:53 +02:00
Marker get start => _startPosition;
2021-09-28 08:18:14 +02:00
2021-09-29 12:18:53 +02:00
Marker get end => _destinationPosition;
2021-09-29 10:07:56 +02:00
2021-09-29 12:18:53 +02:00
TrackTraceRoute? get route => _route;
2021-09-29 10:07:56 +02:00
2021-09-29 12:18:53 +02:00
set route(TrackTraceRoute? newRoute) {
_route = newRoute;
2021-09-29 10:07:56 +02:00
notifyListeners();
2021-09-28 08:18:14 +02:00
}
2021-09-29 12:18:53 +02:00
set mapController(GoogleMapController? controller) {
2021-09-29 10:07:56 +02:00
_mapController = controller;
2021-09-28 08:18:14 +02:00
}
2021-09-29 10:07:56 +02:00
2021-09-29 12:18:53 +02:00
GoogleMapController? get mapController => _mapController;
2021-09-29 13:42:13 +02:00
@override
void dispose() {
_mapController?.dispose();
super.dispose();
}
2021-09-29 12:18:53 +02:00
}
class TrackTraceRoute {
/// route duration in seconds
2021-09-29 13:42:13 +02:00
int _duration = 0;
2021-09-29 12:18:53 +02:00
/// route distance in meters
2021-09-29 13:42:13 +02:00
int _distance = 0;
2021-09-29 12:18:53 +02:00
/// route edge points
2021-09-29 13:42:13 +02:00
final List<PointLatLng> line;
2021-09-29 12:18:53 +02:00
TrackTraceRoute(
int durationValue, int distanceValue, List<PointLatLng> lineValue)
2021-09-29 13:42:13 +02:00
: _duration = durationValue,
_distance = distanceValue,
2021-09-29 12:18:53 +02:00
line = lineValue;
2021-09-29 13:42:13 +02:00
int get distance => _distance;
int get duration => _duration;
set distance(int distance) {
_distance = distance;
}
set duration(int duration) {
_duration = duration;
}
2021-09-28 08:18:14 +02:00
}