add location utilities and profile utilities services

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-02-15 16:48:34 +08:00
parent 4418107f21
commit e7d5e933dd
13 changed files with 418 additions and 253 deletions

View File

@ -4,7 +4,12 @@ import 'package:unit2/model/profile/basic_info.dart';
import 'package:unit2/model/profile/basic_information/primary-information.dart';
import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/model/utils/eligibilities_choices.dart';
import 'package:unit2/sevices/profile/profile_service.dart';
import 'package:unit2/utils/location_utilities.dart';
import 'package:unit2/utils/profile_utilities.dart';
import '../../model/location/country.dart' as country;
import '../../model/location/region.dart' as region;
part 'profile_event.dart';
part 'profile_state.dart';
@ -28,8 +33,16 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
emit(ProfileLoading());
emit(EligibilityLoaded(eligibilities: event.eligibilities));
});
on<EditEligibility>((event, emit) {
emit(EditEligibilityState(eligibityCert: event.eligibityCert));
on<EditEligibility>((event, emit) async{
// try{
List<country.Country> countries = await LocationUtils.instance.getCountries();
List<region.Region> regions = await LocationUtils.instance.getRegions();
List<EligibilityList> eligibilities = await ProfileUtilities.instance.getEligibilities();
emit(EditEligibilityState(eligibityCert: event.eligibityCert,countries: countries,regions: regions,eligibilities: eligibilities));
// }catch(e){
// emit(ProfileErrorState(mesage: e.toString()));
// }
});
}
}

View File

