kinda done
This commit is contained in:
@@ -3,11 +3,13 @@ import 'package:intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:queue_client/backend/DebugHelper.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
// DateFormat dateFormat;
|
||||
|
||||
final String API_ENDPOINT= "https://vps.playpoolstudios.com/qms/api/";
|
||||
|
||||
final dateTimeFormat = DateFormat("yyyy-MM-dd hh:mm");
|
||||
final dateTimeFormat = DateFormat("MM/dd hh:mm a");
|
||||
final timeFormat = DateFormat("hh:mm a");
|
||||
|
||||
class DataManager{
|
||||
static _DataManager? m_instance = null;
|
||||
@@ -24,10 +26,20 @@ class _DataManager{
|
||||
List<dynamic> services = [];
|
||||
List<Map<String, dynamic>> AvailableServices = [];
|
||||
List<Map<String, dynamic>> JoinedServices = [];
|
||||
|
||||
String Username = "";
|
||||
int userId = -1;
|
||||
|
||||
Future<String> AutoLogin() async{
|
||||
final Prefs = await SharedPreferences.getInstance();
|
||||
if(Prefs.containsKey("username") && Prefs.containsKey("password")){
|
||||
return await Login(Prefs.getString("username") ?? "default",Prefs.getString("password") ?? "default");
|
||||
}
|
||||
|
||||
return "-1";
|
||||
}
|
||||
|
||||
Future<String> Login(String username,String password) async{
|
||||
|
||||
String responseTxt = "";
|
||||
try{
|
||||
var response = (await http.post(
|
||||
@@ -39,6 +51,10 @@ class _DataManager{
|
||||
responseTxt = response.body.toString();
|
||||
int result = int.parse(response.body.toString());
|
||||
userId = result;
|
||||
final Prefs = await SharedPreferences.getInstance();
|
||||
Prefs.setString("username", username);
|
||||
Prefs.setString("password",password);
|
||||
Username = username;
|
||||
return "0";
|
||||
}catch(e){
|
||||
Debug.LogError(e);
|
||||
@@ -66,6 +82,9 @@ class _DataManager{
|
||||
JoinedServices=[];
|
||||
for (var m_service in services) {
|
||||
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())){
|
||||
@@ -113,4 +132,85 @@ class _DataManager{
|
||||
|
||||
ProcessServices();
|
||||
}
|
||||
}
|
||||
|
||||
class Helpers{
|
||||
static int isPhoneNumber(String number){
|
||||
if(number.length != 10){
|
||||
return 1;
|
||||
}
|
||||
if(number[0] != "0"){
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(number[1] != "7"){
|
||||
return 3;
|
||||
}
|
||||
if(number[2] == "3" || number[3] == "9"){
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static String DateTimeToRelative(DateTime dt){
|
||||
Duration diff = dt.difference(DateTime.now());
|
||||
if(diff.isNegative){return "Past";}
|
||||
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
final tomorrow = DateTime(now.year, now.month, now.day + 1);
|
||||
final dateToCheck = dt;
|
||||
final aDate = DateTime(dateToCheck.year, dateToCheck.month, dateToCheck.day);
|
||||
if(aDate == today) {
|
||||
return "Today at ${timeFormat.format(dt)}";
|
||||
} else if(aDate == tomorrow) {
|
||||
return "Tomorrow at ${timeFormat.format(dt)}";
|
||||
}
|
||||
|
||||
if(now.month == dt.month){
|
||||
String day = dt.day.toString();
|
||||
if(day == "1" || day=="21" || day=="31"){
|
||||
return "${day}st at ${timeFormat.format(dt)}";
|
||||
}else if(day =="2" || day=="22"){
|
||||
return "${day}nd at ${timeFormat.format(dt)}";
|
||||
}else if(day =="3" || day=="23"){
|
||||
return "${day}rd at ${timeFormat.format(dt)}";
|
||||
}else{
|
||||
return "${day}th at ${timeFormat.format(dt)}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return dateTimeFormat.format(dt);
|
||||
}
|
||||
static Duration ParseDuration(String input){
|
||||
if(input.contains(":")){
|
||||
return Duration(hours: int.parse(input.split(":")[0]), minutes: int.parse(input.split(":")[1]));
|
||||
}
|
||||
|
||||
return Duration(minutes: 0);
|
||||
}
|
||||
}
|
||||
|
||||
extension DurationExtension on Duration{
|
||||
|
||||
|
||||
String toCustomString(){
|
||||
if(this.inMinutes > 60){
|
||||
return "${this.inHours}:${this.inMinutes}";
|
||||
}
|
||||
return "${this.inMinutes} mins";
|
||||
}
|
||||
}
|
||||
|
||||
extension ContextExtension on BuildContext {
|
||||
bool get isTablet => MediaQuery.of(this).size.shortestSide > 600;
|
||||
|
||||
bool get isPhone => MediaQuery.of(this).size.shortestSide < 600;
|
||||
|
||||
bool get isSmall => MediaQuery.of(this).size.shortestSide < 340;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// import 'package:fhub/backend/login_mgr.dart';
|
||||
|
||||
import 'package:duration_picker/duration_picker.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
@@ -66,6 +67,36 @@ class Dialogs{
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static showDurationPicker(BuildContext context, String title) {
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
backgroundColor: Color(0xFF1F1F1F),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
|
||||
title: Text(title,textAlign: TextAlign.center,),
|
||||
// content: DurationPicker(onChange: (Duration value) { return value; },),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
// static hide(){
|
||||
// showing=false;
|
||||
// Navigator.of(navigatorKey.currentContext!).popUntil((route){
|
||||
|
||||
Reference in New Issue
Block a user