Skip to content

Commit

Permalink
fix: logout, warnings and settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
geekymeeky committed Aug 22, 2022
1 parent e70f488 commit e7f8bdd
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 40 deletions.
44 changes: 32 additions & 12 deletions lib/blocs/auth_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down Expand Up @@ -56,11 +56,15 @@ class AuthBloc extends ChangeNotifier {
user = userCredential.user;
} on FirebaseAuthException catch (e) {
if (e.code == 'invalid-credential') {
print("Invalid credential");
if (kDebugMode) {
print("Invalid credential");
}
}
setLoginProgress(false);
} catch (e) {
print("Error: $e");
if (kDebugMode) {
print("Error: $e");
}
}
setLoginProgress(false);

Expand All @@ -78,10 +82,14 @@ class AuthBloc extends ChangeNotifier {
await saveDataToFirestore();
}

print("User logged in");
if (kDebugMode) {
print("User logged in");
}
await saveUserDataToSp();
} else {
print("User not logged in");
if (kDebugMode) {
print("User not logged in");
}
}
return isLoggedIn;
}
Expand Down Expand Up @@ -110,11 +118,15 @@ class AuthBloc extends ChangeNotifier {
user = userCredential.user;
} on FirebaseAuthException catch (e) {
if (e.code == 'invalid-credential') {
print("Invalid credential");
if (kDebugMode) {
print("Invalid credential");
}
}
setLoginProgress(false);
} catch (e) {
print("Error: $e");
if (kDebugMode) {
print("Error: $e");
}
}
setLoginProgress(false);

Expand All @@ -132,15 +144,21 @@ class AuthBloc extends ChangeNotifier {
await saveDataToFirestore();
}

print("User logged in");
if (kDebugMode) {
print("User logged in");
}
await saveUserDataToSp();
} else {
print("User not logged in");
if (kDebugMode) {
print("User not logged in");
}
}

setLoginProgress(false);
} else {
print("Login cancelled");
if (kDebugMode) {
print("Login cancelled");
}
setLoginProgress(false);
}
return isLoggedIn;
Expand Down Expand Up @@ -212,10 +230,12 @@ class AuthBloc extends ChangeNotifier {
_email = "";

// Logout from auth providers
await _googleSignIn.signOut();
_googleSignIn.signOut();
_firebaseAuth.signOut();

print("User logged out");
if (kDebugMode) {
print("User logged out");
}
notifyListeners();
}

