Skip to content

Commit

Permalink
Merge pull request #50 from angrezichatterbox/main
Browse files Browse the repository at this point in the history
Bringing in the onboarding page
  • Loading branch information
angrezichatterbox authored Jan 27, 2025
2 parents 51de26b + bd208ef commit f53dc30
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
4 changes: 2 additions & 2 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.android.application" version "8.2.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

include ":app"
Binary file added assets/bunked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cancelled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/present.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
91 changes: 47 additions & 44 deletions ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions lib/controllers/auth/login_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'package:http/http.dart' as http;
import 'dart:io';

class LoginController extends GetxController {
final CourseSummaryController courseSummaryController = Get.put(CourseSummaryController());
final CourseSummaryController courseSummaryController =
Get.put(CourseSummaryController());
final _storage = const FlutterSecureStorage();
var isLogged = false.obs;

Expand All @@ -18,34 +19,37 @@ class LoginController extends GetxController {
Future<String?> getToken() async {
return await _storage.read(key: 'token');
}
Future<bool> logoutfunction() async {
var headers = { HttpHeaders.authorizationHeader: "Token ${await getToken()}"};
try {
var url = Uri.parse(
ApiEndPoints.baseUrl + ApiEndPoints.authEndPoints.logoutEmail);
http.Response response =
await http.post(url, headers: headers);
if (response.statusCode == 200) {
await _storage.delete(key: 'token');
isLogged.value = false;

} else {
throw jsonDecode(response.body);
}
} catch (error) {
Get.back();
showDialog(
context: Get.context!,
builder: (context) {
return SimpleDialog(
title: const Text('Error'),
contentPadding: const EdgeInsets.all(20),
children: [Text(error.toString())],
);
});
Future<bool> logoutfunction() async {
var headers = {
HttpHeaders.authorizationHeader: "Token ${await getToken()}"
};
try {
var url = Uri.parse(
ApiEndPoints.baseUrl + ApiEndPoints.authEndPoints.logoutEmail);
http.Response response = await http.post(url, headers: headers);
if (response.statusCode == 200) {
await _storage.delete(key: 'token');
await _storage.delete(key: 'onboarding');
isLogged.value = false;
} else {
throw jsonDecode(response.body);
}
return isLogged.value;
} catch (error) {
Get.back();
showDialog(
context: Get.context!,
builder: (context) {
return SimpleDialog(
title: const Text('Error'),
contentPadding: const EdgeInsets.all(20),
children: [Text(error.toString())],
);
});
}
return isLogged.value;
}

Future<bool> loginFunction() async {
var headers = {"Content-Type": "application/json"};
try {
Expand Down Expand Up @@ -80,6 +84,6 @@ Future<bool> logoutfunction() async {
);
});
}
return isLogged.value ;
return isLogged.value;
}
}
}
2 changes: 1 addition & 1 deletion lib/controllers/auth/signup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SignupController extends GetxController {
if (response.statusCode == 201) {
usernameController.clear();
passwordController.clear();
Get.off(const AuthScreen());
Get.off(const LoginScreen());
}
else {
throw jsonDecode(response.body) ?? 'Unknown Error occured' ;
Expand Down
2 changes: 2 additions & 0 deletions lib/controllers/navigation/navigation_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:bunk_mate/screens/Status/status_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class NavigationController extends GetxController {
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/onBoard/on_board_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OnBoardController extends GetxController {
);
_service.submitTimetable(timetable).then((_) {
Get.snackbar("Success", "TimeTable has been created");
Get.off(const Navigation());
Get.off( Navigation());
}).catchError((error) {
Get.snackbar("Error", "Could not create timetableld");
});
Expand Down
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
const storage = FlutterSecureStorage();
WidgetsFlutterBinding.ensureInitialized();
WidgetsFlutterBinding.ensureInitialized();
return FutureBuilder(
future: storage.read(key: 'token'),
builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
Expand All @@ -37,7 +37,7 @@ class MyApp extends StatelessWidget {
ColorScheme.fromSeed(seedColor: Colors.greenAccent),
useMaterial3: true,
),
home: const Navigation(),
home: Navigation(),
);
} else {
return GetMaterialApp(
Expand All @@ -49,7 +49,7 @@ class MyApp extends StatelessWidget {
ColorScheme.fromSeed(seedColor: Colors.greenAccent),
useMaterial3: true,
),
home: const AuthScreen(),
home: const LoginScreen(),
);
}
}
Expand Down
69 changes: 65 additions & 4 deletions lib/screens/Status/status_page.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import 'package:bunk_mate/controllers/status/status_controller.dart';
import 'package:bunk_mate/services/storage_service.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:line_icons/line_icons.dart';
import 'package:intl/intl.dart';
import 'package:onboarding_overlay/onboarding_overlay.dart';

class StatusView extends StatelessWidget {
class StatusView extends StatefulWidget {
final FocusNode focusNode;
StatusView({super.key, required this.focusNode});

@override
State<StatusView> createState() => StatusViewState();
}

class StatusViewState extends State<StatusView> {
final StatusController controller =
Get.put(StatusController(apiUrl: 'https://api.bunkmate.college'));

final Color bgColor = const Color(0xFF121212);

final Color cardColor = const Color(0xFF1E1E1E);

final Color accentColor = const Color(0xFF4CAF50);

final Color textColor = Colors.white;
final Color secondaryTextColor = Colors.white70;

StatusView({super.key});
final Color secondaryTextColor = Colors.white70;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -46,7 +59,15 @@ class StatusView extends StatelessWidget {
),
),
const Spacer(),
_buildRewindTimeButton(context),
Row(
children: [
_buildRewindTimeButton(context),
const SizedBox(
width: 10,
),
_buildHelpButon(context)
],
),
],
),
body: Obx(
Expand All @@ -57,6 +78,41 @@ class StatusView extends StatelessWidget {
);
}

