Clients
This commit is contained in:
parent
b12e36ee6f
commit
6aaab942b9
|
|
@ -1,9 +1,11 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:invoiceninja/utils/formatting.dart';
|
||||
import 'package:invoiceninja/utils/localization.dart';
|
||||
import 'package:invoiceninja/utils/platforms.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ClientDetails extends StatefulWidget {
|
||||
|
|
@ -16,10 +18,9 @@ class ClientDetails extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ClientDetailsState extends State<ClientDetails> {
|
||||
|
||||
Future<Null> _launched;
|
||||
|
||||
Future<Null> _launchInBrowser(String url) async {
|
||||
Future<Null> _launchURL(String url) async {
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url, forceSafariVC: false, forceWebView: false);
|
||||
} else {
|
||||
|
|
@ -43,6 +44,9 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
_buildDetailsList() {
|
||||
var listTiles = <Widget>[];
|
||||
|
||||
listTiles
|
||||
.add(FutureBuilder<Null>(future: _launched, builder: _launchStatus));
|
||||
|
||||
var contacts = client.contacts;
|
||||
contacts.forEach((contact) {
|
||||
if (contact.email.isNotEmpty) {
|
||||
|
|
@ -50,6 +54,9 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
icon: Icons.email,
|
||||
title: contact.fullName() + '\n' + contact.email,
|
||||
subtitle: localization.email,
|
||||
onTap: () => setState(() {
|
||||
_launched = _launchURL('mailto:' + contact.email);
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +65,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
icon: Icons.phone,
|
||||
title: contact.fullName() + '\n' + contact.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,
|
||||
subtitle: localization.website,
|
||||
onTap: () => setState(() {
|
||||
_launched = _launchInBrowser(client.website);
|
||||
_launched = _launchURL(formatURL(client.website));
|
||||
}),
|
||||
));
|
||||
|
||||
listTiles.add(FutureBuilder<Null>(future: _launched, builder: _launchStatus));
|
||||
}
|
||||
|
||||
if (client.workPhone.isNotEmpty) {
|
||||
|
|
@ -80,6 +90,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
icon: Icons.phone,
|
||||
title: client.workPhone,
|
||||
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,
|
||||
title: client.vatNumber,
|
||||
subtitle: localization.vatNumber,
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: client.vatNumber));
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(content: Text(localization.copiedToClipboard)));
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -98,18 +118,27 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
icon: Icons.business,
|
||||
title: client.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 shippingAddress = formatAddress(client, true);
|
||||
var billingAddress = formatAddress(object: client);
|
||||
var shippingAddress = formatAddress(object: client, isShipping: true);
|
||||
|
||||
if (billingAddress.isNotEmpty) {
|
||||
listTiles.add(AppListTile(
|
||||
icon: Icons.pin_drop,
|
||||
title: billingAddress,
|
||||
subtitle: localization.billingAddress,
|
||||
));
|
||||
onTap: () {
|
||||
_launched = _launchURL(getMapURL(context) +
|
||||
Uri.encodeFull(
|
||||
formatAddress(object: client, delimiter: ',')));
|
||||
}));
|
||||
}
|
||||
|
||||
if (shippingAddress.isNotEmpty) {
|
||||
|
|
@ -117,7 +146,11 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
icon: Icons.pin_drop,
|
||||
title: shippingAddress,
|
||||
subtitle: localization.shippingAddress,
|
||||
));
|
||||
onTap: () {
|
||||
_launched = _launchURL(getMapURL(context) +
|
||||
Uri.encodeFull(formatAddress(
|
||||
object: client, delimiter: ',', isShipping: true)));
|
||||
}));
|
||||
}
|
||||
|
||||
return listTiles;
|
||||
|
|
@ -132,7 +165,6 @@ class _ClientDetailsState extends State<ClientDetails> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class AppListTile extends StatelessWidget {
|
||||
AppListTile({
|
||||
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 = '';
|
||||
|
||||
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;
|
||||
|
||||
if (address1.isNotEmpty) {
|
||||
str += address1 + '\n';
|
||||
str += address1 + delimiter;
|
||||
}
|
||||
if (address2.isNotEmpty) {
|
||||
str += address2 + '\n';
|
||||
str += address2 + delimiter;
|
||||
}
|
||||
|
||||
if (city.isNotEmpty || state.isNotEmpty || postalCode.isNotEmpty) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class AppLocalization {
|
|||
'vat_number': 'VAT Number',
|
||||
'id_number': 'Id Number',
|
||||
'create': 'Create',
|
||||
'copied_to_clipboard': 'Copied to clipboard',
|
||||
|
||||
'product': 'Product',
|
||||
'products': 'Products',
|
||||
|
|
@ -126,6 +127,7 @@ class AppLocalization {
|
|||
String get vatNumber => _localizedValues[locale.languageCode]['vat_number'];
|
||||
String get idNumber => _localizedValues[locale.languageCode]['id_number'];
|
||||
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 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