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.
272 righe
9.8 KiB
272 righe
9.8 KiB
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter/services.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
|
//import 'package:flutter_map/plugin_api.dart'; |
|
import 'package:idrocap/api/api_service.dart'; |
|
import 'package:idrocap/private/notifiche.dart'; |
|
|
|
import 'package:hexcolor/hexcolor.dart'; |
|
|
|
import '../utility/utility.dart'; |
|
import 'constant/globals.dart' as globals; |
|
import 'widget/menu.dart'; |
|
|
|
class NuovaMisurazione extends StatefulWidget { |
|
final dynamic water_drawing_meters; |
|
final String id; |
|
|
|
NuovaMisurazione({super.key, required this.water_drawing_meters, required this.id}); |
|
|
|
@override |
|
State<NuovaMisurazione> createState() => _ProfileUserState(); |
|
} |
|
|
|
class _ProfileUserState extends State<NuovaMisurazione> { |
|
final _formInput = GlobalKey<FormState>(); |
|
TextEditingController volume = TextEditingController(text: ''); |
|
|
|
dynamic listMisurazioni = []; |
|
@override |
|
void initState() { |
|
EasyLoading.instance..userInteractions = false; |
|
setState(() { |
|
listMisurazioni = widget.water_drawing_meters; |
|
}); |
|
|
|
super.initState(); |
|
} |
|
|
|
@override |
|
void dispose() { |
|
// TODO: implement dispose |
|
|
|
EasyLoading.dismiss(); |
|
listMisurazioni = []; |
|
|
|
super.dispose(); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return PopScope( |
|
canPop: true, |
|
child: Scaffold( |
|
appBar: AppBar( |
|
iconTheme: IconThemeData(color: Colors.white), |
|
backgroundColor: HexColor(globals.colorAppbar), |
|
title: Wrap( |
|
children: [ |
|
Text( |
|
"Nuova Misurazione", |
|
style: TextStyle(color: Colors.white), |
|
), |
|
], |
|
), |
|
leading: InkWell( |
|
onTap: () { |
|
Navigator.pop(context); |
|
}, |
|
child: Icon( |
|
Icons.arrow_back_ios, |
|
color: Colors.white, |
|
), |
|
), |
|
actions: [ |
|
IconButton( |
|
onPressed: () { |
|
Navigator.push(context, MaterialPageRoute(builder: (context) => Notifiche())); |
|
}, |
|
icon: Icon(Icons.notifications), |
|
) |
|
], |
|
), |
|
drawer: Menu(), |
|
body: ListView( |
|
children: [ |
|
Card( |
|
elevation: 10, |
|
shape: RoundedRectangleBorder( |
|
borderRadius: BorderRadius.circular(20.0), |
|
), |
|
margin: EdgeInsets.all(20), |
|
child: Column(children: [ |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)), |
|
color: HexColor(globals.coloreCard), |
|
), |
|
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15), |
|
child: Column( |
|
children: [ |
|
Row( |
|
children: [ |
|
Text( |
|
"Lista ultime misurazioni dello strumento: ", |
|
style: TextStyle(color: Colors.white), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), |
|
color: Colors.white, |
|
), |
|
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15), |
|
child: Column( |
|
children: [ |
|
if (this.listMisurazioni.length > 0) |
|
for (int i = 0; i < this.listMisurazioni.length; i++) |
|
if (this.listMisurazioni.length > 0) |
|
Container( |
|
child: Column( |
|
children: [ |
|
ListTile( |
|
leading: Icon(Icons.straighten), |
|
title: Text( |
|
this.listMisurazioni[i]['volume'].toString(), |
|
style: TextStyle(fontWeight: FontWeight.bold), |
|
), |
|
subtitle: Text( |
|
(this.listMisurazioni[i]['user']['name'].toString() + |
|
" " + |
|
this.listMisurazioni[i]['user']['surname'].toString()), |
|
style: TextStyle(fontStyle: FontStyle.italic), |
|
), |
|
trailing: Text(this.listMisurazioni[i]['date']), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
) |
|
]), |
|
), |
|
Center( |
|
child: Directionality( |
|
textDirection: TextDirection.rtl, |
|
child: ElevatedButton.icon( |
|
label: Text( |
|
"Aggiungi una nuova misurazione ", |
|
style: TextStyle(color: Colors.white), |
|
), |
|
onPressed: () { |
|
avviaFormSalvataggio(this.context); |
|
}, |
|
icon: Icon( |
|
Icons.add, |
|
color: Colors.white, |
|
), |
|
style: ElevatedButton.styleFrom( |
|
backgroundColor: HexColor(globals.colorAppbar), |
|
), |
|
), |
|
), |
|
), |
|
SizedBox( |
|
height: 30, |
|
), |
|
], |
|
)), |
|
); |
|
} |
|
|
|
Future<void> avviaFormSalvataggio(BuildContext context) { |
|
return showDialog<void>( |
|
context: context, |
|
builder: (BuildContext contextAlert) { |
|
return CupertinoAlertDialog( |
|
title: Text('Aggiungi una nuova misurazione'), |
|
content: Form( |
|
key: _formInput, |
|
child: Column( |
|
children: [ |
|
Container( |
|
padding: EdgeInsets.only(left: 15, right: 15), |
|
child: TextFormField( |
|
controller: this.volume, |
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly], |
|
keyboardType: TextInputType.number, |
|
decoration: InputDecoration( |
|
hintStyle: TextStyle(color: Colors.black), |
|
labelText: 'Lettura volume (m^3)*', |
|
labelStyle: TextStyle(color: Colors.black), |
|
enabledBorder: UnderlineInputBorder( |
|
borderSide: BorderSide(color: Colors.black), |
|
), |
|
focusedBorder: UnderlineInputBorder( |
|
borderSide: BorderSide(color: Colors.black), |
|
// when the TextFormField in focused |
|
), |
|
), |
|
validator: (value) { |
|
if (value!.isEmpty) { |
|
return "Attenzione campo obbligatorio"; |
|
} |
|
return null; |
|
}), |
|
), |
|
], |
|
), |
|
), |
|
actions: <Widget>[ |
|
TextButton( |
|
style: TextButton.styleFrom( |
|
textStyle: Theme.of(context).textTheme.labelLarge, |
|
), |
|
child: const Text('Annulla'), |
|
onPressed: () { |
|
this.volume.text = ""; |
|
|
|
Navigator.of(contextAlert).pop(); |
|
}, |
|
), |
|
TextButton( |
|
style: TextButton.styleFrom( |
|
textStyle: Theme.of(context).textTheme.labelLarge, |
|
), |
|
child: const Text('Salva'), |
|
onPressed: () { |
|
if (_formInput.currentState!.validate()) { |
|
if (this.volume.text != "" && this.widget.id != "") { |
|
ApiService().addMisurazioneStrumenti(this.volume.text, this.widget.id, this.context).then((value) { |
|
if (value['statusCode'] == 200) { |
|
setState(() { |
|
this.volume.text = ""; |
|
}); |
|
Navigator.of(contextAlert).pop(); |
|
Navigator.of(context).pop(); |
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar( |
|
content: Text(value['stringa'].toString()), |
|
)); |
|
} else if (value['statusCode'] == 401) { |
|
EasyLoading.dismiss(); |
|
Navigator.of(contextAlert).pop(); |
|
Utility().dialogAlert(this.context); |
|
} else { |
|
EasyLoading.dismiss(); |
|
Navigator.of(contextAlert).pop(); |
|
ScaffoldMessenger.of(context).showSnackBar( |
|
SnackBar( |
|
content: Text(value['stringa'].toString()), |
|
), |
|
); |
|
} |
|
|
|
EasyLoading.dismiss(); |
|
}); |
|
} |
|
} |
|
}, |
|
), |
|
], |
|
); |
|
}, |
|
); |
|
} |
|
}
|
|
|