added functionality for update tanker

dev
Sneha 2 years ago
parent bd918c3c59
commit b0be1b56fc

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:watermanagement/settings.dart';
import 'package:watermanagement/tankersview.dart';
import 'dashboard.dart';
@ -73,6 +74,7 @@ class _AddTankersState extends State<AddTankers> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppSettings.appBar('Add Tanker'),
body: SafeArea(
child: SingleChildScrollView(
child: Column(
@ -455,9 +457,9 @@ class _AddTankersState extends State<AddTankers> {
payload["phoneNumber"] = tankerPhoneNumberController.text.toString();
payload["alternative_phoneNumber"] = tankerAlternativePhoneNumberController.text.toString();
payload["capacity"] = tankerCapacityController.text.toString();
payload["typeofwater"] = waterTypes;
payload["typeofwater"] = waterTypes;
payload["price"] = waterPrice;
payload["supplier_address"] = '';
payload["supplier_address"] = AppSettings.supplierAddress;
payload["supplier_name"] = AppSettings.suppliername;
bool tankStatus = await AppSettings.addTankers(payload);
@ -469,12 +471,18 @@ class _AddTankersState extends State<AddTankers> {
tankerNameController.text = '';
tankerPhoneNumberController.text = '';
tankerCapacityController.text = '';
tankerAlternativePhoneNumberController.text='';
tankerDrinkingPriceController.text='';
tankerBorePriceController.text='';
waterPrice=[];
waterTypes=[];
isDrinkingChecked=false;
isBoreChecked=false;
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const Dashboard()),
builder: (context) => TankersView()),
);
}

@ -7,7 +7,7 @@ import 'package:watermanagement/login.dart';
import 'package:watermanagement/place_picker.dart';
import 'package:watermanagement/settings.dart';
import 'package:image_picker/image_picker.dart';
import 'package:watermanagement/tanksview.dart';
import 'package:watermanagement/tankersview.dart';
import 'dart:io';
@ -367,13 +367,13 @@ class _DashboardState extends State<Dashboard> {
const SizedBox(
width: 10,
),
Text('Get All Tanks',style: TextStyle(color:primaryColor)),
Text('Tankers View',style: TextStyle(color:primaryColor)),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => TanksView()),
MaterialPageRoute(builder: (context) => TankersView()),
);
},
),

@ -1,112 +0,0 @@
import 'package:watermanagement/settings.dart';
class TankersModel {
String tanker_name = '';
var capacity='';
String type_of_water='';
String phone_number='';
List capacitiesOfTanker=[];
List showCapacity=[];
List waterType=[];
List showTypeofWater=[];
var typeOfWaterForBooking=[];
var capacitiesForBooking=[];
bool isFiveChecked=false;
bool isTenChecked=false;
bool isFifteenChecked=false;
bool isTwentyChecked=false;
bool isDrinkingChecked=false;
bool isBoreChecked=false;
List updatedCapacities=[];
List updatedWaterTypes=[];
TankersModel();
factory TankersModel.fromJson(Map<String, dynamic> json){
TankersModel rtvm = new TankersModel();
rtvm.tanker_name = json['tankerName'] ?? '';
rtvm.phone_number = json['phoneNumber'] ?? '';
rtvm.capacitiesOfTanker = json['capacity']??[];
rtvm.capacitiesOfTanker.forEach((element) {
rtvm.showCapacity.add(element['capacity']);
rtvm.capacitiesForBooking.add(element['capacity']);
rtvm.capacity=rtvm.showCapacity.join(",");
if(element['capacity']=='5000'){
rtvm.isFiveChecked=true;
rtvm.updatedCapacities.add({'capacity': '5000'});
}
else if(element['capacity']=='10000'){
rtvm.isTenChecked=true;
rtvm.updatedCapacities.add({'capacity': '10000'});
}
else if(element['capacity']=='15000'){
rtvm.isFifteenChecked=true;
rtvm.updatedCapacities.add({'capacity': '15000'});
}
else if(element['capacity']=='20000'){
rtvm.isTwentyChecked=true;
rtvm.updatedCapacities.add({'capacity': '20000'});
}
else{
rtvm.isFiveChecked=false;
rtvm.isFiveChecked=false;
rtvm.isFiveChecked=false;
rtvm.isTwentyChecked=false;
rtvm.updatedCapacities.remove({'capacity': '5000'});
rtvm.updatedCapacities.remove({'capacity': '10000'});
rtvm.updatedCapacities.remove({'capacity': '15000'});
rtvm.updatedCapacities.remove({'capacity': '20000'});
}
});
rtvm.waterType = json['typeofwater']??[];
rtvm.waterType.forEach((element) {
rtvm.showTypeofWater.add(element['typeofwater']);
rtvm.typeOfWaterForBooking.add(element['typeofwater']);
rtvm.type_of_water=rtvm.showTypeofWater.join(",");
if(element['typeofwater'].toString().toUpperCase()=='DRINKING WATER'){
rtvm.isDrinkingChecked=true;
rtvm.updatedWaterTypes.add({'typeofwater': 'Drinking Water'});
}
else if(element['typeofwater'].toString().toUpperCase()=='BORE WATER'){
rtvm.isBoreChecked=true;
rtvm.updatedWaterTypes.add({'typeofwater': 'Bore Water'});
}
else{
rtvm.isBoreChecked=false;
rtvm.isDrinkingChecked=false;
rtvm.updatedWaterTypes.remove({'typeofwater': 'Drinking Water'});
rtvm.updatedWaterTypes.remove({'typeofwater': 'Bore Water'});
}
});
return rtvm;
}
Map<String, dynamic> toJson() => {
"tankerName":this.tanker_name,
"capacity": this.capacity,
"typeofwater": this.type_of_water ,
"phoneNumber": this.phone_number,
"capacity": this.capacitiesOfTanker,
"typeofwater": this.waterType,
};
}

