From e6d41e5cfc787818d7fea47817ef47820d531177 Mon Sep 17 00:00:00 2001 From: angrezichatterbox Date: Thu, 16 May 2024 17:56:24 +0530 Subject: [PATCH] fix:Rewind time unable to update due to rewind to current day --- lib/main.dart | 2 +- lib/pages/signin.dart | 3 ++- lib/pages/signup.dart | 3 ++- lib/pages/subject.dart | 33 +++++++++++++++++++++++++++------ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 6325eff..adec7d9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -33,7 +33,7 @@ class MyApp extends StatelessWidget { useMaterial3: true, ), navigatorObservers: [ObserverUtils.routeObserver], - initialRoute: initialRoute, + initialRoute: '/', routes: { '/': (context) => const LoginPage(), '/mainPage': (context) => const Navigation() diff --git a/lib/pages/signin.dart b/lib/pages/signin.dart index 917df1e..d441349 100644 --- a/lib/pages/signin.dart +++ b/lib/pages/signin.dart @@ -29,7 +29,8 @@ class _LoginPageState extends State { "username": UserNameController.text, "password": PasswordController.text, })); - + print(response.body); + print(response.statusCode); if (response.statusCode == 202) { String token = jsonDecode(response.body)["token"]; diff --git a/lib/pages/signup.dart b/lib/pages/signup.dart index 06da6d5..184e466 100644 --- a/lib/pages/signup.dart +++ b/lib/pages/signup.dart @@ -26,7 +26,8 @@ class _SignupPageState extends State { "username": UserNameController.text, "password": PasswordController.text, })); - + print(response.body); + print(response.statusCode); if (response.statusCode == 201) { ScaffoldMessenger.of(context) .showSnackBar(const SnackBar(content: Text("SignUp Succesfull"))); diff --git a/lib/pages/subject.dart b/lib/pages/subject.dart index 462c9d2..c9296b3 100644 --- a/lib/pages/subject.dart +++ b/lib/pages/subject.dart @@ -12,6 +12,7 @@ import 'package:http/http.dart' as http; import 'package:attendence1/utls/imp.dart'; bool coursePresent = false; +bool isHoliday = false; late int _day; late int hello; List subjectIcons = [ @@ -56,7 +57,8 @@ class TimeTableState extends State with RouteAware { } Future getStatus({DateTime? date}) async { - if (date == null) { + + if (date == null && isHoliday == false) { DateTime now = new DateTime.now(); String today = DateFormat('yyyy-MM-dd').format(now); final response = await http.get( @@ -80,7 +82,8 @@ class TimeTableState extends State with RouteAware { } return today; } else { - String today = DateFormat('yyyy-MM-dd').format(date); + print("I am inside the function that should be actually called"); + String today = DateFormat('yyyy-MM-dd').format(date!); print(today); final response = await http.get( Uri.parse(apiUrl + '/datequery?date=$today'), @@ -106,7 +109,7 @@ class TimeTableState extends State with RouteAware { } } - Future updateStatus(String url, String status) async { + Future updateStatus(String url, String status,{DateTime? date}) async { final response = await http.patch( Uri.parse(url), body: jsonEncode({"status": status}), @@ -116,7 +119,13 @@ class TimeTableState extends State with RouteAware { }, ); if (response.statusCode == 200) { - getStatus(); + if (date == null) { + getStatus(); + } + else { + getStatus(date: date); + } + // Signal the stati //stics page to update on navigation statsUpdate = true; @@ -129,6 +138,7 @@ class TimeTableState extends State with RouteAware { late Color c1; void addHoliday() async { + isHoliday = true ; final response = await http.post( Uri.parse("$apiUrl/schedule_selector"), headers: { @@ -144,6 +154,7 @@ class TimeTableState extends State with RouteAware { ); if (response.statusCode == 201) { getStatus(date: selectedDate); + print("I am inside addHoliday"); //_selectDate(context) ScaffoldMessenger.of(context).showSnackBar( @@ -269,17 +280,28 @@ class TimeTableState extends State with RouteAware { ], GestureDetector( onTap: () { + print("Hello i am index"); + courses[index]["status"] = "bunked"; + c1 = Colors.red; + getStatus(date: selectedDate); updateStatus( courses[index]["session_url"], "bunked"); }, onDoubleTap: () { + courses[index]["status"] = "cancelled"; + c1 = Colors.blue.shade700; + getStatus(date: selectedDate); updateStatus( courses[index]["session_url"], "cancelled"); + getStatus(date: selectedDate); }, onLongPress: () { - //courses[index]["status"] = "Present"; + courses[index]["status"] = "Present"; + c1 = Colors.green; + getStatus(date: selectedDate); updateStatus( courses[index]["session_url"], "present"); + getStatus(date: selectedDate); }, child: Padding( padding: const EdgeInsets.only( @@ -366,7 +388,6 @@ class TimeTableState extends State with RouteAware { onSelected: (days) { _day = days!; addHoliday(); - getStatus(); }, ),