import 'package:date_time_picker/date_time_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/src/widgets/placeholder.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:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import '../../../../model/location/city.dart'; import '../../../../model/location/country.dart'; import '../../../../model/location/provinces.dart'; import '../../../../model/location/region.dart'; import '../../../../model/utils/eligibility.dart'; import '../../../../theme-data.dart/btn-style.dart'; import '../../../../theme-data.dart/colors.dart'; import '../../../../theme-data.dart/form-style.dart'; import '../../../../utils/global.dart'; import '../../../../utils/text_container.dart'; class AddEligibilityScreen extends StatefulWidget { const AddEligibilityScreen({super.key}); @override State createState() => _AddEligibilityScreenState(); } class _AddEligibilityScreenState extends State { @override Widget build(BuildContext context) { bool? overseas; final formKey = GlobalKey(); final regionKey = GlobalKey(); Region? selectedRegion; Province? selectedProvince; Country? selectedCountry; CityMunicipality selectedCity; Eligibility? selectedEligibility; return BlocBuilder( builder: (context, state) { if (state is UserLoggedIn) { return BlocBuilder( builder: (context, state) { if (state is AddEligibilityState) { overseas = state.overseas; selectedEligibility = state.currentEligibility; return ProgressHUD( child: Center( child: Padding( padding: const EdgeInsets.symmetric( vertical: 25, horizontal: 18), child: FormBuilder( key: formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ //ELIGIBILITIES DROPDOWN FormBuilderDropdown( initialValue: selectedEligibility, items: state.eligibilities .map>( (Eligibility eligibility) { return DropdownMenuItem( value: eligibility, child: Text(eligibility.title)); }).toList(), name: "eligibility", decoration: normalTextFieldStyle( "Eligibility*", "Eligibility"), ), const SizedBox( height: 20, ), SizedBox( width: screenWidth, child: Row( children: [ //LICENSE NUMBER Flexible( flex: 1, child: FormBuilderTextField( name: 'license number', initialValue: "", decoration: normalTextFieldStyle( "license number", "license number"), ), ), const SizedBox( width: 12, ), //RATING Flexible( flex: 1, child: FormBuilderTextField( name: 'rating', initialValue: "", decoration: normalTextFieldStyle( 'rating', 'rating'), ), ), ], ), ), const SizedBox( height: 20, ), SizedBox( width: screenWidth, child: Row( children: [ //EXAM DATE Flexible( flex: 1, child: DateTimePicker( firstDate: DateTime(2000), lastDate: DateTime(2100), decoration: normalTextFieldStyle( "Exam date", "Exam date"), initialValue: "", )), const SizedBox( width: 12, ), //VALIDITY DATE Flexible( flex: 1, child: DateTimePicker( firstDate: DateTime(2000), lastDate: DateTime(2100), decoration: normalTextFieldStyle( "Validity date", "Validity date"), initialValue: "", ), ), ], ), ), const SizedBox( height: 20, ), Text( "Placement of Examination/Confinement", style: Theme.of(context) .textTheme .displaySmall! .copyWith(fontSize: blockSizeVertical * 2), ), const SizedBox( height: 12, ), FormBuilderSwitch( initialValue: overseas, activeColor: second, onChanged: (value) { overseas = value; regionKey.currentState?.fields['region']?.reset(); context.read().add(AddEligibility( selectedEligibility: selectedEligibility, overseas: overseas!, selectedProvince: null, selectedRegion: null)); }, decoration: normalTextFieldStyle("", ''), name: 'overseas', title: const Text("Overseas Address?"), ), const SizedBox( height: 12, ), SizedBox( child: overseas == true ? FormBuilderDropdown( initialValue: null, items: state.countries .map>( (Country country) { return DropdownMenuItem( value: country, child: FittedBox( child: Text(country.name!))); }).toList(), name: 'country', decoration: normalTextFieldStyle( "Country*", "Country"), onChanged: (Country? value) { selectedCountry = value; }, ) : Column( children: [ //REGION DROPDOWN FormBuilderDropdown( onChanged: (Region? region) { selectedRegion = region; context.read().add( AddEligibility( selectedEligibility: selectedEligibility, overseas: overseas!, selectedProvince: null, selectedRegion: selectedRegion)); }, initialValue: state.currentRegion, decoration: normalTextFieldStyle( "Region*", "Region"), name: 'region', items: state.regions .map>( (Region region) { return DropdownMenuItem( value: region, child: Text(region.description!)); }).toList(), ), const SizedBox( height: 12, ), //PROVINCE DROPDOWN FormBuilderDropdown( initialValue: state.currentProvince, name: 'province', onChanged: (Province? province) { selectedProvince = province; context.read().add( AddEligibility( selectedEligibility: selectedEligibility, overseas: overseas!, selectedProvince: selectedProvince, selectedRegion: state.currentRegion)); }, items: state.provinces == null ? [] : state.provinces!.map< DropdownMenuItem< Province>>( (Province province) { return DropdownMenuItem( value: province, child: Text(province .description!)); }).toList(), decoration: normalTextFieldStyle( "Province*", "Province")), const SizedBox( height: 12, ), FormBuilderDropdown( onChanged: (CityMunicipality? city) { selectedCity = city!; }, decoration: normalTextFieldStyle( "Municipality*", "Municipality"), name: 'municipality', items: state.cities == null ? [] : state.cities!.map< DropdownMenuItem< CityMunicipality>>( (CityMunicipality c) { return DropdownMenuItem( value: c, child: Text(c .description!)); }).toList(), initialValue: null), const SizedBox( height: 20, ), ], )), const Expanded( child: SizedBox(), ), SizedBox( width: screenWidth, height: 60, child: ElevatedButton( style: mainBtnStyle( primary, Colors.transparent, second), onPressed: () {}, child: const Text(submit)), ), const SizedBox( height: 20, ), ], ), ), ), ), ); } return Container(); }); } return Container(); }, ); } }