Skip to content

Commit

Permalink
Merge pull request avinashkranjan#119 from nicks101/issue-103
Browse files Browse the repository at this point in the history
Issue 103
  • Loading branch information
avinashkranjan authored Mar 28, 2021
2 parents 2ab88f4 + ebe26f9 commit d611a67
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 110 deletions.
59 changes: 11 additions & 48 deletions lib/models/classes.dart
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:uuid/uuid.dart';

class Classes {
final String subject;
final String type;
final String teacherName;
final String joinLink;
final DateTime time;
bool isPassed = false;
bool isHappening = false;

Classes({this.subject, this.type, this.teacherName, this.time});
Classes({
this.subject,
this.type,
this.teacherName,
this.joinLink,
this.time,
});

factory Classes.fromMap(Map<String, dynamic> snapshot) => Classes(
subject: snapshot['subject'],
type: snapshot['type'],
teacherName: snapshot['teacherName'],
joinLink: snapshot['joinLink'],
time: (snapshot['time'] != null)
? DateTime.parse(snapshot['time'].toDate().toString())
: null,
: DateTime.now(),
);

toMap() => {
'subject': subject,
'type': type,
'teacherName': teacherName,
'joinLink': joinLink,
'time': time,
};
}

Future<List<Classes>> getClassList(String collegeID) async {
List<Classes> classesList = [];
return FirebaseFirestore.instance
.collection('colleges')
.doc(collegeID)
.get()
.then((documentSnapshot) {
if (documentSnapshot.exists) {
final classesMap = documentSnapshot.data()['classes'] as Map;

classesMap.forEach((key, value) {
classesList.add(Classes.fromMap(value));
});
}
return classesList;
});
}

