Skip to content

Commit

Permalink
Contact Picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Ciber committed Sep 6, 2021
1 parent a145652 commit f36e4c0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
21 changes: 12 additions & 9 deletions lib/app/data/core/platform/contacts.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Future<String> getContactPhoneNumber() async {
// final contact = await FlutterContactPicker.pickPhoneContact();
import 'package:contact_picker/contact_picker.dart';

// return contact.phoneNumber
// .toString()
// .replaceAll('+53', '')
// .replaceAll(' ', '')
// .replaceAll(RegExp('([a-zA-Z])'), '')
// .replaceAll('()', '');
final ContactPicker _contactPicker = ContactPicker();

return '';
Future<String?> getContactPhoneNumber() async {
final contact = await _contactPicker.selectContact();

return contact?.phoneNumber
.toString()
.replaceAll('+53', '')
.replaceAll(' ', '')
.replaceAll(RegExp('([a-zA-Z])'), '')
.replaceAll('()', '')
.replaceAll('-', '');
}
29 changes: 15 additions & 14 deletions lib/ussd_codes/widgets/ussd_code_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ class _UssdCodeFormState extends State<UssdCodeForm> {
labelText: field.name.toUpperCase(),
suffixIcon: IconButton(
onPressed: () async {
var number = await getContactPhoneNumber();
number = number.replaceAll('-', '');

phoneNumberController
..text = number
..addListener(
() {
phoneNumberController.selection =
const TextSelection(
baseOffset: 8,
extentOffset: 8,
);
},
);
final number = await getContactPhoneNumber();

if (number != null) {
phoneNumberController
..text = number
..addListener(
() {
phoneNumberController.selection =
const TextSelection(
baseOffset: 8,
extentOffset: 8,
);
},
);
}
},
icon: const Icon(
Icons.contacts,
Expand Down
9 changes: 9 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
contact_picker:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "9029676b8dd9d54229f592ffb5385bfd5d1fcf62"
url: "https://github.com/correaleyval/contact_picker"
source: git
version: "0.0.1"
convert:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ environment:
dependencies:
beamer: ^0.14.1
bloc: ^7.2.0-dev.1
contact_picker:
git:
url: https://github.com/correaleyval/contact_picker
dio: ^4.0.0
equatable: ^2.0.3
flutter:
Expand Down

0 comments on commit f36e4c0

Please sign in to comment.