Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import 'package:flutter_contact/contacts.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';
class ReadContacts extends StatefulWidget {
@override
_ReadContactsState createState() => _ReadContactsState();
}
class _ReadContactsState extends State<ReadContacts> {
List<Contact> listContacts;
@override
void initState() {
// TODO: implement initState
super.initState();
listContacts = new List();
readContacts();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
appBar: AppBar(
title: Text("Get Phone Contact List"),
backgroundColor: Colors.green,
),
body: Container(
child: (listContacts.length > 0)
? ListView.builder(
itemCount: listContacts.length,
itemBuilder: (context, index) {
Contact contact = listContacts.get(index);
return Card(
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.green,
child: Center(
child: (contact.avatar != null)
? Image.memory(
contact.avatar,
height: 28,
width: 28,
)
: Icon(Icons.face),
),
),
title: Text("${contact.displayName}"),
subtitle: Text((contact.phones.length > 0)
? "${contact.phones.get(0)}"
: "No contact"),
trailing: InkWell(
child: Icon(
Icons.call,
color: Colors.green,
),
onTap: () {
_makePhoneCall(
"tel:${contact.phones.length.gcd(0)}");
},
)),
);
})
: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(
backgroundColor: Colors.red,
),
Text("reading Contacts...")
],
),
),
),
));
}
Future<void> _makePhoneCall(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
readContacts() async {
final PermissionStatus permissionStatus = await _getPermission();
if (permissionStatus == PermissionStatus.granted) {
Contacts.streamContacts().forEach((contact) {
print("${contact.displayName}");
setState(() {
listContacts.add(contact);
});
});
}
// You can manually adjust the buffer size
//return Contacts.streamContacts(bufferSize: 10);
}
//Check contacts permission
Future<PermissionStatus> _getPermission() async {
final PermissionStatus permission = await Permission.contacts.status;
if (permission != PermissionStatus.granted &&
permission != PermissionStatus.denied) {
final Map<Permission, PermissionStatus> permissionStatus =
await [Permission.contacts].request();
return permissionStatus[Permission.contacts] ??
PermissionStatus.undetermined;
} else {
return permission;
}
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team