Skip to content

Commit

Permalink
fix:Rewind time unable to update due to rewind to current day
Browse files Browse the repository at this point in the history
  • Loading branch information
angrezichatterbox committed May 16, 2024
1 parent 7b88724 commit e6d41e5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyApp extends StatelessWidget {
useMaterial3: true,
),
navigatorObservers: [ObserverUtils.routeObserver],
initialRoute: initialRoute,
initialRoute: '/',
routes: {
'/': (context) => const LoginPage(),
'/mainPage': (context) => const Navigation()
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/signin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class _LoginPageState extends State<LoginPage> {
"username": UserNameController.text,
"password": PasswordController.text,
}));

print(response.body);
print(response.statusCode);
if (response.statusCode == 202) {
String token = jsonDecode(response.body)["token"];

Expand Down
3 changes: 2 additions & 1 deletion lib/pages/signup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class _SignupPageState extends State<SignupPage> {
"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")));
Expand Down
33 changes: 27 additions & 6 deletions lib/pages/subject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<IconData> subjectIcons = [
Expand Down Expand Up @@ -56,7 +57,8 @@ class TimeTableState extends State<TimeTable> with RouteAware {
}

Future<dynamic> 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(
Expand All @@ -80,7 +82,8 @@ class TimeTableState extends State<TimeTable> 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'),
Expand All @@ -106,7 +109,7 @@ class TimeTableState extends State<TimeTable> with RouteAware {
}
}

Future<dynamic> updateStatus(String url, String status) async {
Future<dynamic> updateStatus(String url, String status,{DateTime? date}) async {
final response = await http.patch(
Uri.parse(url),
body: jsonEncode({"status": status}),
Expand All @@ -116,7 +119,13 @@ class TimeTableState extends State<TimeTable> 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;
Expand All @@ -129,6 +138,7 @@ class TimeTableState extends State<TimeTable> with RouteAware {

late Color c1;
void addHoliday() async {
isHoliday = true ;
final response = await http.post(
Uri.parse("$apiUrl/schedule_selector"),
headers: {
Expand All @@ -144,6 +154,7 @@ class TimeTableState extends State<TimeTable> with RouteAware {
);
if (response.statusCode == 201) {
getStatus(date: selectedDate);
print("I am inside addHoliday");
//_selectDate(context)

ScaffoldMessenger.of(context).showSnackBar(
Expand Down Expand Up @@ -269,17 +280,28 @@ class TimeTableState extends State<TimeTable> 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(
Expand Down Expand Up @@ -366,7 +388,6 @@ class TimeTableState extends State<TimeTable> with RouteAware {
onSelected: (days) {
_day = days!;
addHoliday();
getStatus();
},
),

Expand Down

0 comments on commit e6d41e5

Please sign in to comment.