Last active
February 22, 2021 01:20
-
-
Save edwinmacalopu/849894db75d84d4a486e1474cb741ba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:contacts_service/contacts_service.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:permission_handler/permission_handler.dart'; | |
class Addcontact extends StatefulWidget { | |
Addcontact({Key key}) : super(key: key); | |
@override | |
_AddcontactState createState() => _AddcontactState(); | |
} | |
class _AddcontactState extends State<Addcontact> { | |
TextEditingController name = TextEditingController(); | |
TextEditingController number = TextEditingController(); | |
Future<dynamic> addcontact() async { | |
Contact contact = Contact(); | |
contact.phones = [Item(label: "mobile", value: "${number.text}")]; | |
contact.givenName = name.text; | |
await ContactsService.addContact(contact); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
padding: EdgeInsets.all(30), | |
child: Center( | |
child: Column( | |
children: [ | |
TextField( | |
controller: name, | |
keyboardType: TextInputType.text, | |
), | |
SizedBox(height: 20), | |
TextField( | |
controller: number, | |
keyboardType: TextInputType.number, | |
), | |
SizedBox(height: 20), | |
RaisedButton( | |
onPressed: () async { | |
if (await Permission.contacts.request().isGranted) { | |
addcontact(); | |
} | |
}, | |
color: Colors.greenAccent, | |
child: Text('save contact'), | |
) | |
], | |
))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment