-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from andreicmirciu/people
Add People tab
- Loading branch information
Showing
15 changed files
with
342 additions
and
8 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Person { | ||
final String name; | ||
final String email; | ||
final String phone; | ||
final String office; | ||
final String position; | ||
final String photo; | ||
|
||
Person({this.name, this.email, this.phone, this.office, this.position, this.photo}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:acs_upb_mobile/generated/l10n.dart'; | ||
import 'package:acs_upb_mobile/pages/people/model/person.dart'; | ||
import 'package:acs_upb_mobile/widgets/toast.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
extension PersonExtension on Person { | ||
static Person fromSnap(DocumentSnapshot snap) { | ||
return Person( | ||
name: snap.data['name'], | ||
email: snap.data['email'], | ||
phone: snap.data['phone'], | ||
office: snap.data['office'], | ||
position: snap.data['position'], | ||
photo: snap.data['photo'], | ||
); | ||
} | ||
} | ||
|
||
class PersonProvider with ChangeNotifier { | ||
Future<List<Person>> fetchPeople({BuildContext context}) async { | ||
try { | ||
QuerySnapshot qSnapshot = | ||
await Firestore.instance.collection("people").getDocuments(); | ||
return qSnapshot.documents | ||
.map((doc) => PersonExtension.fromSnap(doc)) | ||
.toList(); | ||
} catch (e) { | ||
print(e); | ||
if (context != null) { | ||
AppToast.show(S.of(context).errorSomethingWentWrong); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:acs_upb_mobile/generated/l10n.dart'; | ||
import 'package:acs_upb_mobile/pages/people/model/person.dart'; | ||
import 'package:acs_upb_mobile/pages/people/service/person_provider.dart'; | ||
import 'package:acs_upb_mobile/pages/people/view/person_view.dart'; | ||
import 'package:acs_upb_mobile/widgets/scaffold.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class PeoplePage extends StatefulWidget { | ||
PeoplePage({Key key}) : super(key: key); | ||
|
||
@override | ||
_PeoplePageState createState() => _PeoplePageState(); | ||
} | ||
|
||
class _PeoplePageState extends State<PeoplePage> { | ||
Future<List<Person>> people; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
PersonProvider personProvider = | ||
Provider.of<PersonProvider>(context, listen: false); | ||
people = personProvider.fetchPeople(context: context); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AppScaffold( | ||
title: S.of(context).navigationPeople, | ||
body: Container( | ||
child: FutureBuilder( | ||
future: people, | ||
builder: (_, snapshot) { | ||
if (snapshot.connectionState == ConnectionState.done) { | ||
List<Person> peopleData = snapshot.data; | ||
return ListView.builder( | ||
itemCount: peopleData.length, | ||
itemBuilder: (_, index) { | ||
return ListTile( | ||
leading: CircleAvatar( | ||
backgroundImage: | ||
NetworkImage(peopleData[index].photo), | ||
), | ||
title: Text(peopleData[index].name), | ||
subtitle: Text(peopleData[index].email), | ||
onTap: () => showPersonInfo(peopleData[index]), | ||
); | ||
}); | ||
} else { | ||
return Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
}), | ||
), | ||
); | ||
} | ||
|
||
showPersonInfo(Person person) { | ||
showModalBottomSheet<dynamic>( | ||
isScrollControlled: true, | ||
context: context, | ||
builder: (BuildContext buildContext) { | ||
return PersonView( | ||
person: person, | ||
); | ||
}, | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'package:acs_upb_mobile/pages/people/model/person.dart'; | ||
import 'package:acs_upb_mobile/widgets/icon_text.dart'; | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class PersonView extends StatelessWidget { | ||
final Person person; | ||
|
||
const PersonView({Key key, this.person}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Container( | ||
width: MediaQuery.of(context).size.width, | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).accentColor, | ||
shape: BoxShape.rectangle, | ||
border: Border.all(color: Theme.of(context).accentColor, width: 10), | ||
), | ||
child: Center( | ||
child: | ||
Text(person.name, style: Theme.of(context).textTheme.headline6), | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Card( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.only(left: 8.0, right: 16.0), | ||
child: person.photo != null | ||
? CircleAvatar( | ||
maxRadius: 50, | ||
backgroundImage: | ||
CachedNetworkImageProvider(person.photo), | ||
) | ||
: CircleAvatar( | ||
radius: 50, | ||
child: Icon( | ||
Icons.person, | ||
size: 50, | ||
), | ||
), | ||
), | ||
), | ||
Expanded( | ||
flex: 2, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
IconText( | ||
icon: Icons.email, | ||
text: person.email ?? '-', | ||
style: Theme.of(context).textTheme.bodyText1), | ||
SizedBox(height: 8), | ||
IconText( | ||
icon: Icons.phone, | ||
text: person.phone ?? '-', | ||
style: Theme.of(context).textTheme.bodyText1), | ||
SizedBox(height: 8), | ||
IconText( | ||
icon: Icons.location_on, | ||
text: person.office ?? '-', | ||
style: Theme.of(context).textTheme.bodyText1), | ||
SizedBox(height: 8), | ||
IconText( | ||
icon: Icons.work, | ||
text: person.position ?? '-', | ||
style: Theme.of(context).textTheme.bodyText1), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.