Clients
This commit is contained in:
parent
b12e36ee6f
commit
6aaab942b9
|
|
@ -1,9 +1,11 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:invoiceninja/data/models/models.dart';
|
import 'package:invoiceninja/data/models/models.dart';
|
||||||
import 'package:invoiceninja/utils/formatting.dart';
|
import 'package:invoiceninja/utils/formatting.dart';
|
||||||
import 'package:invoiceninja/utils/localization.dart';
|
import 'package:invoiceninja/utils/localization.dart';
|
||||||
|
import 'package:invoiceninja/utils/platforms.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class ClientDetails extends StatefulWidget {
|
class ClientDetails extends StatefulWidget {
|
||||||
|
|
@ -16,10 +18,9 @@ class ClientDetails extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ClientDetailsState extends State<ClientDetails> {
|
class _ClientDetailsState extends State<ClientDetails> {
|
||||||
|
|
||||||
Future<Null> _launched;
|
Future<Null> _launched;
|
||||||
|
|
||||||
Future<Null> _launchInBrowser(String url) async {
|
Future<Null> _launchURL(String url) async {
|
||||||
if (await canLaunch(url)) {
|
if (await canLaunch(url)) {
|
||||||
await launch(url, forceSafariVC: false, forceWebView: false);
|
await launch(url, forceSafariVC: false, forceWebView: false);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -43,6 +44,9 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
_buildDetailsList() {
|
_buildDetailsList() {
|
||||||
var listTiles = <Widget>[];
|
var listTiles = <Widget>[];
|
||||||
|
|
||||||
|
listTiles
|
||||||
|
.add(FutureBuilder<Null>(future: _launched, builder: _launchStatus));
|
||||||
|
|
||||||
var contacts = client.contacts;
|
var contacts = client.contacts;
|
||||||
contacts.forEach((contact) {
|
contacts.forEach((contact) {
|
||||||
if (contact.email.isNotEmpty) {
|
if (contact.email.isNotEmpty) {
|
||||||
|
|
@ -50,6 +54,9 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
icon: Icons.email,
|
icon: Icons.email,
|
||||||
title: contact.fullName() + '\n' + contact.email,
|
title: contact.fullName() + '\n' + contact.email,
|
||||||
subtitle: localization.email,
|
subtitle: localization.email,
|
||||||
|
onTap: () => setState(() {
|
||||||
|
_launched = _launchURL('mailto:' + contact.email);
|
||||||
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,6 +65,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
icon: Icons.phone,
|
icon: Icons.phone,
|
||||||
title: contact.fullName() + '\n' + contact.phone,
|
title: contact.fullName() + '\n' + contact.phone,
|
||||||
subtitle: localization.phone,
|
subtitle: localization.phone,
|
||||||
|
onTap: () => setState(() {
|
||||||
|
_launched =
|
||||||
|
_launchURL('sms:' + cleanPhoneNumber(contact.phone));
|
||||||
|
//_launched = _launchURL('tel:' + cleanPhoneNumber(contact.phone));
|
||||||
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -68,11 +80,9 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
title: client.website,
|
title: client.website,
|
||||||
subtitle: localization.website,
|
subtitle: localization.website,
|
||||||
onTap: () => setState(() {
|
onTap: () => setState(() {
|
||||||
_launched = _launchInBrowser(client.website);
|
_launched = _launchURL(formatURL(client.website));
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
listTiles.add(FutureBuilder<Null>(future: _launched, builder: _launchStatus));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.workPhone.isNotEmpty) {
|
if (client.workPhone.isNotEmpty) {
|
||||||
|
|
@ -80,6 +90,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
icon: Icons.phone,
|
icon: Icons.phone,
|
||||||
title: client.workPhone,
|
title: client.workPhone,
|
||||||
subtitle: localization.phone,
|
subtitle: localization.phone,
|
||||||
|
onTap: () => setState(() {
|
||||||
|
_launched =
|
||||||
|
_launchURL('sms:' + cleanPhoneNumber(client.workPhone));
|
||||||
|
//_launched = _launchURL('tel:' + cleanPhoneNumber(client.workPhone));
|
||||||
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,6 +105,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
icon: Icons.location_city,
|
icon: Icons.location_city,
|
||||||
title: client.vatNumber,
|
title: client.vatNumber,
|
||||||
subtitle: localization.vatNumber,
|
subtitle: localization.vatNumber,
|
||||||
|
onTap: () {
|
||||||
|
Clipboard.setData(ClipboardData(text: client.vatNumber));
|
||||||
|
Scaffold.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(localization.copiedToClipboard)));
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,26 +118,39 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
icon: Icons.business,
|
icon: Icons.business,
|
||||||
title: client.idNumber,
|
title: client.idNumber,
|
||||||
subtitle: localization.idNumber,
|
subtitle: localization.idNumber,
|
||||||
|
onTap: () {
|
||||||
|
Clipboard.setData(ClipboardData(text: client.idNumber));
|
||||||
|
Scaffold.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(localization.copiedToClipboard)));
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
var billingAddress = formatAddress(client);
|
var billingAddress = formatAddress(object: client);
|
||||||
var shippingAddress = formatAddress(client, true);
|
var shippingAddress = formatAddress(object: client, isShipping: true);
|
||||||
|
|
||||||
if (billingAddress.isNotEmpty) {
|
if (billingAddress.isNotEmpty) {
|
||||||
listTiles.add(AppListTile(
|
listTiles.add(AppListTile(
|
||||||
icon: Icons.pin_drop,
|
icon: Icons.pin_drop,
|
||||||
title: billingAddress,
|
title: billingAddress,
|
||||||
subtitle: localization.billingAddress,
|
subtitle: localization.billingAddress,
|
||||||
));
|
onTap: () {
|
||||||
|
_launched = _launchURL(getMapURL(context) +
|
||||||
|
Uri.encodeFull(
|
||||||
|
formatAddress(object: client, delimiter: ',')));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shippingAddress.isNotEmpty) {
|
if (shippingAddress.isNotEmpty) {
|
||||||
listTiles.add(AppListTile(
|
listTiles.add(AppListTile(
|
||||||
icon: Icons.pin_drop,
|
icon: Icons.pin_drop,
|
||||||
title: shippingAddress,
|
title: shippingAddress,
|
||||||
subtitle: localization.shippingAddress,
|
subtitle: localization.shippingAddress,
|
||||||
));
|
onTap: () {
|
||||||
|
_launched = _launchURL(getMapURL(context) +
|
||||||
|
Uri.encodeFull(formatAddress(
|
||||||
|
object: client, delimiter: ',', isShipping: true)));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return listTiles;
|
return listTiles;
|
||||||
|
|
@ -132,7 +165,6 @@ class _ClientDetailsState extends State<ClientDetails> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AppListTile extends StatelessWidget {
|
class AppListTile extends StatelessWidget {
|
||||||
AppListTile({
|
AppListTile({
|
||||||
this.icon,
|
this.icon,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,17 @@
|
||||||
String formatAddress(dynamic object, [bool isShipping = false]) {
|
String cleanPhoneNumber(String phoneNumber) {
|
||||||
|
return phoneNumber.replaceAll(RegExp(r'\D'), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
String formatURL(String url) {
|
||||||
|
if (url.startsWith('http')) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'http://' + url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String formatAddress({dynamic object, bool isShipping = false, String delimiter = '\n'}) {
|
||||||
var str = '';
|
var str = '';
|
||||||
|
|
||||||
String address1 = isShipping ? object.shippingAddress1 : object.address1;
|
String address1 = isShipping ? object.shippingAddress1 : object.address1;
|
||||||
|
|
@ -8,10 +21,10 @@ String formatAddress(dynamic object, [bool isShipping = false]) {
|
||||||
String postalCode = isShipping ? object.postalCode : object.postalCode;
|
String postalCode = isShipping ? object.postalCode : object.postalCode;
|
||||||
|
|
||||||
if (address1.isNotEmpty) {
|
if (address1.isNotEmpty) {
|
||||||
str += address1 + '\n';
|
str += address1 + delimiter;
|
||||||
}
|
}
|
||||||
if (address2.isNotEmpty) {
|
if (address2.isNotEmpty) {
|
||||||
str += address2 + '\n';
|
str += address2 + delimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (city.isNotEmpty || state.isNotEmpty || postalCode.isNotEmpty) {
|
if (city.isNotEmpty || state.isNotEmpty || postalCode.isNotEmpty) {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ class AppLocalization {
|
||||||
'vat_number': 'VAT Number',
|
'vat_number': 'VAT Number',
|
||||||
'id_number': 'Id Number',
|
'id_number': 'Id Number',
|
||||||
'create': 'Create',
|
'create': 'Create',
|
||||||
|
'copied_to_clipboard': 'Copied to clipboard',
|
||||||
|
|
||||||
'product': 'Product',
|
'product': 'Product',
|
||||||
'products': 'Products',
|
'products': 'Products',
|
||||||
|
|
@ -126,6 +127,7 @@ class AppLocalization {
|
||||||
String get vatNumber => _localizedValues[locale.languageCode]['vat_number'];
|
String get vatNumber => _localizedValues[locale.languageCode]['vat_number'];
|
||||||
String get idNumber => _localizedValues[locale.languageCode]['id_number'];
|
String get idNumber => _localizedValues[locale.languageCode]['id_number'];
|
||||||
String get create => _localizedValues[locale.languageCode]['create'];
|
String get create => _localizedValues[locale.languageCode]['create'];
|
||||||
|
String get copiedToClipboard => _localizedValues[locale.languageCode]['copied_to_clipboard'];
|
||||||
|
|
||||||
String get product => _localizedValues[locale.languageCode]['product'];
|
String get product => _localizedValues[locale.languageCode]['product'];
|
||||||
String get products => _localizedValues[locale.languageCode]['products'];
|
String get products => _localizedValues[locale.languageCode]['products'];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
String getMapURL(BuildContext context) {
|
||||||
|
bool iOS = Theme.of(context).platform == TargetPlatform.iOS;
|
||||||
|
return iOS ? 'http://maps.apple.com/?address=' : 'https://maps.google.com/?q=';
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue