You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
10 KiB

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:watermanagement/addtankers.dart';
import 'package:watermanagement/settings.dart';
import 'models/tanksview_model.dart';
class TanksView extends StatefulWidget {
@override
State<TanksView> createState() => _TanksViewState();
}
class _TanksViewState extends State<TanksView> {
List<GetTanksDetailsModel> modelTanksViewList = [];
TextEditingController tankerNameController = TextEditingController();
TextEditingController tankerPhoneController = TextEditingController();
TextEditingController tankerAlterPhoneController = TextEditingController();
bool isLoading=false;
Future<void> readJson() async {
var response1= await AppSettings.getTankers();
print(response1);
setState(() {
modelTanksViewList =
((jsonDecode(response1)['data']) as List).map((dynamic model) {
return GetTanksDetailsModel.fromJson(model);
}).toList();
isLoading=false;
});
}
@override
void initState() {
isLoading=true;
readJson();
super.initState();
}
Widget renderzUi(){
if(modelTanksViewList.length!=0){
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:ListView.builder(
padding: EdgeInsets.all(0),
itemCount: modelTanksViewList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
color: modelTanksViewList[index].cardColor,
child: Padding(
padding:EdgeInsets.all(8) ,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
//width: MediaQuery.of(context).size.width * .55,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('tankerName :',style: labelTextStyle()),
Text('phoneNumber :',style: labelTextStyle()),
Text('alternative_phoneNumber :',style: labelTextStyle()),
Text('Capacity :',style: labelTextStyle()),
Text('Type Of Water :',style: labelTextStyle()),
Text('price :',style: labelTextStyle()),
],
),
SizedBox(width: 5,),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(modelTanksViewList[index].tanker_name,style: valuesTextStyle()),
Text(modelTanksViewList[index].tanker_phone,style: valuesTextStyle()),
Text(modelTanksViewList[index].tanker_alterphone,style: valuesTextStyle()),
Text(modelTanksViewList[index].capacity+' Ltrs',style: valuesTextStyle()),
Text(modelTanksViewList[index].water_type,style: valuesTextStyle()),
Text(modelTanksViewList[index].price_ui,style: valuesTextStyle()),
],
),
],
),
],
),
),
Expanded(child:IconButton(
icon: const Icon(Icons.edit,color: primaryColor,),
onPressed: () {
// showUpdateTankDialog(modelTanksViewList[index]);
},
),),
Expanded(child:IconButton(
icon: const Icon(Icons.delete,color: primaryColor,),
onPressed: () async{
showDialog(
//if set to true allow to close popup by tapping out of the popup
//barrierDismissible: false,
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Do you want to delete tank?',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: ()async {
bool deleteTankStatus = await AppSettings.deleteTanker(modelTanksViewList[index].tanker_name);
if(deleteTankStatus){
readJson();
AppSettings.longSuccessToast('tank deleted successfully');
Navigator.of(context).pop(true);
}
else{
AppSettings.longFailedToast('tank deletion failed');
}
},
child: const Text('Yes',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text('No',
style: TextStyle(
color: primaryColor,
fontSize: 20,
)),
),
],
),
);
},
),)
],
),
),
);
}) ),
Padding(
padding: EdgeInsets.fromLTRB(8, 8, 8, 8),
child: CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async{
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTankers()),
);
//showBoreAddingDialog();
},
),
/* Padding(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Text(
'Add Tanks ',
style: TextStyle(color: Colors.white),
),
)*/
],
),
),
),
]);
}
else{
return Center(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: MediaQuery.of(context).size.height * .25,),
Text('Click below icon to add new Tanker'),
SizedBox(
height: 20,
),
CircleAvatar(
backgroundColor: primaryColor,
radius: 40,
child: IconButton(
iconSize: 40,
icon: const Icon(
Icons.add,
color: Colors.white,
),
onPressed: () async {
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTankers()),
);
},
),
)
],
),
)
);
}
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppSettings.appBar('Tanks'),
body: isLoading?Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
):renderzUi(),
));
}
}