Navaron Bracke

move ContactInfo to its own file

... ... @@ -3,6 +3,7 @@ Improvements:
* 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.
* The `phones` and `urls` of `ContactInfo` are now non-null.
## 3.5.0
New Features:
... ...
... ... @@ -15,6 +15,7 @@ export 'src/mobile_scanner_exception.dart';
export 'src/objects/barcode.dart';
export 'src/objects/barcode_capture.dart';
export 'src/objects/calendar_event.dart';
export 'src/objects/contact_info.dart';
export 'src/objects/driver_license.dart';
export 'src/objects/email.dart';
export 'src/objects/geo_point.dart';
... ...
... ... @@ -7,6 +7,7 @@ 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';
import 'package:mobile_scanner/src/objects/calendar_event.dart';
import 'package:mobile_scanner/src/objects/contact_info.dart';
import 'package:mobile_scanner/src/objects/driver_license.dart';
import 'package:mobile_scanner/src/objects/email.dart';
import 'package:mobile_scanner/src/objects/geo_point.dart';
... ... @@ -121,62 +122,6 @@ class Barcode {
wifi = toWiFi(data['wifi'] as Map?);
}
/// A person's or organization's business card. For example a VCARD.
class ContactInfo {
/// Gets contact person's addresses.
///
/// Returns an empty list if nothing found.
final List<Address> addresses;
/// Gets contact person's emails.
///
/// Returns an empty list if nothing found.
final List<Email> emails;
/// Gets contact person's name.
///
/// Returns null if not available.
final PersonName? name;
/// Gets contact person's organization.
///
/// Returns null if not available.
final String? organization;
/// Gets contact person's phones.
///
/// Returns an empty list if nothing found.
final List<Phone>? phones;
/// Gets contact person's title.
///
/// Returns null if not available.
final String? title;
/// Gets contact person's urls.
///
/// Returns an empty list if nothing found.
final List<String>? urls;
/// Create a [ContactInfo] from native data.
ContactInfo.fromNative(Map data)
: addresses = List.unmodifiable(
(data['addresses'] as List? ?? [])
.cast<Map>()
.map(Address.fromNative),
),
emails = List.unmodifiable(
(data['emails'] as List? ?? []).cast<Map>().map(Email.fromNative),
),
name = toName(data['name'] as Map?),
organization = data['organization'] as String?,
phones = List.unmodifiable(
(data['phones'] as List? ?? []).cast<Map>().map(Phone.fromNative),
),
title = data['title'] as String?,
urls = List.unmodifiable((data['urls'] as List? ?? []).cast<String>());
}
/// An address.
class Address {
/// Gets formatted address, multiple lines when appropriate. This field always contains at least one line.
... ...
import 'package:mobile_scanner/src/objects/barcode.dart';
import 'package:mobile_scanner/src/objects/email.dart';
/// A person's or organization's business card.
/// For example a VCARD.
class ContactInfo {
/// Create a new [ContactInfo] instance.
const ContactInfo({
this.addresses = const <Address>[],
this.emails = const <Email>[],
this.name,
this.organization,
this.phones = const <Phone>[],
this.title,
this.urls = const <String>[],
});
/// Create a new [ContactInfo] instance from a map.
factory ContactInfo.fromNative(Map<Object?, Object?> data) {
final List<Object?>? addresses = data['addresses'] as List<Object?>?;
final List<Object?>? emails = data['emails'] as List<Object?>?;
final List<Object?>? phones = data['phones'] as List<Object?>?;
final List<Object?>? urls = data['urls'] as List<Object?>?;
final Map<Object?, Object?>? name = data['name'] as Map<Object?, Object?>?;
return ContactInfo(
addresses: addresses == null
? const <Address>[]
: List.unmodifiable(
addresses.cast<Map<Object?, Object?>>().map(Address.fromNative),
),
emails: emails == null
? const <Email>[]
: List.unmodifiable(
emails.cast<Map<Object?, Object?>>().map(Email.fromNative),
),
name: name == null ? null : PersonName.fromNative(name),
organization: data['organization'] as String?,
phones: phones == null
? const <Phone>[]
: List.unmodifiable(
phones.cast<Map<Object?, Object?>>().map(Phone.fromNative),
),
title: data['title'] as String?,
urls: urls == null
? const <String>[]
: List.unmodifiable(urls.cast<String>()),
);
}
/// The list of addresses for the person or organisation.
final List<Address> addresses;
/// The list of email addresses for the person or organisation.
final List<Email> emails;
/// The name of the contact person.
final PersonName? name;
/// The name of the organization.
final String? organization;
/// The available phone numbers for the contact person or organisation.
final List<Phone> phones;
/// The contact person's title.
final String? title;
/// The urls associated with the contact person or organisation.
final List<String> urls;
}
... ...