Skip to content

Commit

Permalink
Merge pull request #21 from andreicmirciu/people
Browse files Browse the repository at this point in the history
Add People tab
  • Loading branch information
IoanaAlexandru authored Sep 16, 2020
2 parents d83dd62 + e6c697a commit b4550ac
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class MessageLookup extends MessageLookupByLibrary {
"navigationFilter" : MessageLookupByLibrary.simpleMessage("Filter"),
"navigationHome" : MessageLookupByLibrary.simpleMessage("Home"),
"navigationMap" : MessageLookupByLibrary.simpleMessage("Map"),
"navigationPeople" : MessageLookupByLibrary.simpleMessage("People"),
"navigationPortal" : MessageLookupByLibrary.simpleMessage("Portal"),
"navigationProfile" : MessageLookupByLibrary.simpleMessage("Profile"),
"navigationSettings" : MessageLookupByLibrary.simpleMessage("Settings"),
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class MessageLookup extends MessageLookupByLibrary {
"navigationFilter" : MessageLookupByLibrary.simpleMessage("Filtru"),
"navigationHome" : MessageLookupByLibrary.simpleMessage("Acasă"),
"navigationMap" : MessageLookupByLibrary.simpleMessage("Hartă"),
"navigationPeople" : MessageLookupByLibrary.simpleMessage("Persoane"),
"navigationPortal" : MessageLookupByLibrary.simpleMessage("Portal"),
"navigationProfile" : MessageLookupByLibrary.simpleMessage("Profil"),
"navigationSettings" : MessageLookupByLibrary.simpleMessage("Setări"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"navigationPortal": "Portal",
"navigationMap": "Map",
"navigationProfile": "Profile",
"navigationPeople": "People",
"navigationSettings": "Settings",
"navigationFilter": "Filter",
"navigationClasses": "Classes",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_ro.arb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"navigationPortal": "Portal",
"navigationMap": "Hartă",
"navigationProfile": "Profil",
"navigationPeople": "Persoane",
"navigationSettings": "Setări",
"navigationFilter": "Filtru",
"navigationClasses": "Materii",
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:acs_upb_mobile/navigation/routes.dart';
import 'package:acs_upb_mobile/pages/classes/service/class_provider.dart';
import 'package:acs_upb_mobile/pages/filter/service/filter_provider.dart';
import 'package:acs_upb_mobile/pages/filter/view/filter_page.dart';
import 'package:acs_upb_mobile/pages/people/service/person_provider.dart';
import 'package:acs_upb_mobile/pages/portal/service/website_provider.dart';
import 'package:acs_upb_mobile/pages/settings/settings_page.dart';
import 'package:acs_upb_mobile/resources/locale_provider.dart';
Expand All @@ -33,6 +34,7 @@ main() async {
ChangeNotifierProvider<StorageProvider>(create: (_) => StorageProvider()),
ChangeNotifierProvider<WebsiteProvider>(create: (_) => WebsiteProvider()),
ChangeNotifierProvider<ClassProvider>(create: (_) => ClassProvider()),
ChangeNotifierProvider<PersonProvider>(create: (_) => PersonProvider()),
ChangeNotifierProvider<FilterProvider>(
create: (_) => FilterProvider(global: true)),
], child: MyApp()));
Expand Down
9 changes: 8 additions & 1 deletion lib/navigation/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:acs_upb_mobile/generated/l10n.dart';
import 'package:acs_upb_mobile/pages/classes/view/classes_page.dart';
import 'package:acs_upb_mobile/pages/home/home_page.dart';
import 'package:acs_upb_mobile/pages/people/view/people_page.dart';
import 'package:acs_upb_mobile/pages/portal/view/portal_page.dart';
import 'package:acs_upb_mobile/pages/profile/profile_page.dart';
import 'package:flutter/material.dart';
Expand All @@ -23,13 +24,14 @@ class _AppBottomNavigationBarState extends State<AppBottomNavigationBar>
@override
void initState() {
super.initState();
tabController = TabController(vsync: this, length: 4);
tabs = [
HomePage(key: PageStorageKey('Home')),
ClassesPage(key: PageStorageKey('Classes')),
PortalPage(key: PageStorageKey('Portal')),
PeoplePage(key: PageStorageKey('People')),
ProfilePage(key: PageStorageKey('Profile')),
];
tabController = TabController(vsync: this, length: tabs.length);
}

@override
Expand Down Expand Up @@ -68,6 +70,11 @@ class _AppBottomNavigationBarState extends State<AppBottomNavigationBar>
text: S.of(context).navigationPortal,
iconMargin: EdgeInsets.all(0),
),
Tab(
icon: Icon(Icons.people),
text: S.of(context).navigationPeople,
iconMargin: EdgeInsets.all(0),
),
Tab(
icon: Icon(Icons.person),
text: S.of(context).navigationProfile,
Expand Down
10 changes: 10 additions & 0 deletions lib/pages/people/model/person.dart
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});
}
37 changes: 37 additions & 0 deletions lib/pages/people/service/person_provider.dart
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;
}
}
}
72 changes: 72 additions & 0 deletions lib/pages/people/view/people_page.dart
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,
);
},
);
}
}
89 changes: 89 additions & 0 deletions lib/pages/people/view/person_view.dart
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),
],
),
),
],
),
),
),
),
],
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
network_image_mock:
dependency: "direct dev"
description:
name: network_image_mock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
node_interop:
dependency: transitive
description:
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A mobile application for students at ACS UPB.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.5.4+1
version: 0.6.0+1

environment:
sdk: ">=2.6.0 <3.0.0"
Expand Down Expand Up @@ -114,6 +114,9 @@ dev_dependencies:
# Provider platform interfaces of federated flutter plugins, for testing (like url_launcher)
plugin_platform_interface: ^1.0.0

# Testing utils
network_image_mock: ^1.0.1

dependency_overrides:
# Workaround because timetable depends on pedantic 1.9.0 while flutter_test depends on pedantic 1.8.0
pedantic: 1.9.0
Expand Down
Loading

0 comments on commit b4550ac

Please sign in to comment.