void showPageGuide() async {
bool isOnboardingCompleted = await StorageService().getOnboardingComplete();
final OnboardingState? onboarding = Onboarding.of(context);
if (onboarding != null && !isOnboardingCompleted) {
onboarding.show();
await StorageService().setOnboardingComplete();
} else {
print("Onboarding is null");
}
}

Widget _buildHelpButon(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(right: 20),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: bgColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
onPressed: () {
final OnboardingState? onboarding = Onboarding.of(context);
if (onboarding != null) {
onboarding.show();
} else {
print("Onboarding is null");
}
},
child: const Icon(Icons.help_outline, size: 40, color: Colors.white),
),
);
}

Widget _buildRewindTimeButton(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(right: 20),
Expand All @@ -79,6 +135,11 @@ class StatusView extends StatelessWidget {
padding: const EdgeInsets.all(20.0),
itemCount: controller.courses.length,
itemBuilder: (BuildContext context, int index) {
if (index == 0)
return Focus(
focusNode: widget.focusNode,
child: _buildCourseItem(controller.courses[index]),
);
return _buildCourseItem(controller.courses[index]);
},
);
Expand Down
10 changes: 5 additions & 5 deletions lib/screens/auth/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'package:bunk_mate/controllers/auth/login_controller.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';

class AuthScreen extends StatefulWidget {
const AuthScreen({super.key});
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});

@override
State<AuthScreen> createState() => _AuthScreenState();
State<LoginScreen> createState() => _LoginScreenState();
}

class _AuthScreenState extends State<AuthScreen>
class _LoginScreenState extends State<LoginScreen>
with SingleTickerProviderStateMixin {
LoginController loginController = Get.put(LoginController());
late AnimationController _animationController;
Expand Down Expand Up @@ -185,7 +185,7 @@ class _AuthScreenState extends State<AuthScreen>
onPressed: () async {
bool success = await loginController.loginFunction();
if (success) {
Get.off(const Navigation());
Get.off( Navigation());
}
},
style: ElevatedButton.styleFrom(
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/auth/signup_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class _SignupScreenState extends State<SignupScreen> with SingleTickerProviderSt
),
GestureDetector(
onTap: () {
Get.off(const AuthScreen());
Get.off(const LoginScreen());
},
child: Text(
"Sign in",
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/homepage/homepage_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ class HomePageState extends State<HomePage> {
Future<void> _handleLogout() async {
bool success = await loginController.logoutfunction();
if (!success) {
Get.off(const AuthScreen());
Get.off(const LoginScreen());
Get.snackbar("Logout Successful", "You were logged out successfully");
Get.deleteAll();
} else {
Get.snackbar("Error", "You weren't logged out. Try again.");
Get.to(const Navigation());
Get.to( Navigation());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/screens/on_board_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _OnBoardViewState extends State<OnBoardView> {
_service
.timeTablePresets(value as int)
.then((_) {
Get.off(const Navigation());
Get.off( Navigation());
}).catchError((error) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
Expand Down
13 changes: 13 additions & 0 deletions lib/services/storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ class StorageService {
Future<void> deleteToken() async {
await _storage.delete(key: 'token');
}

Future<void> setOnboardingComplete() async {
await _storage.write(key: 'onboarding', value: 'true');
}

Future<void> deleteOnboarding() async {
await _storage.delete(key: 'onboarding');
}

Future<bool> getOnboardingComplete() async {
final onboarding = await _storage.read(key: 'onboarding');
return onboarding == 'true';
}
}
Loading

0 comments on commit f53dc30

Please sign in to comment.