List<Classes> classes = [
Classes(
subject: "Math",
Expand All @@ -72,28 +60,3 @@ List<Classes> classes = [
time: DateTime.parse("2020-06-06 07:30:00"),
),
];

Map<String, Classes> generateDummyClasses() {
final uuid = Uuid();

Map<String, Classes> data = {};

classes.forEach((element) {
data[uuid.v4()] = element;
});

return data;
}

Future<void> addDummyClassesToFirestore() async {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final DocumentReference documentReference =
_firestore.collection('colleges').doc('USICT-BTECH-CSE-3');
final Map<String, Classes> classesData = generateDummyClasses();

documentReference.update({
'classes': classesData.map((key, value) {
return MapEntry(key, value.toMap());
})
});
}
51 changes: 51 additions & 0 deletions lib/services/classes_db_services.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:uuid/uuid.dart';

import '../models/classes.dart';

class ClassesDBServices {
Future<List<Classes>> getClassList(String collegeID) async {
List<Classes> classesList = [];
return FirebaseFirestore.instance
.collection('colleges')
.doc(collegeID)
.get()
.then((documentSnapshot) {
if (documentSnapshot.exists) {
final classesMap = documentSnapshot.data()['classes'] as Map;

classesMap.forEach((key, value) {
classesList.add(Classes.fromMap(value));
});
}
return classesList;
});
}

Map<String, Classes> generateDummyClasses() {
final uuid = Uuid();

Map<String, Classes> data = {};

classes.forEach((element) {
data[uuid.v4()] = element;
});

return data;
}

Future<void> addDummyClassesToFirestore() async {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
final DocumentReference documentReference =
_firestore.collection('colleges').doc('USICT-BTECH-CSE-3');
final Map<String, Classes> classesData = generateDummyClasses();

documentReference.update({
'classes': classesData.map((key, value) {
return MapEntry(key, value.toMap());
})
});
}
}

ClassesDBServices classesDBServices = ClassesDBServices();
134 changes: 73 additions & 61 deletions lib/widgets/build_classes.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:class_manager/services/user_info_services.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:intl/intl.dart';
import 'package:class_manager/constants.dart';
import 'package:class_manager/models/classes.dart';

import '../services/classes_db_services.dart';

class BuildClasses extends StatelessWidget {
final DateFormat dateFormat = DateFormat("hh:mm a");

Expand All @@ -15,7 +18,7 @@ class BuildClasses extends StatelessWidget {
listen: false,
).user.collegeID;

final classes = getClassList(collegeID);
final classes = classesDBServices.getClassList(collegeID);

return FutureBuilder(
future: classes,
Expand Down Expand Up @@ -47,27 +50,12 @@ class BuildClasses extends StatelessWidget {
children: <Widget>[
Row(
children: <Widget>[
Text(
"${dateFormat.format(c.time)}",
style: TextStyle(
color: c.isPassed
? Colors.white.withOpacity(0.2)
: Colors.white,
fontSize: 18.0,
),
),
_displayClassHeading(
text: "${dateFormat.format(c.time)}", isPassed: c.isPassed),
SizedBox(width: 20.0),
_getTime(c, context),
SizedBox(width: 20.0),
Text(
c.subject,
style: TextStyle(
color: c.isPassed
? Colors.white.withOpacity(0.2)
: Colors.white,
fontSize: 18.0,
),
),
_displayClassHeading(text: c.subject, isPassed: c.isPassed),
SizedBox(width: 20.0),
c.isHappening
? Container(
Expand Down Expand Up @@ -100,51 +88,32 @@ class BuildClasses extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Icon(
Icons.location_on,
color: c.isPassed
? Theme.of(context).accentColor.withOpacity(0.3)
: Theme.of(context).accentColor,
size: 20.0,
),
SizedBox(width: 8.0),
Text(
c.type,
style: TextStyle(
color: c.isPassed
? kTextColor.withOpacity(0.3)
: kTextColor,
fontSize: 15.0,
fontWeight: FontWeight.w600,
),
),
],
_buildClassDetail(
context: context,
icon: Icons.location_on,
text: c.type,
isPassed: c.isPassed,
),
SizedBox(height: 6.0),
Row(
children: <Widget>[
Icon(
Icons.person,
color: c.isPassed
? Theme.of(context).accentColor.withOpacity(0.3)
: Theme.of(context).accentColor,
size: 20.0,
),
SizedBox(width: 8.0),
Text(
c.teacherName,
style: TextStyle(
color: c.isPassed
? kTextColor.withOpacity(0.3)
: kTextColor,
fontSize: 15.0,
fontWeight: FontWeight.w600,
),
),
],
_buildClassDetail(
context: context,
icon: Icons.person,
text: c.teacherName,
isPassed: c.isPassed,
),
SizedBox(height: 6.0),
if (!c.isPassed && c.type == 'Online Class')
InkWell(
onTap: () async {
await _launchURL(c.joinLink);
},
child: _buildClassDetail(
context: context,
icon: Icons.phone_outlined,
text: 'Join Now',
isPassed: c.isPassed,
),
),
],
),
],
Expand All @@ -156,6 +125,19 @@ class BuildClasses extends StatelessWidget {
);
}

Widget _displayClassHeading({
@required String text,
bool isPassed = true,
}) =>
Text(
text,
// "${dateFormat.format(time)}",
style: TextStyle(
color: isPassed ? Colors.white.withOpacity(0.2) : Colors.white,
fontSize: 18.0,
),
);

_getStatus(Classes c) {
DateTime now = DateTime.now();
DateTime finishedTime = c.time.add(Duration(hours: 1));
Expand All @@ -168,6 +150,33 @@ class BuildClasses extends StatelessWidget {
}
}

Widget _buildClassDetail({
@required BuildContext context,
@required IconData icon,
@required String text,
bool isPassed = true,
}) =>
Row(
children: <Widget>[
Icon(
icon,
color: isPassed
? Theme.of(context).accentColor.withOpacity(0.3)
: Theme.of(context).accentColor,
size: 20.0,
),
SizedBox(width: 8.0),
Text(
text,
style: TextStyle(
color: isPassed ? kTextColor.withOpacity(0.3) : kTextColor,
fontSize: 15.0,
fontWeight: FontWeight.w600,
),
),
],
);

_getTime(Classes c, context) {
return Container(
height: 25.0,
Expand Down Expand Up @@ -205,4 +214,7 @@ class BuildClasses extends StatelessWidget {
}
return null;
}

Future<void> _launchURL(String url) async =>
await canLaunch(url) ? await launch(url) : print('Could not launch $url');
}
44 changes: 43 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
version: "4.2.1"
provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -476,6 +476,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
uuid:
dependency: "direct main"
description:
Expand Down
Loading

0 comments on commit d611a67

Please sign in to comment.