Skip to content

Instantly share code, notes, and snippets.

@fabiomsr
Last active March 9, 2022 19:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiomsr/f1292dbbdd25e680b072c26d3d455a1a to your computer and use it in GitHub Desktop.
Save fabiomsr/f1292dbbdd25e680b072c26d3d455a1a to your computer and use it in GitHub Desktop.
Flutter Contact list view
import 'package:flutter/material.dart';
import '../../data/contact_data.dart';
import 'contact_presenter.dart';
class ContactsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Contacts"),
),
body: ContactList()
);
}
}
///
/// Contact List
///
class ContactList extends StatefulWidget{
ContactList({ Key key }) : super(key: key);
@override
_ContactListState createState() => _ContactListState();
}
class _ContactListState extends State<ContactList> implements ContactListViewContract {
ContactListPresenter _presenter;
List<Contact> _contacts;
bool _isSearching;
_ContactListState() {
_presenter = ContactListPresenter(this);
}
@override
void initState() {
super.initState();
_isSearching = true;
_presenter.loadContacts();
}
@override
void onLoadContactsComplete(List<Contact> items) {
setState(() {
_contacts = items;
_isSearching = false;
});
}
@override
void onLoadContactsError() {
// TODO: implement onLoadContactsError
}
@override
Widget build(BuildContext context) {
var widget;
if(_isSearching) {
widget = Center(
child: Padding(
padding: EdgeInsets.only(left: 16.0, right: 16.0),
child: CircularProgressIndicator()
)
);
}else {
widget = ListView(
padding: EdgeInsets.symmetric(vertical: 8.0),
children: _buildContactList()
);
}
return widget;
}
List<_ContactListItem> _buildContactList() {
return _contacts.map((contact) => _ContactListItem(contact))
.toList();
}
}
///
/// Contact List Item
///
class _ContactListItem extends ListTile {
_ContactListItem(Contact contact) :
super(
title : Text(contact.fullName),
subtitle: Text(contact.email),
leading: CircleAvatar(
child: Text(contact.fullName[0])
)
);
}
@AmandaDEn32
Copy link

is there a way to access groups names also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment