Skip to content

Commit

Permalink
Merge pull request #1 from MatteoGalletta/voti-scrutinio
Browse files Browse the repository at this point in the history
Aggiunta Voti Scrutinio
  • Loading branch information
MatteoGalletta authored Aug 29, 2021
2 parents 6162189 + cbe620e commit 9d634ad
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 10 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":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"android":[{"name":"background_fetch","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\background_fetch-0.4.0\\\\","dependencies":[]},{"name":"flutter_local_notifications","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_local_notifications-1.4.0\\\\","dependencies":[]},{"name":"fluttertoast","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"install_plugin","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\install_plugin-2.0.1\\\\","dependencies":[]},{"name":"package_info","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.4.0+16\\\\","dependencies":[]},{"name":"path_provider","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.5\\\\","dependencies":[]},{"name":"quick_actions","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\quick_actions-0.4.0+2\\\\","dependencies":[]},{"name":"url_launcher","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-5.4.2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4\\\\","dependencies":[]},{"name":"url_launcher_macos","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher_macos-0.0.1+2\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"fluttertoast","path":"D:\\\\Flutter SDK\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-4.0.1\\\\","dependencies":[]},{"name":"url_launcher_web","path":"D:\\\\Flutter SDK\\\\.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-08-29 01:18:36.554890","version":"2.2.3"}
43 changes: 43 additions & 0 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,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
6 changes: 6 additions & 0 deletions lib/backdropWidgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ getBackdrop(context) {
Icon(FontAwesomeIcons.fileAlt,
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 Down
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 +137,11 @@ class MyApp extends StatelessWidget {
route = OrarioRoute();
}
break;
case '/scrutinio':
{
route = ScrutinioRoute();
}
break;
case '/info':
{
route = InfoRoute();
Expand Down
78 changes: 78 additions & 0 deletions lib/scrutinio.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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';
import 'database.dart';

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

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

generaLista() {
var tiles = <Widget>[];
voti.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: aggiornaVoti,
child: ListView(
children: new List.from(<Widget>[])..addAll(lista)
)
)
);
}

Future aggiornaVoti() async {
var nuoviVoti = await votiscruitinio();

if (nuoviVoti.isNotEmpty) {
await Database.put('votiscrutinio', nuoviVoti);
}

setState(() {
voti = nuoviVoti;
});
}


void initState() {
super.initState();
WidgetsBinding.instance
.addPostFrameCallback((_) => _refreshIndicatorKey.currentState.show());
}
}
22 changes: 17 additions & 5 deletions lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ widgetNota(nota) {
}

cerchioVoto(voto, {radius = 40.0}) {
voto = double.parse(voto);
var votoAsDouble = double.tryParse(voto) ?? 10; // Per le materie dove il voto non è numerico
return CircularPercentIndicator(
radius: radius,
lineWidth: 5.0,
percent: voto / 10,
center: Text(voto.toString()),
progressColor: coloreVoto(voto.toString()),
percent: votoAsDouble / 10,
center: Text(voto),
progressColor: coloreVoto(votoAsDouble),
);
}

coloreVoto(voto) {
voto = double.parse(voto);
if (voto <= 0) {
return Colors.white;
} else if (voto >= 6) {
Expand Down Expand Up @@ -119,6 +118,19 @@ widgetVoto(voto, context) {
)));
}

widgetScrutinio(voto, context) {
return Padding(
padding: EdgeInsets.only(left: 5, top: 5),
child: ListTile(
leading: cerchioVoto(voto['votoOrale']['codVoto']),
title: Text(voto['desMateria']),
subtitle: ListBody(children: [
Text((voto['assenze'] ?? 0).toString() + " assenze")
])
)
);
}

widgetBacheca(elemento, {var refresh}) {
var subtitle = <Widget>[Text(elemento['messaggio'])];
var buttons = <Widget>[];
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
backdrop:
dependency: "direct main"
description:
Expand Down Expand Up @@ -314,7 +314,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -349,7 +349,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -407,5 +407,5 @@ packages:
source: hosted
version: "2.2.0"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"

0 comments on commit 9d634ad

Please sign in to comment.