Skip to content

Commit

Permalink
Merge pull request #19 from MatteoGalletta/logout
Browse files Browse the repository at this point in the history
- Aggiunto pulsante Logout in Impostazioni
- Aggiunta schermata vari anagrafici
- Aggiunta schermata voti scrutinio
- Fix vari
  • Loading branch information
peppelg authored Sep 9, 2021
2 parents 6162189 + 6771f9d commit da77284
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"background_fetch","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"android":[{"name":"background_fetch","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]},{"name":"url_launcher_macos","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-0.0.1+2\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"url_launcher_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-0.1.0+2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"background_fetch","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"fluttertoast","dependencies":[]},{"name":"install_plugin","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"quick_actions","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2021-03-13 19:21:35.468884","version":"2.0.1"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"background_fetch","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"android":[{"name":"background_fetch","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"restart_app","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\restart_app-1.0.3\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]},{"name":"url_launcher_macos","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-0.0.1+2\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"fluttertoast","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"url_launcher_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_web-0.1.0+2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"background_fetch","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"fluttertoast","dependencies":[]},{"name":"install_plugin","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"quick_actions","dependencies":[]},{"name":"restart_app","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2021-09-09 10:05:29.896674","version":"2.0.1"}
44 changes: 44 additions & 0 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Future login(school, username, password) async {
fullHeaders['x-prg-scheda'],
fullHeaders['x-prg-alunno'],
fullHeaders['x-prg-scuola']);
await Database.put('dati-anagrafici', info[0]['alunno']);
return 'OK';
} else {
return 'Errore sconosciuto.';
Expand Down Expand Up @@ -417,6 +418,49 @@ Future bacheca({var response}) async {
return listaBacheca;
}

Future periodiscrutinio({var response}) async {
if (response == null) {
response = await argoRequest(fullHeaders, 'periodiclasse',
{'page': '1', 'start': '0', 'limit': '25'});
}

if (!(response is List) && response.containsKey('error')) {
Fluttertoast.showToast(msg: 'Errore sconosciuto:\n\n' + response['error']);
return {};
}

return response['dati'];
}

Future votiscruitinio({var response}) async {
if (response == null) {
response = await argoRequest(fullHeaders, 'votiscrutinio',
{'page': '1', 'start': '0', 'limit': '25'});
}
// Si controlla che response non sia una lista, quindi che abbia il metodo .containsKey
// (la richiesta votiscrutinio non ritorna un oggetto con un campo 'dati', bensì una lista)
if (!(response is List) && response.containsKey('error')) {
Fluttertoast.showToast(msg: 'Errore sconosciuto:\n\n' + response['error']);
return {};
}
var periodi = await periodiscrutinio();

Map scrutinio = {};
for (var periodo in periodi)
scrutinio[periodo['prgPeriodo']] = {
'titolo': periodo['desPeriodo'],
'esito': periodo['esito'],
'dati': []
};

for (var elemento in response) {
int periodo = elemento['prgPeriodo'];
scrutinio[periodo]['dati'].add(elemento);
}

return scrutinio;
}

bacheca_parse(elemento) {
return {
'oggetto': elemento['desOggetto'],
Expand Down
18 changes: 16 additions & 2 deletions lib/backdropWidgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ getBackdrop(context) {
widgetMenuBottone(
'I miei voti',
'/voti',
Icon(FontAwesomeIcons.pen, color: Colors.white, size: 18.0),
Icon(FontAwesomeIcons.pen,
color: Colors.white, size: 18.0),
context),
widgetMenuBottone(
'Orario',
Expand Down Expand Up @@ -50,6 +51,18 @@ getBackdrop(context) {
Icon(FontAwesomeIcons.fileAlt,
color: Colors.white, size: 18.0),
context),
widgetMenuBottone(
'Dati anagrafici',
'/datianagrafici',
Icon(FontAwesomeIcons.info,
color: Colors.white, size: 18.0),
context),
widgetMenuBottone(
'Scrutinio',
'/scrutinio',
Icon(FontAwesomeIcons.thumbtack,
color: Colors.white, size: 18.0),
context),
widgetMenuBottone(
'Cosa è successo oggi',
'/oggi',
Expand All @@ -59,7 +72,8 @@ getBackdrop(context) {
widgetMenuBottone(
'Impostazioni',
'/impostazioni',
Icon(FontAwesomeIcons.cog, color: Colors.white, size: 18.0),
Icon(FontAwesomeIcons.cog,
color: Colors.white, size: 18.0),
context)
])));
}
Expand Down
5 changes: 5 additions & 0 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ class Database {
var r = await box.get(key);
return r;
}

static Future resetDatabase() async {
await autoInit();
await box.clear();
}
}
87 changes: 87 additions & 0 deletions lib/datianagrafici.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'package:backdrop/backdrop.dart';
import 'package:flutter/material.dart';

import 'backdropWidgets.dart';
import 'database.dart';

class DatiAnagraficiRoute extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _DatiAnagraficiRouteState();
}
}