Expand Down
19 changes: 8 additions & 11 deletions lib/components/side_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@ class SideDrawer extends StatelessWidget {
style: const TextStyle(color: kTextColor),
),
currentAccountPicture: GestureDetector(
child: authBloc.profilePicUrl != null
? CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
authBloc.profilePicUrl,
),
)
: const Icon(
Icons.person,
size: 40,
),
),
child: CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
authBloc.profilePicUrl == ""
? "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"
: authBloc.profilePicUrl,
),
)),
decoration: const BoxDecoration(
color: kSecondaryColor,
),
Expand Down Expand Up @@ -106,6 +102,7 @@ class SideDrawer extends StatelessWidget {
),
onTap: () {
authBloc.signOut();
Navigator.popUntil(context, (route) => route.isFirst);
Navigator.pushReplacementNamed(context, OnBoardingPage.id);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/breast_cancer_prediction.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:medibuddy/constants/colors.dart';
import 'package:flutter/foundation.dart';
import 'package:toggle_switch/toggle_switch.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:medibuddy/services/prediction_model.dart';

Expand Down Expand Up @@ -738,6 +737,7 @@ class _BreastCancerPredictState extends State<BreastCancerPredict> {
PredictionModel model = PredictionModel();
var res = await model.getBreastPrediction(data);
res = double.parse(res['prediction']) / 100;
// ignore: use_build_context_synchronously
await _showFullModal(context, res);
},
style: TextButton.styleFrom(
Expand Down
7 changes: 4 additions & 3 deletions lib/screens/heart_predict_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class _HeartPredictState extends State<HeartPredict> {
[Color.fromARGB(255, 231, 120, 120)],
[Color.fromARGB(255, 108, 179, 111)]
],
inactiveBgColor: Color.fromARGB(255, 236, 230, 230),
inactiveBgColor: const Color.fromARGB(255, 236, 230, 230),
initialLabelIndex: 1,
totalSwitches: 2,
labels: const ['Yes', 'No'],
Expand Down Expand Up @@ -240,7 +240,7 @@ class _HeartPredictState extends State<HeartPredict> {
[Color.fromARGB(255, 231, 120, 120)],
[Color.fromARGB(255, 108, 179, 111)]
],
inactiveBgColor: Color.fromARGB(255, 236, 230, 230),
inactiveBgColor: const Color.fromARGB(255, 236, 230, 230),
initialLabelIndex: 1,
totalSwitches: 2,
labels: const ['Yes', 'No'],
Expand Down Expand Up @@ -394,7 +394,7 @@ class _HeartPredictState extends State<HeartPredict> {
[Color.fromARGB(255, 231, 120, 120)],
[Color.fromARGB(255, 108, 179, 111)]
],
inactiveBgColor: Color.fromARGB(255, 236, 230, 230),
inactiveBgColor: const Color.fromARGB(255, 236, 230, 230),
initialLabelIndex: 1,
totalSwitches: 2,
labels: const ['Yes', 'No'],
Expand Down Expand Up @@ -440,6 +440,7 @@ class _HeartPredictState extends State<HeartPredict> {
PredictionModel model = PredictionModel();
var res = await model.getHeartPrediction(data);
res = double.parse(res['prediction']) / 100;
// ignore: use_build_context_synchronously
await _showFullModal(context, res);
},
style: TextButton.styleFrom(
Expand Down
1 change: 0 additions & 1 deletion lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:medibuddy/components/bottom_navbar.dart';
import 'package:medibuddy/components/side_drawer.dart';
import 'package:medibuddy/constants/colors.dart';
import 'package:medibuddy/components/image_card.dart';
import 'package:medibuddy/components/notification_card.dart';
import 'package:medibuddy/components/heading.dart';
import 'package:medibuddy/screens/bmi_screen.dart';
import 'package:medibuddy/screens/breast_cancer_prediction.dart';
Expand Down
2 changes: 0 additions & 2 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,7 +17,6 @@ class LoginScreen extends StatefulWidget {
}

class _LoginScreenState extends State<LoginScreen> {
final _auth = FirebaseAuth.instance;
// ignore: unused_field
final GlobalKey<FormState> _key = GlobalKey<FormState>();
String email = "";
Expand Down
10 changes: 7 additions & 3 deletions lib/screens/onboarding_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:medibuddy/blocs/auth_bloc.dart';
import 'package:medibuddy/screens/home_screen.dart';
import 'package:medibuddy/screens/login_screen.dart';
import 'package:provider/provider.dart';

class OnBoardingPage extends StatefulWidget {
static const id = 'onboarding_screen';
Expand Down Expand Up @@ -33,7 +31,13 @@ class _OnBoardingPageState extends State<OnBoardingPage> {
Navigator.pushNamed(context, HomeScreen.id);
}
},
)
).catchError(
(error) {
if (kDebugMode) {
print(error);
}
},
),
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/screens/percentage_indicator_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyProgressIndicator extends StatelessWidget {
percent: result < 0 ? 0 : result / 100,
//percentage of circle
center: Text(
result < 0 ? 'Negative :"(' : result.toStringAsFixed(2) + ' %',
result < 0 ? 'Negative :"(' : '${result.toStringAsFixed(2)} %',
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 28.0),
), //center text, you can set Icon as well
Expand All @@ -45,7 +45,7 @@ class MyProgressIndicator extends StatelessWidget {
fontFamily: 'Nunito'),
),
), //footer text
backgroundColor: Color.fromARGB(
backgroundColor: const Color.fromARGB(
255, 207, 235, 232), //backround of progress bar
circularStrokeCap: CircularStrokeCap.round,
//if result negative then red else green //corner shape of progress bar at start/end
Expand Down
1 change: 1 addition & 0 deletions lib/screens/registration_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
final newUser =
await _auth.createUserWithEmailAndPassword(
email: email.trim(), password: password);
// ignore: unnecessary_null_comparison
if (newUser != null) {
// ignore: use_build_context_synchronously
Navigator.pushNamedAndRemoveUntil(
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:medibuddy/constants/colors.dart';
import 'package:medibuddy/screens/license_screen.dart';

class SettingsScreen extends StatefulWidget {
Expand All @@ -15,7 +16,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
void toggleDarkMode(bool value) {
setState(() {
isDarkModeEnabled = !isDarkModeEnabled;
print(isDarkModeEnabled);
debugPrint(isDarkModeEnabled.toString());
});
}

Expand All @@ -25,7 +26,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
extendBodyBehindAppBar: true,
appBar: AppBar(
title: const Text('Settings'),
backgroundColor: Colors.transparent,
),
body: ListView(
physics: const ClampingScrollPhysics(
Expand All @@ -43,7 +43,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
// height: 1,
// ),
ListTile(
title: Text('Licenses'),
title: const Text('Licenses'),
onTap: () {
Navigator.pushNamed(context, LicenseScreen.id);
},
Expand Down
5 changes: 4 additions & 1 deletion lib/services/networking.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';

Expand All @@ -19,7 +20,9 @@ class NetworkHandler {

return jsonDecode(data);
} else {
print(response.statusCode);
if (kDebugMode) {
print(response.statusCode);
}
}
}
}
6 changes: 5 additions & 1 deletion lib/services/prediction_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:medibuddy/services/networking.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter/material.dart';

// ignore: constant_identifier_names
const API_URI = 'http://20.198.106.110';

class PredictionModel {
Expand All @@ -10,7 +12,9 @@ class PredictionModel {
NetworkHandler(Uri.parse('$API_URI/predict_heart_disease'), body);

var predictionData = await networkHelper.getData();
print(predictionData);
if (kDebugMode) {
print(predictionData);
}
return predictionData;
}

Expand Down

0 comments on commit e7f8bdd

Please sign in to comment.