import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:unit2/bloc/offline/offline_passo/land/land_property_assessment/land_property_assessment_bloc.dart'; import 'package:unit2/bloc/offline/offline_passo/land/value_adjustment/value_adjustment_bloc.dart'; import '../../../../../model/passo/land_value_adjustment.dart'; import '../../../../../theme-data.dart/form-style.dart'; import '../../../../../utils/text_container.dart'; import '../../../../../widgets/error_state.dart'; class AddPropertyAssessmentEditOfflineModal extends StatefulWidget { // final List unit; // final List options; // final int tempId; // AddLandAppraisalModal(this.unit, this.options, this.tempId); @override _AddPropertyAssessmentEditOfflineModal createState() => _AddPropertyAssessmentEditOfflineModal(); } class _AddPropertyAssessmentEditOfflineModal extends State { final focus = FocusNode(); bool isPainted = false; bool isSecondHand = false; TextEditingController textEditingController = TextEditingController(); double _unitBase = 0; int _areaValue = 0; final double _depValue = 0; double _unitValue = 0; String _subClassDesc = ""; int _classId = 0; String _structureType = ""; int _notPaintedUnitVal = 0; int _secondHandUnitVal = 0; String cityCode = ''; String cityDesc = ''; int classCode = 1; String _classDesc = ''; String _treeType = ""; bool _nonfruitBearing = false; bool _fruitBearing = false; int qty = 0; int pr_qty = 0; int nonpr_qty = 0; String _actualUse = "Residential"; String _assessmentLevel = ""; GlobalKey assessmentKey = GlobalKey(); final typeOfTree = [ "Non-Fruit Bearing", "Fruit Bearing", ]; final actual_use = [ "Residential", "Agricultural", "Commercial", "Industrial", "Mineral", "Timberland", ]; calculateAssessmentValue() { switch (_actualUse) { case "Residential": return (_unitValue * 0.20).ceil(); case "Agricultural": return (_unitValue * 0.40).ceil(); case "Commercial": return (_unitValue * 0.50).ceil(); case "Industrial": return (_unitValue * 0.50).ceil(); case "Mineral": return (_unitValue * 0.50).ceil(); case "Timberland": return (_unitValue * 0.20).ceil(); default: } } BoxDecoration box1() { return const BoxDecoration(boxShadow: [ BoxShadow(color: Colors.black12, spreadRadius: 5, blurRadius: 5) ], color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(3))); } double _amountofDepreciation(unitVal, unitBase, area, depreciation) { return ((unitVal * unitBase) * area) * depreciation; } double _totalMarketValue(unitBase, area) { return unitBase * area; } @override Widget build(BuildContext context) { return BlocBuilder( buildWhen: (previous, current) { return false; }, builder: (context, state) { if (state is ShowLandPropertyAssessmentcreen) { return BlocConsumer( listener: (context, state) { // TODO: implement listener }, builder: (context, state) { if (state is ValueAdjustmentLoaded) { final assessment = state.valueAdjustment; return FormBuilder( key: assessmentKey, onChanged: () { assessmentKey.currentState?.save(); }, autovalidateMode: AutovalidateMode.disabled, child: Padding( padding: const EdgeInsets.all(8.0), child: Container( child: SingleChildScrollView( padding: const EdgeInsets.all(8.0), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Container( margin: const EdgeInsets.only( left: 0, top: 10, right: 0, bottom: 0), child: Expanded( flex: 1, child: FormBuilderDropdown( name: 'value_adjustments', autofocus: false, decoration: normalTextFieldStyle( "Value Adjustments", ""), items: state.valueAdjustment .map((adj) => DropdownMenuItem( value: adj, child: Text( (adj.adjustmentFactors ?? ""), ), )) .toList(), onChanged: (selectedAdj) { if (selectedAdj != null) { setState(() { _unitValue = double.parse( selectedAdj.marketValue!); }); } }, )), ), SizedBox( height: 10, ), FormBuilderDropdown( name: "land_actual_use", autofocus: false, decoration: normalTextFieldStyle("Actual Use", ""), items: actual_use .map((item) => DropdownMenuItem( value: item, child: Text(item), )) .toList(), onChanged: (value) { setState(() { _actualUse = value!; switch (value) { case "Residential": setState(() { _assessmentLevel = '20'; }); break; case "Agricultural": setState(() { _assessmentLevel = '40'; }); break; case "Commercial": setState(() { _assessmentLevel = '50'; }); break; case "Industrial": setState(() { _assessmentLevel = '50'; }); break; case "Mineral": setState(() { _assessmentLevel = '50'; }); break; case "Timberland": setState(() { _assessmentLevel = '20'; }); break; default: } }); }, ), SizedBox( height: 10, ), Text('Assessment Level'), Container( height: 45.0, width: double.infinity, decoration: BoxDecoration( color: Colors.white, border: Border.all( color: Colors.grey, width: 1.0, ), borderRadius: BorderRadius.circular(5.0), ), child: Align( alignment: Alignment.center, child: Text(_assessmentLevel + '%'), ), ), SizedBox( height: 10, ), Text('Assessment Value'), Container( height: 45.0, width: double.infinity, decoration: BoxDecoration( color: Colors.white, border: Border.all( color: Colors.grey, width: 1.0, ), borderRadius: BorderRadius.circular(5.0), ), child: Align( alignment: Alignment.center, child: Text(NumberFormat.currency( locale: 'en-PH', symbol: "₱", ).format(calculateAssessmentValue().toString() == "0.00" ? "00.0" : calculateAssessmentValue())), ), ), const SizedBox(height: 10), Row( children: [ Container( width: 120, height: 60, padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () async { final tempID = await SharedPreferences.getInstance(); print(tempID.getInt('landid')! - 1); context .read() .add(AddLandPropertyAssessment( landapprDetailsId: tempID.getInt('landid')! - 1, actualUse: _actualUse, marketval: _unitValue.toString(), assessmentLevel: _assessmentLevel, assessedValue: calculateAssessmentValue() .toString(), totalMarketval: '0', totalAssessedval: '0')); }, style: ElevatedButton.styleFrom( primary: Colors.black, ), child: const Text("Submit"), ), ), const SizedBox( width: 5), // Use SizedBox for horizontal spacing in a Row Container( width: 120, height: 60, padding: const EdgeInsets.all(8.0), child: ElevatedButton( onPressed: () { context .read() .add( const LoadLandPropertyAssessment()); }, style: ElevatedButton.styleFrom( primary: Colors.black, ), child: const Text("Cancel"), ), ), ], ) ], ), ), ), )); } if (state is ValueAdjustmentErrorState) { return SomethingWentWrong( message: onError, onpressed: () { context .read() .add(const LoadValueAdjustment()); }, ); } return Container(); }); } if (state is LandPropertyAssessmentErrorState) { return SomethingWentWrong( message: onError, onpressed: () { context .read() .add(const LoadLandPropertyAssessment()); }, ); } return Container(); }); } }