@ -17,6 +17,10 @@ class GetTanksDetailsModel {
String price_ui='';
Color cardColor=Colors.white;
bool isDrinking=false;
bool isBore=false;
List updatedWaterTypes=[];
List updatePrice=[];
GetTanksDetailsModel();
@ -35,6 +39,17 @@ class GetTanksDetailsModel {
rtvm.water_type=rtvm.showTypeofWater.join(",");
if(element['typeofwater'].toString().toLowerCase()=='drinking water'){
rtvm.isDrinking=true;
rtvm.updatedWaterTypes.add({'typeofwater': 'Drinking Water'});
}
else if(element['typeofwater'].toString().toLowerCase()=='bore water'){
rtvm.isBore=true;
rtvm.updatedWaterTypes.add({'typeofwater': 'Bore Water'});
}
});
rtvm.price = json['price'] ?? [];

@ -64,6 +64,7 @@ class AppSettings {
static String accessToken = '';
static String customerId = '';
static String supplierId = '';
static String supplierAddress = '';
static String customerIdsign = '';
static List<String> storedPreferenceValidKeys = ['suppliername', 'access_token'];
static String preloadText = 'Please wait';
@ -84,6 +85,7 @@ class AppSettings {
static String verifyPhnUrl = host+'supplierphone';
static String resetTokenUrl = host+'reset_token';
static String addTankerUrl = host + 'addTankers';
static String UpdateTankerUrl = host + 'updateTankers';
static String getTankersDataUrl = host + 'getTankers';
static String deleteTankerUrl = host + 'deleteTanker';
@ -346,6 +348,38 @@ class AppSettings {
}
}
static Future<bool> updateTanker(tankerName, payload) async {
var uri = Uri.parse(UpdateTankerUrl + '/' + supplierId);
uri = uri.replace(query: 'tankerName=$tankerName');
try {
var response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else if (response.statusCode == 401) {
bool status = await AppSettings.resetToken();
if (status) {
response = await http.put(uri,
body: json.encode(payload), headers: await buildRequestHeaders());
if (response.statusCode == 200) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} catch (e) {
print(e);
return false;
}
}
static Future<bool> deleteTanker(tankerName) async {
var uri = Uri.parse(deleteTankerUrl + '/' + supplierId);
uri = uri.replace(query: 'tankerName=$tankerName');
@ -378,7 +412,6 @@ class AppSettings {
}
}
static Future<bool> addDeliverboy(payload) async {
var response = await http.post(Uri.parse(addDeliveryboyUrl + '/' + supplierId),
body: json.encode(payload), headers: await buildRequestHeaders());
@ -425,6 +458,8 @@ class AppSettings {
await saveData('phone', input['simplydata']['phone'], 'STRING');
await saveData('email', input['simplydata']['email'][0]['email'], 'STRING');
await saveData('supplierId', input['simplydata']['supplierId'], 'STRING');
await saveData('supplieraddress', input['simplydata']['office_address'], 'STRING');
await loadDataFromMemory();
}
static Future<void> saveProfile(dynamic image) async {
@ -439,6 +474,7 @@ class AppSettings {
email=await getData('email', 'STRING');
phoneNumber=await getData('phone', 'STRING');
supplierId=await getData('supplierId', 'STRING');
supplierAddress=await getData('supplieraddress', 'STRING');
}
//assign saved values to variables

@ -0,0 +1,657 @@
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/tankersview_model.dart';
class TankersView extends StatefulWidget {
@override
State<TankersView> createState() => _TankersViewState();
}
class _TankersViewState extends State<TankersView> {
List<GetTanksDetailsModel> modelTanksViewList = [];
TextEditingController tankerNameController = TextEditingController();
TextEditingController tankerPhoneController = TextEditingController();
TextEditingController tankerAlterPhoneController = TextEditingController();
TextEditingController updateTankerNameController = TextEditingController();
TextEditingController updateTankerDescriptionController = TextEditingController();
TextEditingController updateTankerPhoneNumberController = TextEditingController();
TextEditingController updateTankerAlternatePhoneNumberController = TextEditingController();
TextEditingController updateTankerCapacityController = TextEditingController();
TextEditingController tankerBorePriceController = TextEditingController();
TextEditingController tankerDrinkingPriceController = TextEditingController();
bool isLoading=false;
bool isDrinkingChecked = false;
bool isBoreChecked = false;
List waterTypes = [];
List waterPrice = [];
List updateWaterTypes = [];
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();
}
showUpdateTankerDialog(var object) async {
updateTankerNameController.text = object.tanker_name;
updateTankerDescriptionController.text = '';
updateTankerPhoneNumberController.text = object.tanker_phone;
updateTankerCapacityController.text=object.capacity;
updateTankerAlternatePhoneNumberController.text = object.tanker_alterphone;
isDrinkingChecked=object.isDrinking;
isBoreChecked = object.isBore;
tankerDrinkingPriceController.text=object.pricetype[0].toString();
tankerBorePriceController.text=object.pricetype[1].toString();
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return AlertDialog(
title: const Text('Update Tanker'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Container(
//padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextFormField(
cursorColor: greyColor,
controller: updateTankerNameController,
textCapitalization: TextCapitalization.characters,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.ac_unit_outlined,
color: greyColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter update tanker supplier name',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
), //tanker name
),
const SizedBox(
height: 30,
),
Container(
//padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextFormField(
cursorColor: greyColor,
controller: updateTankerPhoneNumberController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.phone_android,
color: greyColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter phone number',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),
), //phone number
const SizedBox(
height: 30,
),
Visibility(
visible: true,
child: Container(
//padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextFormField(
cursorColor: greyColor,
controller:
updateTankerAlternatePhoneNumberController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.phone_android,
color: greyColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter alternate phone number',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),
)), //alternate phone number
const SizedBox(
height: 30,
),
Visibility(
visible: true,
child: Container(
//padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextFormField(
onChanged: (value) {
value = '${AppSettings.formNum(
value.replaceAll(',', ''),
)}';
updateTankerCapacityController.value = TextEditingValue(
text: value,
selection: TextSelection.collapsed(
offset: value.length,
),
);
},
cursorColor: greyColor,
controller: updateTankerCapacityController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.ac_unit_outlined,
color: greyColor,
),
suffix: capacitySuffixText(),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter Capacity',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
),
),
)), //capacity
const SizedBox(
height: 30,
),
Container(
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: Visibility(
visible: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Choose type of water',
style: TextStyle(color: primaryColor,fontSize: 20),
),
SizedBox(height:10),
Row(
children: [
Text(
'Drinking',
style: TextStyle(color: Colors.black,fontSize: 20),
),
Checkbox(
checkColor: Colors.white,
activeColor: primaryColor,
value: isDrinkingChecked,
onChanged: (bool? value) {
setState(() {
isDrinkingChecked = value!;
});
if (isDrinkingChecked) {
object.updatedWaterTypes
.add({'typeofwater': 'Drinking Water'});
// waterPrice.add({'price': tankerDrinkingPriceController.text.toString()});
} else {
object.updatedWaterTypes.removeWhere((e) => e['typeofwater'].toString().toUpperCase() == 'DRINKING WATER');
// waterPrice.removeWhere((e) => e['price'].toString().toUpperCase() == tankerDrinkingPriceController.text.toString());
}
},
),
Visibility(
visible: isDrinkingChecked,
child: Container(
height: 40,
width:200,
child:TextFormField(
cursorColor: greyColor,
controller: tankerDrinkingPriceController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.currency_rupee,
color: greyColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter Price',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
contentPadding: EdgeInsets.all(5),
),
),
),
)
],
),
SizedBox(height:10),
Row(
children: [
Text(
'Bore',
style: TextStyle(color: Colors.black,fontSize: 20),
),
SizedBox(width: 35),
Checkbox(
checkColor: Colors.white,
activeColor: primaryColor,
value: isBoreChecked,
onChanged: (bool? value) {
setState(() {
isBoreChecked = value!;
});
if (isBoreChecked) {
object.updatedWaterTypes
.add({'typeofwater': 'Bore Water'});
} else {
object.updatedWaterTypes.removeWhere((e) => e['typeofwater'].toString().toUpperCase() == 'BORE WATER');
}
},
),
Visibility(
visible: isBoreChecked,
child: Container(
height: 40,
width:200,
child:TextFormField(
cursorColor: greyColor,
controller: tankerBorePriceController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(
Icons.currency_rupee,
color: greyColor,
),
border: OutlineInputBorder(
borderSide: BorderSide(color: greyColor)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: greyColor),
),
labelText: 'Enter Price',
labelStyle: TextStyle(
color: greyColor, //<-- SEE HERE
),
contentPadding: EdgeInsets.all(5),
),
),
),)
],
)
],
))
),
],
),
),
actions: <Widget>[
TextButton(
child: Text('cancel', style: textButtonStyle()),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Update', style: textButtonStyle()),
onPressed: () async {
if (updateTankerNameController.text != '' &&
updateTankerPhoneNumberController.text != '' &&
object.updatedWaterTypes.isNotEmpty ) {
waterPrice=[];
if(isDrinkingChecked){
waterPrice.add({'price': tankerDrinkingPriceController.text.toString()});
}
if(isBoreChecked){
waterPrice.add({'price': tankerBorePriceController.text.toString()});
}
AppSettings.preLoaderDialog(context);
var payload = new Map<String, dynamic>();
payload["tankerName"] = updateTankerNameController.text.toString();
payload["phoneNumber"] = updateTankerPhoneNumberController.text.toString();
payload["alternative_phoneNumber"] = updateTankerAlternatePhoneNumberController.text.toString();
payload["capacity"] = updateTankerCapacityController.text.toString();
payload["typeofwater"] = object.updatedWaterTypes;
payload["price"] = waterPrice;
payload["supplier_address"] = AppSettings.supplierAddress;
payload["supplier_name"] = AppSettings.suppliername;
bool tankStatus = await AppSettings.updateTanker(object.tanker_name, payload);
try {
if (tankStatus) {
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longSuccessToast(
"Tanker Updated Successfully");
updateTankerNameController.text = '';
updateTankerPhoneNumberController.text = '';
updateTankerAlternatePhoneNumberController.text='';
updateTankerCapacityController.text='';
Navigator.of(context).pop();
await readJson();
} else {
Navigator.of(context, rootNavigator: true).pop();
AppSettings.longFailedStyledToast(
"Tanker upadtion failed", context);
Navigator.of(context).pop();
}
} catch (exception) {
Navigator.of(context).pop();
print(exception);
}
} else {
AppSettings.longFailedStyledToast("enter details", context);
}
},
),
],
);
});
},
);
}
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: () {
showUpdateTankerDialog(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('Tankers'),
body: isLoading?Center(
child: CircularProgressIndicator(
color: primaryColor,
strokeWidth: 5.0,
),
):renderzUi(),
));
}
}

@ -1,272 +0,0 @@
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(),
));
}
}
Loading…
Cancel
Save