class _DatiAnagraficiRouteState extends State<DatiAnagraficiRoute> {
var dati = {};
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
new GlobalKey<RefreshIndicatorState>();

List<TextSpan> createLines(List<Map<String, String>> elements) {

var labelStyle = new TextStyle(color: Theme.of(context).textTheme.bodyText2.color.withOpacity(0.5));
var valueStyle = new TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0, color: Theme.of(context).textTheme.bodyText2.color);

return elements.map((e) => [
new TextSpan(text: e['label'], style: labelStyle),
new TextSpan(text: e['value'] ?? '', style: valueStyle),
new TextSpan(text: '\n')
]).expand((e) => e).toList();
}

@override
Widget build(BuildContext context) {

var text = dati == null
? <TextSpan>[]
: createLines([
{'label': 'Nome: ', 'value': dati['desNome']},
{'label': 'Cognome: ', 'value': dati['desCognome']},
{'label': 'Sesso: ', 'value': dati['flgSesso'] == 'M' ? 'Maschio' : 'Femmina'},
{'label': 'Cittadinanza: ', 'value': dati['desCittadinanza']},
{'label': 'Codice Fiscale: ', 'value': dati['desCf']},
{'label': 'Telefono: ', 'value': dati['desTelefono']},
{'label': 'Cellulare: ', 'value': dati['desCellulare']},
{'label': 'Data di Nascita: ', 'value': dati['datNascita']}, // List.from(dati['datNascita'].split('-').reversed).join('-')
{'label': 'Comune di Nascita: ', 'value': dati['desComuneNascita']},
{'label': 'CAP di Nascita: ', 'value': dati['desCap']},
{'label': 'Comune di Residenza: ', 'value': dati['desComuneResidenza']},
{'label': 'CAP di Residenza: ', 'value': dati['desCapResidenza']},
{'label': 'Comune di Recapito: ', 'value': dati['desComuneRecapito']},
{'label': 'Indirizzo di Recapito: ', 'value': dati['desIndirizzoRecapito']},
// {'label': '??: ', 'value': dati['desVia']}
]);

return BackdropScaffold(
title: Text('Dati Anagrafici'),
backLayer: getBackdrop(context),
frontLayer: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: aggiornaDatiAnagrafici,
child: Container(
margin: const EdgeInsets.only(left: 20.0, right: 20.0, top: 15.0),
child: new RichText(
text: new TextSpan(
style: new TextStyle(
height: 1.6
),
children: text,
),
)
)
)
);
}

Future aggiornaDatiAnagrafici() async {
var nuoviDati = await Database.get('dati-anagrafici');
setState(() {
dati = nuoviDati;
});
}

