raw_contacts 0.0.4 raw_contacts: ^0.0.4 copied to clipboard
Manage Contact lists in flutter
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:raw_contacts/raw_contacts.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Iterable<Contact> _contacts;
String _accountType = "com.hub_games.langless";
GlobalKey<ScaffoldState> _key = new GlobalKey<ScaffoldState>();
@override
void initState() {
initPlatformState();
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
var response = await RawContacts.getContacts(filter: _accountType);
setState(() {
_contacts = response;
});
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
key: _key,
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: ListView(
children: _contacts != null
? _contacts
.map(
(test) => ListTile(
onTap: () {
test.displayName = "Super Test";
test.avatar = null;
RawContacts.updateContact(
accountType: _accountType, newContact: test);
},
leading: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
image: DecorationImage(
image: test.avatar != null
? MemoryImage(test.avatar)
: NetworkImage(
"https://via.placeholder.com/200?text=" +
test.displayName
.substring(0, 2)
.toUpperCase()),
),
),
),
title: Text(test.displayName),
subtitle: Text(test.emails.elementAt(0).value),
),
)
.toList()
: <Widget>[Container()],
),
));
}
}