Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
404 righe
14 KiB
404 righe
14 KiB
import 'dart:convert'; |
|
|
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:hexcolor/hexcolor.dart'; |
|
import 'package:http/http.dart' as http; |
|
import 'package:idrocap/api/api_service.dart'; |
|
import 'package:idrocap/private/dettaglio_pratica.dart'; |
|
import 'package:idrocap/private/model/pratiche_model.dart'; |
|
import 'package:idrocap/private/notifiche.dart'; |
|
import 'package:idrocap/utility/utility.dart'; |
|
|
|
import 'constant/globals.dart' as globals; |
|
import 'widget/menu.dart'; |
|
|
|
class Pratiche extends StatefulWidget { |
|
const Pratiche({Key? key}) : super(key: key); |
|
|
|
@override |
|
State<Pratiche> createState() => _PraticheState(); |
|
} |
|
|
|
class _PraticheState extends State<Pratiche> { |
|
late Future<List<PraticheModel>> shows; |
|
String searchString = ""; |
|
TextEditingController provincia = TextEditingController(); |
|
TextEditingController cod = TextEditingController(); |
|
TextEditingController codRar = TextEditingController(); |
|
TextEditingController concessionario = TextEditingController(); |
|
List<String> provinceSicilia = ['', 'Agrigento', 'Caltanissetta', 'Catania', 'Enna', 'Messina', 'Palermo', 'Ragusa', 'Siracusa', 'Trapani']; |
|
bool nextPage = false; |
|
bool prevPage = false; |
|
int page = 1; |
|
int pageCount = 0; |
|
bool visibleList = false; |
|
Color coloreNotifica = Colors.white; |
|
|
|
@override |
|
void initState() { |
|
EasyLoading.dismiss(); |
|
super.initState(); |
|
shows = fetchShows(context, "", "", this.page, "", ""); |
|
updateNotificationColor(); |
|
} |
|
|
|
void updateNotificationColor() { |
|
setState(() { |
|
coloreNotifica = globals.userAccess.user.notifications ? Colors.red : Colors.white; |
|
}); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar( |
|
iconTheme: IconThemeData(color: Colors.white), |
|
backgroundColor: HexColor(globals.colorAppbar), |
|
title: Center( |
|
child: Text( |
|
"Pratiche", |
|
style: TextStyle(color: Colors.white), |
|
), |
|
), |
|
actions: [ |
|
IconButton( |
|
onPressed: () { |
|
Navigator.push(context, MaterialPageRoute(builder: (context) => Notifiche())).then((value) { |
|
updateNotificationColor(); |
|
}); |
|
}, |
|
icon: Icon( |
|
Icons.notifications, |
|
color: coloreNotifica, |
|
), |
|
) |
|
], |
|
), |
|
drawer: Menu(), |
|
body: SingleChildScrollView( |
|
child: Column( |
|
children: [ |
|
Padding( |
|
padding: EdgeInsets.all(8), |
|
child: Container( |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
children: [ |
|
TextButton.icon( |
|
onPressed: () { |
|
clearFilters(); |
|
dialogFilter(context); |
|
}, |
|
icon: Icon(Icons.filter_list_rounded), |
|
label: Text("Filtri"), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
Visibility( |
|
visible: !visibleList, |
|
child: Padding( |
|
padding: EdgeInsets.symmetric(horizontal: 20), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
children: [ |
|
Text( |
|
"Pagina $page di $pageCount", |
|
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w600, fontStyle: FontStyle.italic), |
|
), |
|
if (prevPage) |
|
TextButton.icon( |
|
onPressed: () => navigatePage(-1), |
|
icon: Icon(Icons.arrow_back_ios), |
|
label: Text(""), |
|
), |
|
if (nextPage) |
|
TextButton.icon( |
|
onPressed: () => navigatePage(1), |
|
icon: Icon(Icons.arrow_forward_ios_rounded), |
|
label: Text(""), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
Visibility( |
|
visible: !visibleList, |
|
child: FutureBuilder<List<PraticheModel>>( |
|
future: shows, |
|
builder: (context, snapshot) { |
|
if (snapshot.connectionState != ConnectionState.done) { |
|
return Center( |
|
child: Padding( |
|
padding: EdgeInsets.only(top: 80), |
|
child: CircularProgressIndicator(), |
|
), |
|
); |
|
} |
|
|
|
if (snapshot.hasData) { |
|
return ListView.separated( |
|
physics: NeverScrollableScrollPhysics(), |
|
shrinkWrap: true, |
|
itemCount: snapshot.data!.length, |
|
itemBuilder: (context, index) => buildPraticaCard(snapshot.data![index]), |
|
separatorBuilder: (context, index) => Divider(), |
|
); |
|
} else if (snapshot.hasError) { |
|
return Center( |
|
child: Padding( |
|
padding: EdgeInsets.all(20), |
|
child: Text('Nessuna corrispondenza trovata.'), |
|
), |
|
); |
|
} |
|
|
|
return Center( |
|
child: CircularProgressIndicator(), |
|
); |
|
}, |
|
), |
|
), |
|
Visibility( |
|
visible: visibleList, |
|
child: Padding( |
|
padding: EdgeInsets.all(50), |
|
child: Center( |
|
child: ListTile( |
|
leading: Icon(Icons.warning), |
|
title: Text("La ricerca non ha fornito alcun risultato"), |
|
), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
floatingActionButtonLocation: FloatingActionButtonLocation.miniEndFloat, |
|
floatingActionButton: Column( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
children: [ |
|
FloatingActionButton( |
|
onPressed: reloadList, |
|
tooltip: 'Ricarica la lista', |
|
child: Icon(Icons.refresh, color: HexColor(globals.colorAppbar)), |
|
backgroundColor: Colors.white, |
|
), |
|
SizedBox(height: 10), |
|
], |
|
), |
|
); |
|
} |
|
|
|
void clearFilters() { |
|
setState(() { |
|
provincia.text = ""; |
|
cod.text = ""; |
|
codRar.text = ""; |
|
concessionario.text = ""; |
|
}); |
|
} |
|
|
|
void navigatePage(int direction) { |
|
setState(() { |
|
page += direction; |
|
shows = fetchShows(context, provincia.text, cod.text, page, codRar.text, concessionario.text); |
|
}); |
|
} |
|
|
|
void reloadList() { |
|
setState(() { |
|
shows = fetchShows(context, "", "", 1, "", ""); |
|
}); |
|
} |
|
|
|
Widget buildPraticaCard(PraticheModel pratica) { |
|
return GestureDetector( |
|
onTap: () => showPraticaDetail(pratica), |
|
child: Card( |
|
elevation: 10, |
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)), |
|
margin: EdgeInsets.all(20), |
|
child: Column( |
|
children: [ |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.only(topRight: Radius.circular(10), topLeft: Radius.circular(10)), |
|
color: HexColor(globals.coloreCard), |
|
), |
|
padding: EdgeInsets.all(15), |
|
child: Column( |
|
children: [ |
|
Row( |
|
children: [ |
|
Text("ID: ${pratica.id}", style: TextStyle(color: Colors.white)), |
|
], |
|
), |
|
Row( |
|
children: [ |
|
Text("Codice identificativo: ${pratica.authority_identification_code_civil_engineering_office}", |
|
style: TextStyle(color: Colors.white)), |
|
], |
|
) |
|
], |
|
), |
|
), |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), |
|
color: Colors.white, |
|
), |
|
padding: EdgeInsets.all(15), |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text("Stato: ${pratica.water_drawing_paperwork_status.description}"), |
|
Text("Provincia: ${pratica.authority_province}"), |
|
Text("Data di rilascio: ${pratica.release_date.toString()}"), |
|
Text("Scadenza: ${pratica.expiration_date}"), |
|
Text("Creata il: ${pratica.controllable_object.created}"), |
|
Text("Modificata il: ${pratica.controllable_object.modified}"), |
|
Divider(height: 5), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
|
|
void showPraticaDetail(PraticheModel pratica) { |
|
EasyLoading.show(status: "Caricamento in corso..."); |
|
ApiService().getData(pratica.id, "", 0).then((value) { |
|
EasyLoading.dismiss(); |
|
if (value['statusCode'].toString() == "200") { |
|
Navigator.push(context, MaterialPageRoute(builder: (context) => PraticheDettaglio(oggettoRicevuto: value))); |
|
} else { |
|
if (value['statusCode'].toString() == "401") { |
|
Utility().dialogAlert(this.context); |
|
} else { |
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(value["result"]))); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
Future<List<PraticheModel>> fetchShows( |
|
BuildContext context, String provinciaScelta, String codice, int paginazione, String codiceDrar, String conc) async { |
|
String urlRiferimento = globals.url_endpoint + globals.listaPratica + "?page=$paginazione"; |
|
if (codice.isNotEmpty) urlRiferimento += "&cod=${codice.trim()}"; |
|
if (provinciaScelta.isNotEmpty) urlRiferimento += "&province=${provinciaScelta.trim()}"; |
|
if (codiceDrar.isNotEmpty) urlRiferimento += "&cod_drar=${codiceDrar.trim()}"; |
|
if (conc.isNotEmpty) urlRiferimento += "&surname=${conc.trim()}"; |
|
|
|
var response = await http.get(Uri.parse(urlRiferimento), headers: globals.headers); |
|
var data = json.decode(utf8.decode(response.bodyBytes)); |
|
print("###################"); |
|
print(data); |
|
print("###################"); |
|
if (response.statusCode == 200) { |
|
setState(() { |
|
prevPage = data['pagination']['hasPrevPage']; |
|
nextPage = data['pagination']['hasNextPage']; |
|
pageCount = data['pagination']['pageCount']; |
|
visibleList = ((data['waterDrawingPaperworks'] as List).isEmpty || !data.toString().contains("waterDrawingPaperworks")); |
|
}); |
|
var topShowsJson = data['waterDrawingPaperworks'] as List; |
|
return topShowsJson.map((show) => PraticheModel.fromJson(show)).toList(); |
|
} else if (response.statusCode == 401) { |
|
EasyLoading.dismiss(); |
|
Utility().dialogAlert(context); |
|
throw Exception('Unauthorized'); |
|
} else { |
|
throw Exception('Problemi nel caricare i dati: ${data["result"]}'); // Gestisce altri problemi di risposta |
|
} |
|
} |
|
|
|
void dialogFilter(BuildContext context) { |
|
showDialog<void>( |
|
context: context, |
|
builder: (context) { |
|
return StatefulBuilder( |
|
builder: (context, setState) { |
|
return CupertinoAlertDialog( |
|
title: Text(''), |
|
content: Column( |
|
mainAxisSize: MainAxisSize.min, |
|
children: [ |
|
Row( |
|
children: [ |
|
Icon(Icons.filter_alt), |
|
Text("Filtri", style: TextStyle(fontSize: 18)), |
|
], |
|
), |
|
SizedBox(height: 10), |
|
TextField( |
|
decoration: InputDecoration(labelText: "Numero Pratica (GC)"), |
|
keyboardType: TextInputType.text, |
|
controller: cod, |
|
), |
|
TextField( |
|
decoration: InputDecoration(labelText: "Numero Pratica (DRAR)"), |
|
keyboardType: TextInputType.text, |
|
controller: codRar, |
|
), |
|
TextField( |
|
decoration: InputDecoration(labelText: "Cognome Concessionario:"), |
|
keyboardType: TextInputType.text, |
|
controller: concessionario, |
|
), |
|
SizedBox(height: 20), |
|
SizedBox( |
|
width: double.infinity, |
|
child: DropdownButton<String>( |
|
isExpanded: true, |
|
value: provincia.text.isNotEmpty ? provincia.text : null, |
|
hint: Text("Seleziona la provincia"), |
|
icon: Icon(Icons.arrow_downward), |
|
elevation: 16, |
|
underline: Container(height: 1, color: Colors.black), |
|
onChanged: (String? value) { |
|
setState(() { |
|
provincia.text = value!; |
|
}); |
|
}, |
|
items: provinceSicilia.map((String value) { |
|
return DropdownMenuItem<String>( |
|
value: value, |
|
child: Text(value), |
|
); |
|
}).toList(), |
|
), |
|
), |
|
], |
|
), |
|
actions: <Widget>[ |
|
TextButton( |
|
onPressed: () { |
|
clearFilters(); |
|
Navigator.of(context).pop(); |
|
}, |
|
child: const Text('Annulla'), |
|
), |
|
TextButton( |
|
onPressed: () { |
|
setState(() { |
|
page = 1; |
|
shows = fetchShows(context, provincia.text, cod.text, page, codRar.text, concessionario.text); |
|
}); |
|
Navigator.of(context).pop(); |
|
}, |
|
child: const Text('Avvia ricerca'), |
|
), |
|
], |
|
); |
|
}, |
|
); |
|
}, |
|
); |
|
} |
|
}
|
|
|