Navaron Bracke

move Address to its own file

## NEXT
Improvements:
* The `type` of an `Address` is now non-null.
* The `type` of an `Email` is now non-null.
* The `phoneNumber` of an `SMS` is now non-null.
* The `latitude` and `longitude` of a `GeoPoint` are now non-null.
... ...
... ... @@ -12,6 +12,7 @@ export 'src/enums/torch_state.dart';
export 'src/mobile_scanner.dart';
export 'src/mobile_scanner_controller.dart';
export 'src/mobile_scanner_exception.dart';
export 'src/objects/address.dart';
export 'src/objects/barcode.dart';
export 'src/objects/barcode_capture.dart';
export 'src/objects/calendar_event.dart';
... ...
import 'package:mobile_scanner/src/enums/address_type.dart';
/// An address.
class Address {
/// Creates a new [Address] instance.
const Address({
this.addressLines = const <String>[],
this.type = AddressType.unknown,
});
/// Creates a new [Address] instance from a map.
factory Address.fromNative(Map<Object?, Object?> data) {
final List<Object?>? addressLines = data['addressLines'] as List<Object?>?;
final AddressType type = AddressType.fromRawValue(
data['type'] as int? ?? 0,
);
if (addressLines == null) {
return Address(type: type);
}
return Address(
addressLines: List.unmodifiable(addressLines.cast<String>()),
type: type,
);
}
/// The address lines that represent this address.
final List<String> addressLines;
/// Gets type of the address.
final AddressType type;
}
... ...
... ... @@ -2,7 +2,6 @@ import 'dart:typed_data';
import 'dart:ui';
import 'package:mobile_scanner/src/barcode_utility.dart';
import 'package:mobile_scanner/src/enums/address_type.dart';
import 'package:mobile_scanner/src/enums/barcode_format.dart';
import 'package:mobile_scanner/src/enums/barcode_type.dart';
import 'package:mobile_scanner/src/enums/phone_type.dart';
... ... @@ -123,24 +122,6 @@ class Barcode {
wifi = toWiFi(data['wifi'] as Map?);
}
/// An address.
class Address {
/// Gets formatted address, multiple lines when appropriate. This field always contains at least one line.
final List<String> addressLines;
/// Gets type of the address.
///
/// Returns null if not available.
final AddressType? type;
/// Create a [Address] from native data.
Address.fromNative(Map data)
: addressLines = List.unmodifiable(
(data['addressLines'] as List? ?? []).cast<String>(),
),
type = AddressType.values[data['type'] as int];
}
/// Phone number info.
class Phone {
/// Gets phone number.
... ...
import 'package:mobile_scanner/src/objects/address.dart';
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/objects/email.dart';
import 'package:mobile_scanner/src/objects/person_name.dart';
... ...