Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ app.*.map.json
/android/app/google-services.json
/android/app/profile
/android/app/release
ios/Runner/GoogleService-Info.plist
ios/firebase_app_id_file.json
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (flutterVersionName == null) {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
Expand Down Expand Up @@ -67,5 +68,6 @@ flutter {
}

dependencies {
implementation platform('com.google.firebase:firebase-bom:31.1.1')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/app_navigation_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:classroom/blocs/classroom_bloc.dart';
import 'package:classroom/blocs/navigation_bloc.dart';
import 'package:classroom/blocs/user_bloc.dart';
import 'package:floating_action_bubble/floating_action_bubble.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Expand Down Expand Up @@ -37,6 +38,7 @@ class _AppNavigationControllerState extends State<AppNavigationController>
Size size = MediaQuery.of(context).size;
NavigationBloc nb = Provider.of<NavigationBloc>(context);
ClassroomBloc cb = Provider.of<ClassroomBloc>(context);
UserBloc ub = Provider.of<UserBloc>(context);

final bool showFab = MediaQuery.of(context).viewInsets.bottom == 0.0;
return Scaffold(
Expand Down Expand Up @@ -73,8 +75,8 @@ class _AppNavigationControllerState extends State<AppNavigationController>
fontFamily: "PublicSans",
fontWeight: FontWeight.bold,
),
onPress: () async{
await cb.joinClass(""); //TODO create dialog to fetch classroom ID
onPress: () async {
await cb.joinClass(context, "EnterClassroomID", ub.uid);
_animationController.reverse();
},
),
Expand Down
31 changes: 29 additions & 2 deletions lib/blocs/classroom_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import 'package:classroom/configs/configs.dart';
import 'package:classroom/utils/snackbar.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

class ClassroomBloc extends ChangeNotifier {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;

Future joinClass(String classroomId) async {
bool _isLoading = false;

await _firestore.collection(Config.fscClassroom).doc(classroomId).update({});
bool get isLoading => _isLoading;

//Toggle loading status
void setLoading(bool value) {
_isLoading = value;
notifyListeners();
}

Future joinClass(
BuildContext context, String classroomId, String userId) async {
setLoading(true);
try {
// Add that student to class -
await _firestore.collection(Config.fscClassroom).doc(classroomId).update({
'students': FieldValue.arrayUnion([userId])
});

// Add that class to that user's joined classes
await _firestore.collection(Config.fscUser).doc(userId).update({
'joinedClasses': FieldValue.arrayUnion([classroomId])
});

setLoading(false);
} catch (e) {
setLoading(false);
showSnackBar(context, e.toString());
}
}
}
Loading