Appointments system

This commit is contained in:
2023-08-14 17:11:11 +05:30
parent da15e3cda6
commit 50e9dda303
6 changed files with 167 additions and 62 deletions

View File

@@ -24,6 +24,7 @@ class _DataManager{
_DataManager();
List<dynamic> services = [];
List<dynamic> joinedServices=[];
List<Map<String, dynamic>> AvailableServices = [];
List<Map<String, dynamic>> JoinedServices = [];
String Username = "";
@@ -74,34 +75,45 @@ class _DataManager{
Debug.LogError(e);
}
ProcessServices();
await ProcessServices();
}
void ProcessServices(){
Future<void> ProcessServices() async{
try{
var response = (await http.post(
Uri.parse('${API_ENDPOINT}get_joined_services.php'),
body: <String, String>{
'userId':userId.toString()
}));
Debug.LogResponse(response.body.toString());
joinedServices = jsonDecode(response.body.toString());
Debug.LogResponse(services);
}catch(e){
Debug.LogError(e);
}
AvailableServices=[];
JoinedServices=[];
for (var m_service in services) {
Map<String,dynamic> service= jsonDecode(m_service);
Map<String,dynamic> service = jsonDecode(m_service);
if(DateTime.parse(service['end_time']).isBefore(DateTime.now())){
continue;
}
List<String> members = service['members'].toString().split(',');
if(members.contains(userId.toString())){
int tokenId = 0;
for(int i=0;i<members.length; i++){
if(members[i] == userId.toString()){
tokenId = i;
break;
}
bool joined = false;
for (var m_joinedService in joinedServices){
if(service['id'] == jsonDecode(m_joinedService)['service_id']){
//Joined this
JoinedServices.add(jsonDecode(m_joinedService));
joined=true;
break;
}
service.putIfAbsent("tokenId", () => tokenId);
JoinedServices.add(service);
}else{
AvailableServices.add(service);
}
m_service = jsonEncode(service);
if(!joined){
AvailableServices.add(service);
}
}
}
@@ -130,7 +142,7 @@ class _DataManager{
Debug.LogError(e);
}
ProcessServices();
await ProcessServices();
}
}

View File

@@ -15,6 +15,7 @@ class Debug{
static void LogError(Object? msg){
if(!enableLogging){return;}
if(!enableErrorLoggin) {return;}
print(StackTrace.current);
print('\x1B[31m$msg\x1B[0m');
}

View File

@@ -3,6 +3,7 @@
import 'package:duration_picker/duration_picker.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:queue_client/backend/DebugHelper.dart';
// import 'package:flutter_spinkit/flutter_spinkit.dart';
// import 'package:shared_preferences/shared_preferences.dart';
// import 'package:url_launcher/url_launcher.dart';
@@ -41,8 +42,7 @@ class Dialogs{
}
static bool showing = false;
static BuildContext? context;
static waiting(){
static waiting(BuildContext context){
showing=true;
// context=navigatorKey.currentContext;
if(context!=null) {
@@ -68,6 +68,39 @@ class Dialogs{
}
}
static Future<bool> AskQuestion(BuildContext context, String title, String message) async{
bool yes = false;
AlertDialog alert = AlertDialog(
backgroundColor: Color(0xFF1F1F1F),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
title: Text(title,textAlign: TextAlign.center,),
content: Text(message,textAlign: TextAlign.center,),
actions: [
TextButton(onPressed: (){
yes=true;
Navigator.pop(context);
}, child: Text("Yes")),
TextButton(onPressed: (){
Navigator.pop(context);
}, child: Text("No")),
],
);
// show the dialog
await showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
return yes;
}
static showDurationPicker(BuildContext context, String title) {
// set up the button
Widget okButton = TextButton(
@@ -97,11 +130,11 @@ class Dialogs{
},
);
}
// static hide(){
// showing=false;
// Navigator.of(navigatorKey.currentContext!).popUntil((route){
// return route.settings.name!="Progress";
// });
// }
static hide(BuildContext context){
showing=false;
Navigator.of(context).popUntil((route){
return route.settings.name!="Progress";
});
}
}