199 lines
7.6 KiB
Dart
199 lines
7.6 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:queue_mgr/backend/DataManager.dart';
|
|
import 'package:queue_mgr/backend/DebugHelper.dart';
|
|
import 'package:queue_mgr/backend/Dialogs.dart';
|
|
import 'package:queue_mgr/new_service.dart';
|
|
import 'package:queue_mgr/scanning_page.dart';
|
|
|
|
class ServicePage extends StatefulWidget {
|
|
ServicePage({super.key,required this.serviceId});
|
|
String serviceId;
|
|
@override
|
|
State<ServicePage> createState() => _ServicePageState();
|
|
}
|
|
|
|
class _ServicePageState extends State<ServicePage> {
|
|
|
|
Timer timer = Timer(Duration(hours: 1), () { });
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
timer = Timer.periodic(const Duration(seconds: 10), (timer) {
|
|
refresh();
|
|
});
|
|
}
|
|
|
|
void refresh() async{
|
|
await DataManager.instance().GetData();
|
|
setState(() {
|
|
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
timer.cancel();
|
|
Debug.Log("Cancelling timer");
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Map<String, dynamic> service = DataManager.instance().GetServiceById(widget.serviceId.toString());
|
|
// List<String> members = service['members'].toString().split(',');
|
|
// members.removeAt(0);
|
|
List<dynamic> appointments = service['appointments'];
|
|
Debug.Log(appointments);
|
|
return Scaffold(
|
|
appBar: AppBar(title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(service['name']),
|
|
InkWell(
|
|
onTap: (){
|
|
Navigator.of(context).push(MaterialPageRoute(builder:(_)=> NewService(id: widget.serviceId))).then((value) {
|
|
Map<String, dynamic> _service = DataManager.instance().GetServiceById(widget.serviceId.toString());
|
|
if(_service == null || _service.isEmpty){
|
|
Navigator.of(context).pop();
|
|
}
|
|
setState(() {
|
|
|
|
});});
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Icon(Icons.edit),
|
|
),
|
|
)
|
|
],
|
|
),),
|
|
body: SafeArea(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
children: [
|
|
GridView.count(shrinkWrap: true,crossAxisCount: 2,children: [
|
|
Card(child:
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Row(mainAxisAlignment: MainAxisAlignment.center,children: [Icon(Icons.play_arrow),Text(" Starting Time")],),
|
|
Column(
|
|
children: [
|
|
Text(dateFormat.format(DateTime.parse(service['start_time']))),
|
|
Text(timeFormat.format(DateTime.parse(service['start_time'])),style: TextStyle(fontSize: 20)),
|
|
],
|
|
),
|
|
Container(height: 20,)
|
|
],
|
|
),),
|
|
Card(child:
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Row(mainAxisAlignment: MainAxisAlignment.center,children: [Icon(Icons.stop),Text(" Ending Time")],),
|
|
Column(
|
|
children: [
|
|
Text(dateFormat.format(DateTime.parse(service['end_time']))),
|
|
Text(timeFormat.format(DateTime.parse(service['end_time'])),style: TextStyle(fontSize: 20)),
|
|
],
|
|
),
|
|
Container(height: 20,)
|
|
],
|
|
),),
|
|
|
|
],),
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.people_alt_rounded),
|
|
Text(" Queue Length"),
|
|
],
|
|
),
|
|
Text(appointments.length.toString(),style: TextStyle(fontSize: 25),)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 50,
|
|
),
|
|
ElevatedButton(onPressed: () async{
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context)=> ScanningPage(id: widget.serviceId))).then((value){setState(() {
|
|
|
|
});});
|
|
}, child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
children: [
|
|
Icon(Icons.qr_code_scanner),
|
|
SizedBox(height: 10,),
|
|
Text("Scan Mode"),
|
|
],
|
|
),
|
|
)),
|
|
SizedBox(height: 50,),
|
|
(appointments.length >0) ? Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
children: [
|
|
Row(mainAxisAlignment: MainAxisAlignment.center,children: [
|
|
Icon(Icons.emoji_people),
|
|
Text(" Queue")
|
|
],),
|
|
SizedBox(height: 20,),
|
|
GridView.count(
|
|
crossAxisCount: 5,
|
|
mainAxisSpacing: 10,
|
|
crossAxisSpacing: 10,
|
|
shrinkWrap: true,
|
|
children: List.generate(appointments.length, (index){
|
|
Map<String,dynamic> appointment = jsonDecode(appointments[index].toString());
|
|
Debug.Log(appointment);
|
|
|
|
bool past = DateTime.parse(service['start_time']).add(Helpers.ParseDuration(service['duration'])).isBefore(DateTime.now());
|
|
return InkWell(
|
|
onTap: () async{
|
|
bool confirm = await Dialogs.AskQuestion(context, "Complete Token ${appointment['id']}", "Press Yes to remove this token from queue");
|
|
|
|
if(confirm){
|
|
Dialogs.waiting(context);
|
|
await DataManager.instance().CompleteService(service['id'],appointment['user_id']);
|
|
Dialogs.hide(context);
|
|
}
|
|
setState(() {
|
|
|
|
});
|
|
},
|
|
child: Container(decoration: BoxDecoration(borderRadius: BorderRadius.circular(20),color: (past) ? Colors.red.withOpacity(0.2) :Colors.black.withOpacity(0.2)),child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Center(child: Text(appointment['appointment_id'],style: TextStyle(fontSize: 18),)),
|
|
)),
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
) : Container()
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|