void initState() {
super.initState();
WidgetsBinding.instance
.addPostFrameCallback((_) => _refreshIndicatorKey.currentState.show());
}
}
32 changes: 32 additions & 0 deletions lib/impostazioni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:background_fetch/background_fetch.dart';
import 'package:backdrop/backdrop.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:restart_app/restart_app.dart';
import 'backdropWidgets.dart';
import 'database.dart';
import 'api.dart';
Expand Down Expand Up @@ -148,6 +149,37 @@ class _ImpostazioniRouteState extends State<ImpostazioniRoute> {
onTap: () {
Navigator.of(context).pushNamed('/info');
})));
widgetsImpostazioni.add(Card(
child: ListTile(
title: Text('Logout'),
leading: Icon(Icons.exit_to_app),
onTap: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Logout'),
content: Text(
'Vuoi resettare tutti i dati dell\'applicazione?'),
actions: <Widget>[
FlatButton(
child: new Text('No'),
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: new Text('Sì'),
onPressed: () async {
await Database.resetDatabase();
Restart.restartApp();
},
),
],
);
},
);
})));
return BackdropScaffold(
title: Text('Impostazioni'),
backLayer: getBackdrop(context),
Expand Down
2 changes: 1 addition & 1 deletion lib/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _LoginRouteState extends State<LoginRoute> {
passwordField.text);
},
child: Text(
"LOGIN",
'LOGIN',
),
))
]));
Expand Down
12 changes: 12 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:background_fetch/background_fetch.dart';
import 'datianagrafici.dart';
import 'redirectRoute.dart';
import 'database.dart';
import 'login.dart';
Expand All @@ -17,6 +18,7 @@ import 'debugApi.dart';
import 'aggiornamento.dart';
import 'impostazioni.dart';
import 'bacheca.dart';
import 'scrutinio.dart';

var darkTheme = false;

Expand Down Expand Up @@ -136,6 +138,16 @@ class MyApp extends StatelessWidget {
route = OrarioRoute();
}
break;
case '/datianagrafici':
{
route = DatiAnagraficiRoute();
}
break;
case '/scrutinio':
{
route = ScrutinioRoute();
}
break;
case '/info':
{
route = InfoRoute();
Expand Down
6 changes: 3 additions & 3 deletions lib/orario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ class _OrarioRouteState extends State<OrarioRoute> {
])),
actions: <Widget>[
FlatButton(
child: Text('Salva'),
child: Text('Chiudi'),
onPressed: () {
Navigator.of(context).pop();
modificaMateria(giorno, ora);
},
),
FlatButton(
child: Text('Chiudi'),
child: Text('Salva'),
onPressed: () {
Navigator.of(context).pop();
modificaMateria(giorno, ora);
},
),
]);
Expand Down
65 changes: 65 additions & 0 deletions lib/scrutinio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:argo_famiglia/widgets.dart';
import 'package:flutter/material.dart';
import 'package:backdrop/backdrop.dart';
import 'dart:async';
import 'backdropWidgets.dart';
import 'api.dart';

class ScrutinioRoute extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ScrutinioRouteState();
}
}

class _ScrutinioRouteState extends State<ScrutinioRoute> {
var scrutinio = {};
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
new GlobalKey<RefreshIndicatorState>();

generaLista() {
var tiles = <Widget>[];
scrutinio.forEach((final idPeriodo, var periodoScrutinio) {
var votiScrutinio = <Widget>[];
print('periodoScrutinio => ' + periodoScrutinio.toString());
for (var voto in periodoScrutinio['dati']) {
votiScrutinio.add(widgetScrutinio(voto, context));
}

tiles.add(ExpansionTile(
title: Text(periodoScrutinio['titolo']),
children: votiScrutinio.isNotEmpty
? votiScrutinio
: [new Text('Nessun voto')]));
});

return tiles;
}

@override
Widget build(BuildContext context) {
var lista = generaLista();

return BackdropScaffold(
title: Text('Voti Scrutinio'),
backLayer: getBackdrop(context),
frontLayer: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: aggiornaScrutinio,
child:
ListView(children: new List.from(<Widget>[])..addAll(lista))));
}

Future aggiornaScrutinio() async {
var nuoviVoti = await votiscruitinio();
setState(() {
scrutinio = nuoviVoti;
});
}

void initState() {
super.initState();
WidgetsBinding.instance
.addPostFrameCallback((_) => _refreshIndicatorKey.currentState.show());
}
}
Loading

0 comments on commit da77284

Please sign in to comment.