passo_mobile_app/lib/screens/passo/Building/add_building.dart

295 lines
11 KiB
Dart
Raw Normal View History

2023-07-28 02:35:36 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
2023-09-01 03:22:48 +00:00
import 'package:fluttertoast/fluttertoast.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:unit2/bloc/passo/bulding/class_components/class_components_bloc.dart';
import 'package:unit2/bloc/passo/bulding/property_appraisal/property_appraisal_bloc.dart';
import 'package:unit2/bloc/passo/bulding/property_info/property_info_bloc.dart';
import 'package:unit2/bloc/passo/bulding/unit_construct/unit_construct_bloc.dart';
2023-07-28 02:35:36 +00:00
import 'package:unit2/model/passo/bldg_loc.dart';
import 'package:unit2/model/passo/class_components.dart';
2023-09-01 03:22:48 +00:00
import 'package:unit2/model/passo/general_description.dart';
2023-07-28 02:35:36 +00:00
import 'package:unit2/model/passo/land_ref.dart';
2023-09-01 03:22:48 +00:00
import 'package:unit2/model/passo/property_appraisal.dart';
2023-07-28 02:35:36 +00:00
import 'package:unit2/model/passo/property_info.dart';
2023-09-01 03:22:48 +00:00
import 'package:unit2/model/passo/structural_materials_ii.dart';
2023-07-28 02:35:36 +00:00
import 'package:unit2/screens/passo/Building/add_building_components/additional_items.dart';
import 'package:unit2/screens/passo/Building/add_building_components/bldg_location_landref.dart';
import 'package:unit2/screens/passo/Building/add_building_components/general_description.dart';
import 'package:unit2/screens/passo/Building/add_building_components/property_appraisal.dart';
import 'package:unit2/screens/passo/Building/add_building_components/property_assessment.dart';
import 'package:unit2/screens/passo/Building/add_building_components/property_info.dart';
import 'package:unit2/screens/passo/Building/add_building_components/structural_materials.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:im_stepper/stepper.dart';
2023-09-01 03:22:48 +00:00
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/error_state.dart';
2023-07-28 02:35:36 +00:00
GlobalKey<FormBuilderState> formKey = GlobalKey<FormBuilderState>();
class AddBuilding extends StatefulWidget {
@override
_AddBuilding createState() => _AddBuilding();
}
class _AddBuilding extends State<AddBuilding> {
int activeStep = 0; // Initial step set to 5.
int upperBound = 6;
bool saveStep1 = false;
bool saveStep2 = false;
bool saveStep3 = false;
bool saveStep4 = false;
bool saveStep5 = false;
bool saveStep6 = false;
bool saveStep7 = false;
int tempId = 0;
2023-09-01 03:22:48 +00:00
Future<void> _loadTempId() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
tempId = (prefs.getInt('tempid') ?? 0);
});
}
void PrevBtn() {
setState(() {
activeStep--;
});
}
void NextBtn() {
setState(() {
activeStep++;
});
2023-07-28 02:35:36 +00:00
}
2023-09-01 03:22:48 +00:00
void onPutStructuralMaterials() {
if (activeStep < upperBound) {
2023-07-28 02:35:36 +00:00
setState(() {
activeStep++;
});
}
2023-09-01 03:22:48 +00:00
// var strucMaterials = StructureMaterialsII(
// foundation: _foundations.getSelectedAsString().split(","),
// columns: _coumns.getSelectedAsString().split(","),
// beams: _beams.getSelectedAsString().split(","),
// trussFraming:
// _trussframing.getSelectedAsString().split(","),
// roof: _roof.getSelectedAsString().split(","),
// flooring: _flooring.getSelectedAsString().split(","),
// walls: _walls.getSelectedAsString().split(","));
}
void onPutPropertyAppraisal() {}
void bldgPrevBtn() {
if (activeStep > 0) {
setState(() {
activeStep--;
});
}
2023-07-28 02:35:36 +00:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: primary,
centerTitle: true,
title: const Text("Building FAAS"),
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<PropertyInfoBloc, PropertyInfoState>(listener: (
context,
state,
) {
if (state is PropertyInfoLoading) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
2023-09-01 03:22:48 +00:00
if (state is PropertyInfoLoaded) {
2023-07-28 02:35:36 +00:00
final progress = ProgressHUD.of(context);
progress?.dismiss();
}
2023-09-01 03:22:48 +00:00
if (state is PropertyInfoErrorState) {
final progress = ProgressHUD.of(context);
progress?.dismiss();
}
if (state is ShowBldgLocErrorAlertState ||
state is ShowGenDescErrorAlertState ||
state is ShowLandRefErrorAlertState ||
state is ShowStrucMatErrorAlertState) {
2023-09-01 03:22:48 +00:00
Fluttertoast.showToast(
msg: "Slow internet connection, please try again!");
}
if (state is ShowLandRefSuccessAlertState ||
state is ShowGenDescSuccessAlertState ||
state is ShowStrucMatSuccessAlertState) {
NextBtn();
2023-09-01 03:22:48 +00:00
}
2023-07-28 02:35:36 +00:00
}, builder: (context, state) {
2023-09-01 03:22:48 +00:00
if (state is PropertyInfoLoaded ||
state is PropertyInfoErrorState ||
state is ShowBldgLocErrorAlertState ||
state is ShowGenDescErrorAlertState ||
state is ShowLandRefErrorAlertState ||
state is ShowStrucMatErrorAlertState ||
state is ShowBldgLocSuccessAlertState ||
state is ShowLandRefSuccessAlertState ||
state is ShowGenDescSuccessAlertState ||
state is ShowStrucMatSuccessAlertState) {
2023-07-28 02:35:36 +00:00
return BlocConsumer<UnitConstructBloc, UnitConstructState>(
2023-09-01 03:22:48 +00:00
listener: (
context,
state,
) {
if (state is UnitConstructLoading) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is UnitConstructLoaded ||
state is UnitConstructErrorState) {
final progress = ProgressHUD.of(context);
progress?.dismiss();
}
2023-07-28 02:35:36 +00:00
},
builder: (context, state) {
if (state is UnitConstructLoaded) {
final unit = state.unit;
return BlocConsumer<ClassComponentsBloc,
ClassComponentsState>(
2023-09-01 03:22:48 +00:00
listener: (
context,
state,
) {
if (state is ClassComponentLoading) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is ClassComponentLoaded ||
state is ClassComponentErrorState) {
final progress = ProgressHUD.of(context);
progress?.dismiss();
}
2023-07-28 02:35:36 +00:00
},
builder: (context, state) {
if (state is ClassComponentLoaded) {
2023-09-01 03:22:48 +00:00
final classes = state.classes;
2023-07-28 02:35:36 +00:00
return Column(
children: [
NumberStepper(
numbers: [1, 2, 3, 4, 5, 6, 7],
stepPadding: 5,
2023-09-01 03:22:48 +00:00
activeStepColor: primary,
numberStyle: TextStyle(color: Colors.white),
lineColor: primary,
2023-07-28 02:35:36 +00:00
// activeStep property set to activeStep variable defined above.
activeStep: activeStep,
2023-09-01 03:22:48 +00:00
activeStepBorderColor: Colors.white,
activeStepBorderWidth: 1,
2023-07-28 02:35:36 +00:00
// This ensures step-tapping updates the activeStep.
onStepReached: (index) {
setState(() {
activeStep = index;
});
},
2023-09-01 03:22:48 +00:00
enableStepTapping: false,
2023-07-28 02:35:36 +00:00
),
Expanded(
2023-09-01 03:22:48 +00:00
child: StatefulBuilder(builder:
(BuildContext context,
StateSetter setState) {
return FormBuilder(
key: formKey,
onChanged: () {
formKey.currentState?.save();
},
autovalidateMode: AutovalidateMode.disabled,
child: Container(
child: content(
unit,
classes,
PrevBtn,
NextBtn,
),
),
);
}),
),
2023-07-28 02:35:36 +00:00
],
);
}
2023-09-01 03:22:48 +00:00
if (state is ClassComponentErrorState) {
return SomethingWentWrong(
message: onError,
onpressed: () {
context
.read<ClassComponentsBloc>()
.add(LoadClassComponents());
},
);
}
2023-07-28 02:35:36 +00:00
return Container();
},
);
}
2023-09-01 03:22:48 +00:00
if (state is UnitConstructErrorState) {
return SomethingWentWrong(
message: onError,
onpressed: () {
context
.read<UnitConstructBloc>()
.add(LoadUnitConstruct());
},
);
}
2023-07-28 02:35:36 +00:00
return Container();
},
);
}
2023-09-01 03:22:48 +00:00
2023-07-28 02:35:36 +00:00
return Container();
})),
);
}
2023-09-01 03:22:48 +00:00
Widget content(unit, List<ClassComponents> classes, PrevBtn, NextBtn) {
2023-07-28 02:35:36 +00:00
switch (activeStep) {
case 0:
2023-09-01 03:22:48 +00:00
return PropertyInfoPage(NextBtn);
2023-07-28 02:35:36 +00:00
case 1:
2023-09-01 03:22:48 +00:00
return BldgLocationLandrefPage(PrevBtn, NextBtn);
2023-07-28 02:35:36 +00:00
case 2:
2023-09-01 03:22:48 +00:00
return GeneralDescriptionPage(unit, NextBtn, PrevBtn);
2023-07-28 02:35:36 +00:00
case 3:
2023-09-01 03:22:48 +00:00
return StructuralMaterialsPage(PrevBtn, NextBtn);
2023-07-28 02:35:36 +00:00
case 4:
2023-09-01 03:22:48 +00:00
return AdditionalItemPage(unit, classes, PrevBtn, NextBtn);
2023-07-28 02:35:36 +00:00
case 5:
2023-09-01 03:22:48 +00:00
return PropertyAppraisalPage(NextBtn, PrevBtn);
2023-07-28 02:35:36 +00:00
case 6:
return PropertyAssessmentPage(onSAveAll);
default:
return Text("Property Info");
}
}
void onSAveAll() {
return Navigator.of(context).pop();
}
}