@ -36,7 +36,10 @@ class EligibilityLoaded extends ProfileState{
class EditEligibilityState extends ProfileState{
final EligibityCert eligibityCert;
const EditEligibilityState({required this.eligibityCert});
final List<EligibilityList> eligibilities;
final List<country.Country> countries;
final List<region.Region> regions;
const EditEligibilityState({required this.eligibityCert, required this.eligibilities, required this.countries, required this.regions});
@override
List<Object> get props => [eligibityCert];
}

View File

@ -16,20 +16,20 @@ class Barangay {
required this.cityMunicipality,
});
final String code;
final String description;
final CityMunicipality cityMunicipality;
final String? code;
final String? description;
final CityMunicipality? cityMunicipality;
factory Barangay.fromJson(Map<String, dynamic> json) => Barangay(
code: json["code"],
description: json["description"],
cityMunicipality: CityMunicipality.fromJson(json["city_municipality"]),
cityMunicipality: json['city_municipality'] == null? null: CityMunicipality.fromJson(json["city_municipality"]),
);
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"city_municipality": cityMunicipality.toJson(),
"city_municipality": cityMunicipality!.toJson(),
};
}
@ -42,16 +42,16 @@ class CityMunicipality {
required this.zipcode,
});
final String code;
final String description;
final Province province;
final String psgcCode;
final String zipcode;
final String? code;
final String? description;
final Province? province;
final String? psgcCode;
final String? zipcode;
factory CityMunicipality.fromJson(Map<String, dynamic> json) => CityMunicipality(
code: json["code"],
description: json["description"],
province: Province.fromJson(json["province"]),
province: json['province'] == null? null:Province.fromJson(json["province"]),
psgcCode: json["psgc_code"],
zipcode: json["zipcode"],
);
@ -59,7 +59,7 @@ class CityMunicipality {
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"province": province.toJson(),
"province": province!.toJson(),
"psgc_code": psgcCode,
"zipcode": zipcode,
};
@ -74,16 +74,16 @@ class Province {
required this.shortname,
});
final String code;
final String description;
final Region region;
final String psgcCode;
final String shortname;
final String? code;
final String? description;
final Region? region;
final String? psgcCode;
final String? shortname;
factory Province.fromJson(Map<String, dynamic> json) => Province(
code: json["code"],
description: json["description"],
region: Region.fromJson(json["region"]),
region: json['region'] == null? null: Region.fromJson(json["region"]),
psgcCode: json["psgc_code"],
shortname: json["shortname"],
);
@ -91,7 +91,7 @@ class Province {
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"region": region.toJson(),
"region": region!.toJson(),
"psgc_code": psgcCode,
"shortname": shortname,
};
@ -104,9 +104,9 @@ class Region {
required this.psgcCode,
});
final int code;
final String description;
final String psgcCode;
final int? code;
final String? description;
final String? psgcCode;
factory Region.fromJson(Map<String, dynamic> json) => Region(
code: json["code"],

View File

@ -18,16 +18,16 @@ class City {
required this.zipcode,
});
final String code;
final String description;
final Province province;
final String psgcCode;
final String zipcode;
final String? code;
final String? description;
final Province? province;
final String? psgcCode;
final String? zipcode;
factory City.fromJson(Map<String, dynamic> json) => City(
code: json["code"],
description: json["description"],
province: Province.fromJson(json["province"]),
province: json['province'] == null? null : Province.fromJson(json["province"]),
psgcCode: json["psgc_code"],
zipcode: json["zipcode"],
);
@ -35,7 +35,7 @@ class City {
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"province": province.toJson(),
"province": province!.toJson(),
"psgc_code": psgcCode,
"zipcode": zipcode,
};
@ -50,16 +50,16 @@ class Province {
required this.shortname,
});
final String code;
final String description;
final Region region;
final String psgcCode;
final String shortname;
final String? code;
final String? description;
final Region? region;
final String? psgcCode;
final String? shortname;
factory Province.fromJson(Map<String, dynamic> json) => Province(
code: json["code"],
description: json["description"],
region: Region.fromJson(json["region"]),
region: json['region'] == null ? null : Region.fromJson(json["region"]),
psgcCode: json["psgc_code"],
shortname: json["shortname"],
);
@ -67,7 +67,7 @@ class Province {
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"region": region.toJson(),
"region": region!.toJson(),
"psgc_code": psgcCode,
"shortname": shortname,
};
@ -80,9 +80,9 @@ class Region {
required this.psgcCode,
});
final int code;
final String description;
final String psgcCode;
final int? code;
final String? description;
final String? psgcCode;
factory Region.fromJson(Map<String, dynamic> json) => Region(
code: json["code"],

View File

@ -16,14 +16,14 @@ class Country {
required this.code,
});
final int id;
final String name;
final String code;
final int? id;
final String? name;
final String? code;
factory Country.fromJson(Map<String, dynamic> json) => Country(
id: json["id"],
name: json["name"],
code: json["code"],
code: json["code"].toString(),
);
Map<String, dynamic> toJson() => {

View File

@ -18,16 +18,16 @@ class Province {
required this.shortname,
});
final String code;
final String description;
final Region region;
final String psgcCode;
final String shortname;
final String? code;
final String? description;
final Region? region;
final String? psgcCode;
final String? shortname;
factory Province.fromJson(Map<String, dynamic> json) => Province(
code: json["code"],
description: json["description"],
region: Region.fromJson(json["region"]),
region: json['region'] == null? null: Region.fromJson(json["region"]),
psgcCode: json["psgc_code"],
shortname: json["shortname"],
);
@ -35,7 +35,7 @@ class Province {
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"region": region.toJson(),
"region": region!.toJson(),
"psgc_code": psgcCode,
"shortname": shortname,
};
@ -48,9 +48,9 @@ class Region {
required this.psgcCode,
});
final int code;
final String description;
final String psgcCode;
final int? code;
final String? description;
final String? psgcCode;
factory Region.fromJson(Map<String, dynamic> json) => Region(
code: json["code"],

View File

@ -16,9 +16,9 @@ class Region {
required this.psgcCode,
});
final int code;
final String description;
final String psgcCode;
final int? code;
final String? description;
final String? psgcCode;
factory Region.fromJson(Map<String, dynamic> json) => Region(
code: json["code"],

View File

@ -5,12 +5,12 @@
import 'package:meta/meta.dart';
import 'dart:convert';
Eligibilities eligibilitiesFromJson(String str) => Eligibilities.fromJson(json.decode(str));
EligibilityList eligibilitiesFromJson(String str) => EligibilityList.fromJson(json.decode(str));
String eligibilitiesToJson(Eligibilities data) => json.encode(data.toJson());
String eligibilitiesToJson(EligibilityList data) => json.encode(data.toJson());
class Eligibilities {
Eligibilities({
class EligibilityList {
EligibilityList({
required this.id,
required this.title,
required this.type,
@ -20,7 +20,7 @@ class Eligibilities {
final String title;
final String type;
factory Eligibilities.fromJson(Map<String, dynamic> json) => Eligibilities(
factory EligibilityList.fromJson(Map<String, dynamic> json) => EligibilityList(
id: json["id"],
title: json["title"],
type: json["type"],

View File

@ -2,10 +2,13 @@ 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:intl/intl.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/eligibility.dart';
import '../../../../model/location/country.dart' as c;
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart';
@ -14,7 +17,7 @@ import '../../../../utils/text_container.dart';
class EditEligibilityScreen extends StatefulWidget {
final EligibityCert eligibityCert;
const EditEligibilityScreen({super.key,required this.eligibityCert});
const EditEligibilityScreen({super.key, required this.eligibityCert});
@override
State<EditEligibilityScreen> createState() => _EditEligibilityScreenState();
@ -22,13 +25,21 @@ class EditEligibilityScreen extends StatefulWidget {
class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
final formKey = GlobalKey<FormBuilderState>();
bool overseas =false;
bool overseas = false;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
c.Country? selectedCountry;
@override
Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is EditEligibilityState) {
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 25, horizontal: 18),
padding: const EdgeInsets.symmetric(
vertical: 25, horizontal: 18),
child: FormBuilder(
key: formKey,
child: Column(
@ -37,9 +48,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
children: [
FormBuilderTextField(
name: "eligibility",
initialValue: widget.eligibityCert.eligibility!.title!,
decoration:
normalTextFieldStyle("Eligibility", "Eligibility"),
initialValue:
widget.eligibityCert.eligibility!.title!,
decoration: normalTextFieldStyle(
"Eligibility", "Eligibility"),
),
const SizedBox(
height: 20,
@ -65,10 +77,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
flex: 1,
child: FormBuilderTextField(
name: 'rating',
initialValue:
widget.eligibityCert.rating.toString(),
decoration:
normalTextFieldStyle('rating', 'rating'),
initialValue: widget.eligibityCert.rating
.toString(),
decoration: normalTextFieldStyle(
'rating', 'rating'),
),
),
],
@ -88,8 +100,9 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
lastDate: DateTime(2100),
decoration: normalTextFieldStyle(
"Exam date", "Exam date"),
initialValue:
widget.eligibityCert.examDate == null
initialValue: widget
.eligibityCert.examDate ==
null
? ''
: dteFormat2.format(
widget.eligibityCert.examDate!),
@ -105,10 +118,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
decoration: normalTextFieldStyle(
"Validity date", "Validity date"),
initialValue:
widget.eligibityCert.validityDate == null
widget.eligibityCert.validityDate ==
null
? ''
: dteFormat2.format(
widget.eligibityCert.validityDate!),
: dteFormat2.format(widget
.eligibityCert.validityDate!),
),
),
],
@ -144,10 +158,23 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
),
SizedBox(
child: overseas == true
? FormBuilderTextField(
? FormBuilderDropdown<dynamic>(
items: state.countries
.map<DropdownMenuItem<c.Country>>(
(c.Country country) {
return DropdownMenuItem<c.Country>(
value: country,
child: Text(country.name!));
}).toList(),
name: 'country',
decoration: normalTextFieldStyle(
"Country", "Country"),
onChanged: (value) {
setState(() {
selectedCountry = value;
});
},
)
: Column(
children: [
@ -215,11 +242,21 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
onPressed: () {},
child: const Text(submit)),
),
const SizedBox(height: 20,),
const SizedBox(
height: 20,
),
]),
),
),
);;
);
}
return Container();
},
);
}
return Container();
},
);
;
}
}

