Last active
December 12, 2021 16:43
-
-
Save csells/cf880582fae9f6c2a908c1500ffb2b6b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class UserListView extends StatelessWidget { | |
UserListView({Key? key}) : super(key: key); | |
// live Firestore query | |
final usersCollection = FirebaseFirestore.instance.collection('users'); | |
@override | |
Widget build(BuildContext context) => Scaffold( | |
appBar: AppBar(title: const Text('Contacts')), | |
body: FirestoreListView<Map>( | |
query: usersCollection, | |
pageSize: 15, | |
primary: true, | |
padding: const EdgeInsets.all(8), | |
itemBuilder: (context, snapshot) { | |
final user = snapshot.data(); | |
return Column( | |
children: [ | |
Row( | |
children: [ | |
CircleAvatar( | |
child: Text((user['firstName'] ?? 'Unknown')[0]), | |
), | |
const SizedBox(width: 8), | |
Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.center, | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Text( | |
'${user['firstName'] ?? 'unknown'} ' | |
'${user['lastName'] ?? 'unknown'}', | |
style: Theme.of(context).textTheme.subtitle1, | |
), | |
Text( | |
user['number'] ?? 'unknown', | |
style: Theme.of(context).textTheme.caption, | |
), | |
], | |
), | |
], | |
), | |
const Divider(), | |
], | |
); | |
}, | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment