QueueMgr/lib/backend/DataManager.dart
2023-08-08 08:28:09 +05:30

56 lines
1.4 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:queue_mgr/backend/DebugHelper.dart';
// DateFormat dateFormat;
final String API_ENDPOINT= "https://vps.playpoolstudios.com/qms/api/";
class DataManager{
static _DataManager? m_instance = null;
static _DataManager instance(){
m_instance ??= _DataManager();
return m_instance!;
}
}
class _DataManager{
_DataManager();
List<dynamic> services = [];
Future<void> GetData() async{
try{
var response = (await http.post(
Uri.parse('${API_ENDPOINT}get_services.php'),
body: <String, String>{}));
Debug.LogResponse(response.body.toString());
services = jsonDecode(response.body.toString());
Debug.LogResponse(services);
}catch(e){
Debug.LogError(e);
}
}
Future<void> AddService(String name, DateTime sTime, DateTime eTime,TimeOfDay duration) async {
try{
var response = (await http.post(
Uri.parse('${API_ENDPOINT}add_service.php'),
body: <String, String>{
'name':name,
'stime':sTime.toString(),
'etime':eTime.toString(),
'duration':"${duration.hour}:${duration.minute}"
}));
Debug.LogResponse(response.body.toString());
services = jsonDecode(response.body.toString());
Debug.LogResponse(services);
}catch(e){
Debug.LogError(e);
}
}
}