Showing
5 changed files
with
35 additions
and
14 deletions
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | Improvements: | 2 | Improvements: |
| 3 | * The `type` of an `Email` is now non-null. | 3 | * The `type` of an `Email` is now non-null. |
| 4 | * The `phoneNumber` of an `SMS` is now non-null. | 4 | * The `phoneNumber` of an `SMS` is now non-null. |
| 5 | +* The `latitude` and `longitude` of a `GeoPoint` are now non-null. | ||
| 5 | 6 | ||
| 6 | ## 3.5.0 | 7 | ## 3.5.0 |
| 7 | New Features: | 8 | New Features: |
| @@ -17,6 +17,7 @@ export 'src/objects/barcode_capture.dart'; | @@ -17,6 +17,7 @@ export 'src/objects/barcode_capture.dart'; | ||
| 17 | export 'src/objects/calendar_event.dart'; | 17 | export 'src/objects/calendar_event.dart'; |
| 18 | export 'src/objects/driver_license.dart'; | 18 | export 'src/objects/driver_license.dart'; |
| 19 | export 'src/objects/email.dart'; | 19 | export 'src/objects/email.dart'; |
| 20 | +export 'src/objects/geo_point.dart'; | ||
| 20 | export 'src/objects/mobile_scanner_arguments.dart'; | 21 | export 'src/objects/mobile_scanner_arguments.dart'; |
| 21 | export 'src/objects/sms.dart'; | 22 | export 'src/objects/sms.dart'; |
| 22 | export 'src/objects/wifi.dart'; | 23 | export 'src/objects/wifi.dart'; |
| @@ -2,6 +2,7 @@ import 'dart:math' as math; | @@ -2,6 +2,7 @@ import 'dart:math' as math; | ||
| 2 | 2 | ||
| 3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:mobile_scanner/mobile_scanner.dart'; | 4 | import 'package:mobile_scanner/mobile_scanner.dart'; |
| 5 | +import 'package:mobile_scanner/src/objects/geo_point.dart'; | ||
| 5 | 6 | ||
| 6 | Size toSize(Map data) { | 7 | Size toSize(Map data) { |
| 7 | final width = data['width'] as double; | 8 | final width = data['width'] as double; |
| @@ -9,6 +9,7 @@ import 'package:mobile_scanner/src/enums/phone_type.dart'; | @@ -9,6 +9,7 @@ import 'package:mobile_scanner/src/enums/phone_type.dart'; | ||
| 9 | import 'package:mobile_scanner/src/objects/calendar_event.dart'; | 9 | import 'package:mobile_scanner/src/objects/calendar_event.dart'; |
| 10 | import 'package:mobile_scanner/src/objects/driver_license.dart'; | 10 | import 'package:mobile_scanner/src/objects/driver_license.dart'; |
| 11 | import 'package:mobile_scanner/src/objects/email.dart'; | 11 | import 'package:mobile_scanner/src/objects/email.dart'; |
| 12 | +import 'package:mobile_scanner/src/objects/geo_point.dart'; | ||
| 12 | import 'package:mobile_scanner/src/objects/sms.dart'; | 13 | import 'package:mobile_scanner/src/objects/sms.dart'; |
| 13 | import 'package:mobile_scanner/src/objects/wifi.dart'; | 14 | import 'package:mobile_scanner/src/objects/wifi.dart'; |
| 14 | 15 | ||
| @@ -242,20 +243,6 @@ class PersonName { | @@ -242,20 +243,6 @@ class PersonName { | ||
| 242 | pronunciation = data['pronunciation'] as String?; | 243 | pronunciation = data['pronunciation'] as String?; |
| 243 | } | 244 | } |
| 244 | 245 | ||
| 245 | -/// GPS coordinates from a 'GEO:' or similar QRCode type. | ||
| 246 | -class GeoPoint { | ||
| 247 | - /// Gets the latitude. | ||
| 248 | - final double? latitude; | ||
| 249 | - | ||
| 250 | - /// Gets the longitude. | ||
| 251 | - final double? longitude; | ||
| 252 | - | ||
| 253 | - /// Create a [GeoPoint] from native data. | ||
| 254 | - GeoPoint.fromNative(Map data) | ||
| 255 | - : latitude = data['latitude'] as double?, | ||
| 256 | - longitude = data['longitude'] as double?; | ||
| 257 | -} | ||
| 258 | - | ||
| 259 | /// Phone number info. | 246 | /// Phone number info. |
| 260 | class Phone { | 247 | class Phone { |
| 261 | /// Gets phone number. | 248 | /// Gets phone number. |
lib/src/objects/geo_point.dart
0 → 100644
| 1 | +/// GPS coordinates from a `GEO:` or similar QRCode type. | ||
| 2 | +class GeoPoint { | ||
| 3 | + /// Construct a new [GeoPoint] instance. | ||
| 4 | + const GeoPoint({ | ||
| 5 | + required this.latitude, | ||
| 6 | + required this.longitude, | ||
| 7 | + }); | ||
| 8 | + | ||
| 9 | + /// Construct a [GeoPoint] from the given [data]. | ||
| 10 | + /// | ||
| 11 | + /// If the data does not contain valid GeoPoint coordinates, | ||
| 12 | + /// then `0,0` is returned. | ||
| 13 | + factory GeoPoint.fromNative(Map<Object?, Object?> data) { | ||
| 14 | + final double? latitude = data['latitude'] as double?; | ||
| 15 | + final double? longitude = data['longitude'] as double?; | ||
| 16 | + | ||
| 17 | + // If either is not set, then this GeoPoint is invalid. | ||
| 18 | + // Return the geographic center as fallback. | ||
| 19 | + if (latitude == null || longitude == null) { | ||
| 20 | + return const GeoPoint(latitude: 0.0, longitude: 0.0); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + return GeoPoint(latitude: latitude, longitude: longitude); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /// The latitude of the coordinate. | ||
| 27 | + final double latitude; | ||
| 28 | + | ||
| 29 | + /// The longitude of the coordinate. | ||
| 30 | + final double longitude; | ||
| 31 | +} |
-
Please register or login to post a comment