View File

@ -18,6 +18,8 @@ import 'package:unit2/widgets/empty_data.dart';
import '../../../utils/alerts.dart';
class EligibiltyScreen extends StatelessWidget {
const EligibiltyScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(

View File

@ -0,0 +1,61 @@
import 'dart:convert';
import 'package:unit2/model/location/country.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import '../model/location/region.dart';
class LocationUtils {
static final LocationUtils _instance = LocationUtils();
static LocationUtils get instance => _instance;
Future<List<Country>>getCountries()async{
List<Country> countries=[];
String path = Url.instance.getCounties();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
// try{
http.Response response = await Request.instance.getRequest(path: path, param: {},headers: headers);
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
if(data['data'] != null){
data['data'].forEach((var country){
Country newCOuntry = Country.fromJson(country);
countries.add(newCOuntry);
});
}
}
// }catch(e){
// throw(e.toString());
// }
return countries;
}
Future<List<Region>>getRegions()async{
List<Region> regions=[];
String path = Url.instance.getRegions();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
// try{
http.Response response = await Request.instance.getRequest(path: path, param: {},headers: headers);
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
if(data['data'] != null){
data['data'].forEach((var region){
Region newRegion = Region.fromJson(region);
regions.add(newRegion);
});
}
}
// }catch(e){
// throw(e.toString());
// }
return regions;
}
}

View File

@ -0,0 +1,38 @@
import 'dart:convert';
import 'package:unit2/model/location/country.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/model/location/region.dart';
import 'package:unit2/model/utils/eligibilities_choices.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
class ProfileUtilities {
static final ProfileUtilities _instance = ProfileUtilities();
static ProfileUtilities get instance => _instance;
Future<List<EligibilityList>>getEligibilities()async{
List<EligibilityList> eligibilities=[];
String path = Url.instance.eligibilities();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
// try{
http.Response response = await Request.instance.getRequest(path: path, param: {},headers: headers);
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
if(data['data'] != null){
data['data'].forEach((var eligibility){
EligibilityList newEligibilities = EligibilityList.fromJson(eligibility);
eligibilities.add(newEligibilities);
});
}
}
// }catch(e){
// throw(e.toString());
// }
return eligibilities;
}
}

View File

@ -15,4 +15,15 @@ class Url {
String profileInformation(){
return '/api/jobnet_app/profile/pds/';
}
String eligibilities(){
return "/api/jobnet_app/eligibilities/";
}
// location utils path
String getCounties(){
return "/api/jobnet_app/countries/";
}
String getRegions(){
return "/api/web_app/location/region/";
}
}