-
Notifications
You must be signed in to change notification settings - Fork 1
/
dettagli_lezione.dart
232 lines (206 loc) · 9.01 KB
/
dettagli_lezione.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import 'dart:convert';
import 'package:calendario_lezioni/login.dart';
import 'package:calendario_lezioni/userpage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'costanti.dart';
class DettagliLezione extends StatelessWidget {
const DettagliLezione({super.key});
//final AuthController controller = Get.find();
@override
Widget build(BuildContext context) {
return DettagliLezionePage();
}
}
class DettagliLezionePage extends StatelessWidget {
final ControllerDettagliLezione controller = Get.find();
final ControllerLogin ctrlLogin = Get.find();
final ControllerListaLezioni ctrlLezione = Get.find();
void EffettuaDisdiciLezione(int tipologia) async {
try {
var url = Uri.parse('$SERVER/operazione/${ctrlLezione.idLezione.value}+${ctrlLezione.codLezione.value}/${tipologia.toString()}');
print(url);
var response = await http.get(url, headers: {
"Access-Control-Allow-Origin": "*",
// Required for CORS support to work
"Access-Control-Allow-Credentials": 'false',
// Required for cookies, authorization headers with HTTPS
"Access-Control-Allow-Headers": "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
"Access-Control-Allow-Methods": "*",
'Content-Type': 'application/json',
});
var rispJson = json.decode(response.body);
if (response.statusCode == 200) {
if (rispJson['ok'] == 'true') {
if(rispJson['stato'] == 'effettuata') {
controller.coloreFeedback.value = Colors.yellow.shade700;
controller.messaggioFeedback.value = 'Hai frequentato questa lezione';
}
else if(rispJson['stato'] == 'disdetta') {
controller.coloreFeedback.value = Colors.redAccent;
controller.messaggioFeedback.value = 'Hai disdetto la tua prenotazione';
}
controller.coloreBottoneEffettuato.value = Colors.grey;
controller.coloreBottoneDisdetto.value = Colors.grey ;
controller.bottoneDisabilitato.value = true;
//aggiornamento della lista lezioni prenotate
ctrlLezione.listalezioni.value = <Lezione>[];
UserPage prova = new UserPage(); //istanza della classe userpage
prova.getDataListaLezioni(); //chiama la funzione per inserire lista lezioni con i dati aggiornati
} else {
controller.coloreFeedback.value = Colors.redAccent;
controller.messaggioFeedback.value = 'Errore, riprova più tardi';
}
} else {
controller.coloreFeedback.value = Colors.redAccent;
controller.messaggioFeedback.value = 'Errore...';
}
} catch (e) {
print(e);
}
}
Widget build(BuildContext context) {
controller.coloreFeedback.value = Colors.transparent;
controller.messaggioFeedback.value = '';
if(controller.stato.value == 2 || controller.stato.value == 3){
controller.bottoneDisabilitato.value = true;
controller.coloreBottoneDisdetto.value = Colors.grey;
controller.coloreBottoneEffettuato.value = Colors.grey;
} else {
controller.bottoneDisabilitato.value = false;
controller.coloreBottoneDisdetto.value = Colors.red;
controller.coloreBottoneEffettuato.value = Colors.yellow;
}
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepOrangeAccent,
title: Text('Dettagli Lezione di ${ctrlLogin.nomeUtente.value}: ${controller.materia.value}'),
) ,
body: Center(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 0.0),
child: Text('ID lezione: ${controller.idLezione.value}',),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 0.0),
child: Text('Insegnante: ${controller.insegnante.value}'),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 0.0),
child: Text('Inizio Lezione: ${controller.inizioLezione.value}'),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 0.0),
child: Text('Fine Lezione: ${controller.fineLezione.value}'),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 0.0),
child: Text('Hai prenotato questa lezione il giorno: ${controller.orarioInserimento.value}'),
),
],
),
),
const Padding(
padding: EdgeInsets.fromLTRB(0, 15, 0, 40),
child: Text('Scegli se effettuare o disdire la lezione',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
child: Obx(() => MaterialButton(
onPressed: () {
if(controller.bottoneDisabilitato.value){
controller.coloreFeedback.value = Colors.grey;
controller.messaggioFeedback.value = 'Attenzione, non puoi più modificare lo stato della lezione';
} else {
EffettuaDisdiciLezione(2);
}
},
color: controller.coloreBottoneEffettuato.value,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: Row(
children: const [
Icon(Icons.check_circle,
color: Color(0xFFFFFFFF),
),
Text("EFFETTUA",
style: TextStyle(fontSize: 16, color: Colors.white),
textAlign: TextAlign.center),
],
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
child: Obx(() => MaterialButton(
onPressed: () {
if(controller.bottoneDisabilitato.value){
controller.coloreFeedback.value = Colors.grey;
controller.messaggioFeedback.value = 'Attenzione, non puoi più modificare lo stato della lezione';
} else {
EffettuaDisdiciLezione(3);
}
},
color:controller.coloreBottoneDisdetto.value,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: Row(
children: const [
Icon(Icons.cancel_rounded,
color: Color(0xFFFFFFFF),
),
Text("DISDICI",
style: TextStyle(fontSize: 16, color: Colors.white),
textAlign: TextAlign.center),
],
),
),
),
),
],
),
Obx(() =>
Padding(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color:controller.coloreFeedback.value ,
),
child: Padding(
padding: const EdgeInsets.all(10),
child: Text(
style: TextStyle(fontSize: 16, color: Colors.black),
controller.messaggioFeedback.value,
),
),
),
),
),
const Spacer(),
],
),
),
);
}
}