2023-02-23 00:53:14 +00:00
|
|
|
import 'package:date_time_picker/date_time_picker.dart';
|
|
|
|
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';
|
2023-02-23 05:51:53 +00:00
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
2023-02-23 00:53:14 +00:00
|
|
|
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';
|
2023-02-23 05:51:53 +00:00
|
|
|
import '../../../../utils/location_utilities.dart';
|
2023-02-23 00:53:14 +00:00
|
|
|
import '../../../../utils/text_container.dart';
|
|
|
|
|
|
|
|
class AddEligibilityScreen extends StatefulWidget {
|
|
|
|
const AddEligibilityScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AddEligibilityScreen> createState() => _AddEligibilityScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
|
2023-02-23 05:51:53 +00:00
|
|
|
final formKey = GlobalKey<FormBuilderState>();
|
|
|
|
final provinceKey = GlobalKey<FormBuilderState>();
|
|
|
|
bool? overseas;
|
|
|
|
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
|
|
|
|
Region? selectedRegion;
|
|
|
|
Province? selectedProvince;
|
|
|
|
CityMunicipality? selectedMunicipality;
|
|
|
|
Country? selectedCountry;
|
|
|
|
Eligibility? selectedEligibility;
|
|
|
|
List<Province>? provinces;
|
|
|
|
List<CityMunicipality>? citymuns;
|
|
|
|
bool provinceCall = false;
|
|
|
|
bool cityCall = false;
|
2023-02-23 00:53:14 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-02-23 05:51:53 +00:00
|
|
|
//USERBLOC
|
2023-02-23 00:53:14 +00:00
|
|
|
return BlocBuilder<UserBloc, UserState>(
|
|
|
|
builder: (context, state) {
|
2023-02-23 05:51:53 +00:00
|
|
|
//LOGGED IN USER STATE
|
2023-02-23 00:53:14 +00:00
|
|
|
if (state is UserLoggedIn) {
|
2023-02-23 05:51:53 +00:00
|
|
|
//PROFIILE BLOC
|
2023-02-23 00:53:14 +00:00
|
|
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
2023-02-23 05:51:53 +00:00
|
|
|
buildWhen: (previous, current) {
|
|
|
|
if (state is EditEligibilityState) {}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
builder: (context, state) {
|
|
|
|
//EDIT ELIGIBILITY STATE
|
|
|
|
if (state is AddEligibilityState) {
|
|
|
|
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<Eligibility>(
|
|
|
|
onChanged: (Eligibility? eligibility) {
|
|
|
|
selectedEligibility = eligibility;
|
|
|
|
},
|
|
|
|
initialValue: state.eligibilities[0],
|
|
|
|
items: state.eligibilities
|
|
|
|
.map<DropdownMenuItem<Eligibility>>(
|
|
|
|
(Eligibility eligibility) {
|
|
|
|
return DropdownMenuItem<Eligibility>(
|
|
|
|
value: eligibility,
|
|
|
|
child: Text(eligibility.title));
|
|
|
|
}).toList(),
|
|
|
|
name: "eligibility",
|
|
|
|
decoration:
|
|
|
|
normalTextFieldStyle("Eligibility", "")
|
|
|
|
.copyWith(
|
|
|
|
hintStyle: const TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
labelStyle: const TextStyle(
|
|
|
|
color: Colors.black)),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
|
|
|
|
SizedBox(
|
|
|
|
width: screenWidth,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
//LICENSE NUMBER
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
name: 'license_number',
|
|
|
|
initialValue:null,
|
|
|
|
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"license number", "license number"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
//RATING
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
name: 'rating',
|
|
|
|
|
|
|
|
// ignore: prefer_null_aware_operators
|
|
|
|
initialValue:null,
|
|
|
|
|
|
|
|
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
'rating', 'rating'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-02-23 00:53:14 +00:00
|
|
|
),
|
2023-02-23 05:51:53 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: screenWidth,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
//EXAM DATE
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: DateTimePicker(
|
|
|
|
// controller: examDateController,
|
|
|
|
firstDate: DateTime(2000),
|
|
|
|
lastDate: DateTime(2100),
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Exam date", "Exam date"),
|
|
|
|
initialValue:null,
|
|
|
|
)),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
//VALIDITY DATE
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: DateTimePicker(
|
|
|
|
// controller: validityDateController,
|
|
|
|
firstDate: DateTime(2000),
|
|
|
|
lastDate: DateTime(2100),
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Validity date", "Validity date"),
|
|
|
|
initialValue:null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-02-23 00:53:14 +00:00
|
|
|
),
|
2023-02-23 05:51:53 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Placement of Examination/Confinement",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.displaySmall!
|
|
|
|
.copyWith(fontSize: blockSizeVertical * 2),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
//OVERSEAS ADDRESS SWITCH
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
FormBuilderSwitch(
|
|
|
|
initialValue: overseas,
|
|
|
|
activeColor: second,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
overseas = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
decoration: normalTextFieldStyle("", ''),
|
|
|
|
name: 'overseas',
|
|
|
|
title: const Text("Overseas Address?"),
|
2023-02-23 00:53:14 +00:00
|
|
|
),
|
2023-02-23 05:51:53 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
2023-02-23 00:53:14 +00:00
|
|
|
),
|
2023-02-23 05:51:53 +00:00
|
|
|
//COUNTRY DROPDOWN
|
|
|
|
SizedBox(
|
|
|
|
child: overseas == true
|
|
|
|
? FormBuilderDropdown<Country>(
|
|
|
|
initialValue: null,
|
|
|
|
items: state.countries.map<
|
|
|
|
DropdownMenuItem<
|
|
|
|
Country>>(
|
|
|
|
(Country country) {
|
|
|
|
return DropdownMenuItem<
|
|
|
|
Country>(
|
|
|
|
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<Region?>(
|
|
|
|
onChanged:
|
|
|
|
(Region? region) async {
|
|
|
|
setState(() {
|
|
|
|
provinceCall = true;
|
|
|
|
});
|
|
|
|
selectedRegion = region;
|
|
|
|
getProvinces();
|
|
|
|
},
|
|
|
|
initialValue: selectedRegion,
|
|
|
|
decoration:
|
|
|
|
normalTextFieldStyle(
|
|
|
|
"Region*", "Region"),
|
|
|
|
name: 'region',
|
|
|
|
items: state.regions.map<
|
|
|
|
DropdownMenuItem<
|
|
|
|
Region>>(
|
|
|
|
(Region region) {
|
|
|
|
return DropdownMenuItem<
|
|
|
|
Region>(
|
|
|
|
value: region,
|
|
|
|
child: Text(region
|
|
|
|
.description!));
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
//PROVINCE DROPDOWN
|
|
|
|
SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: ModalProgressHUD(
|
|
|
|
inAsyncCall: cityCall,
|
|
|
|
child: DropdownButtonFormField<
|
|
|
|
Province?>(
|
|
|
|
isExpanded: true,
|
|
|
|
value: selectedProvince,
|
|
|
|
onChanged: (Province?
|
|
|
|
province) {
|
|
|
|
setState(() {
|
|
|
|
cityCall = true;
|
|
|
|
});
|
|
|
|
selectedProvince = province;
|
|
|
|
getCities();
|
|
|
|
},
|
|
|
|
items: provinces == null
|
|
|
|
? []
|
|
|
|
: provinces!.map<
|
|
|
|
DropdownMenuItem<
|
|
|
|
Province>>(
|
|
|
|
(Province
|
|
|
|
province) {
|
|
|
|
return DropdownMenuItem(
|
|
|
|
value:
|
|
|
|
province,
|
|
|
|
child: FittedBox(
|
|
|
|
child: Text(
|
|
|
|
province
|
|
|
|
.description!),
|
|
|
|
));
|
|
|
|
}).toList(),
|
|
|
|
decoration:
|
|
|
|
normalTextFieldStyle(
|
|
|
|
"Province*",
|
|
|
|
"Province")),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: DropdownButtonFormField<
|
|
|
|
CityMunicipality>(
|
|
|
|
onChanged:
|
|
|
|
(CityMunicipality?
|
|
|
|
city) {
|
|
|
|
selectedMunicipality =
|
|
|
|
city;
|
|
|
|
},
|
|
|
|
decoration:
|
|
|
|
normalTextFieldStyle(
|
|
|
|
"Municipality*",
|
|
|
|
"Municipality"),
|
|
|
|
value: selectedMunicipality,
|
|
|
|
items: citymuns == null
|
|
|
|
? []
|
|
|
|
: citymuns!.map<
|
|
|
|
DropdownMenuItem<
|
|
|
|
CityMunicipality>>(
|
|
|
|
(CityMunicipality
|
|
|
|
c) {
|
|
|
|
return DropdownMenuItem(
|
|
|
|
value: c,
|
|
|
|
child: Text(c
|
|
|
|
.description!));
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
]),
|
2023-02-23 00:53:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-02-23 05:51:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
2023-02-23 00:53:14 +00:00
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-02-23 05:51:53 +00:00
|
|
|
|
|
|
|
Future<void> getProvinces() async {
|
|
|
|
List<Province> _provinces = await LocationUtils.instance
|
|
|
|
.getProvinces(regionCode: selectedRegion!.code.toString());
|
|
|
|
setState(() {
|
|
|
|
provinces = _provinces;
|
|
|
|
selectedProvince = provinces![0];
|
|
|
|
getCities();
|
|
|
|
provinceCall = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Future<void> getCities()async{
|
|
|
|
List<CityMunicipality> _cities = await LocationUtils.instance.getCities(code: selectedProvince!.code.toString());
|
|
|
|
citymuns = _cities;
|
|
|
|
setState(() {
|
|
|
|
selectedMunicipality = _cities[0];
|
|
|
|
cityCall = false;
|
|
|
|
});
|
|
|
|
}
|
2023-02-23 00:53:14 +00:00
|
|
|
}
|