| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import 'package:flutter/foundation.dart';
- /// Native GPS speed snapshot. Speed is in km/h; a stationary fix is 0.
- @immutable
- class GpsSpeed {
- const GpsSpeed({
- this.hasPermission = false,
- this.hasFix = false,
- this.speedKmh,
- this.updatedAt = 0,
- });
- final bool hasPermission;
- final bool hasFix;
- final double? speedKmh;
- final int updatedAt;
- bool isFresh(DateTime now) {
- if (!hasFix || speedKmh == null || updatedAt <= 0) return false;
- final age = now.millisecondsSinceEpoch - updatedAt;
- return age >= 0 && age < 5000;
- }
- factory GpsSpeed.fromMap(Map<dynamic, dynamic> map) {
- return GpsSpeed(
- hasPermission: map['hasPermission'] == true,
- hasFix: map['hasFix'] == true,
- speedKmh: (map['speedKmh'] as num?)?.toDouble(),
- updatedAt: (map['updatedAt'] as num?)?.toInt() ?? 0,
- );
- }
- @override
- bool operator ==(Object other) {
- return other is GpsSpeed &&
- other.hasPermission == hasPermission &&
- other.hasFix == hasFix &&
- other.speedKmh == speedKmh &&
- other.updatedAt == updatedAt;
- }
- @override
- int get hashCode => Object.hash(hasPermission, hasFix, speedKmh, updatedAt);
- }
|