commit before flutter upgrade

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-02-16 15:10:54 +08:00
parent e7d5e933dd
commit 3a53445ec6
9 changed files with 244 additions and 169 deletions

View File

@ -10,7 +10,9 @@ 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;
import '../../model/location/provinces.dart' as province;
import '../../model/location/city.dart' as city;
import '../../model/location/barangay.dart' as barangay;
part 'profile_event.dart';
part 'profile_state.dart';
@ -38,7 +40,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
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));
List<province.Province> provinces = await LocationUtils.instance.getProvinces(regionCode: event.eligibityCert.examAddress!.cityMunicipality!.province!.region!.code!.toString());
emit(EditEligibilityState(provinces: provinces, eligibityCert: event.eligibityCert,countries: countries,regions: regions,eligibilities: eligibilities));
// }catch(e){
// emit(ProfileErrorState(mesage: e.toString()));
// }

View File

@ -39,7 +39,8 @@ class EditEligibilityState extends ProfileState{
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});
List<province.Province> provinces;
EditEligibilityState({ required this.provinces,required this.eligibityCert, required this.eligibilities, required this.countries, required this.regions});
@override
List<Object> get props => [eligibityCert];
}

View File

@ -5,6 +5,8 @@
import 'package:meta/meta.dart';
import 'dart:convert';
import 'region.dart';
Province provinceFromJson(String str) => Province.fromJson(json.decode(str));
String provinceToJson(Province data) => json.encode(data.toJson());
@ -40,27 +42,3 @@ class Province {
"shortname": shortname,
};
}
class Region {
Region({
required this.code,
required this.description,
required this.psgcCode,
});
final int? code;
final String? description;
final String? psgcCode;
factory Region.fromJson(Map<String, dynamic> json) => Region(
code: json["code"],
description: json["description"],
psgcCode: json["psgc_code"],
);
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"psgc_code": psgcCode,
};
}

View File

@ -36,7 +36,7 @@ class EligibityCert {
examDate: json['exam_date'] == null? null: DateTime.parse(json["exam_date"]),
attachments: null,
eligibility: json['eligibility'] == null?null: Eligibility.fromJson(json["eligibility"]),
examAddress: json['eligibilty'] == null? null: ExamAddress.fromJson(json["exam_address"]),
examAddress: json['exam_address'] == null? null: ExamAddress.fromJson(json["exam_address"]),
validityDate: json["validity_date"],
licenseNumber: json["license_number"],
);

View File

@ -8,7 +8,10 @@ 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 'package:unit2/model/utils/eligibilities_choices.dart';
import '../../../../model/location/country.dart' as c;
import '../../../../model/location/region.dart' as r;
import '../../../../model/location/provinces.dart' as p;
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart';
@ -30,12 +33,22 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
c.Country? selectedCountry;
@override
Widget build(BuildContext context) {
//USERBLOC
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
//LOGGED IN USER STATE
if (state is UserLoggedIn) {
//PROFIILE BLOC
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
//EDIT ELIGIBILITY STATE
if (state is EditEligibilityState) {
String? region = state.eligibityCert.examAddress!
.cityMunicipality!.province!.region!.description;
String? eligibiltyTitle =
state.eligibityCert.eligibility!.title!;
String? province = state.eligibityCert.examAddress!
.cityMunicipality!.province!.description!;
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(
@ -46,20 +59,35 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
FormBuilderTextField(
//ELIGIBILITIES DROPDOWN
FormBuilderDropdown<dynamic>(
initialValue: state.eligibityCert.eligibility,
items: state.eligibilities
.map<DropdownMenuItem<EligibilityList>>(
(EligibilityList eligibility) {
return DropdownMenuItem<EligibilityList>(
value: eligibility,
child: Text(eligibility.title));
}).toList(),
name: "eligibility",
initialValue:
widget.eligibityCert.eligibility!.title!,
decoration: normalTextFieldStyle(
"Eligibility", "Eligibility"),
"Eligibility", eligibiltyTitle)
.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(
@ -73,6 +101,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
const SizedBox(
width: 12,
),
//RATING
Flexible(
flex: 1,
child: FormBuilderTextField(
@ -93,6 +122,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
width: screenWidth,
child: Row(
children: [
//EXAM DATE
Flexible(
flex: 1,
child: DateTimePicker(
@ -110,6 +140,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
const SizedBox(
width: 12,
),
//VALIDITY DATE
Flexible(
flex: 1,
child: DateTimePicker(
@ -141,6 +172,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
const SizedBox(
height: 12,
),
//OVERSEAS ADDRESS SWITCH
FormBuilderSwitch(
initialValue: overseas,
activeColor: second,
@ -156,13 +188,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
const SizedBox(
height: 20,
),
//COUNTRY DROPDOWN
SizedBox(
child: overseas == true
? FormBuilderDropdown<dynamic>(
items: state.countries
.map<DropdownMenuItem<c.Country>>(
(c.Country country) {
return DropdownMenuItem<c.Country>(
value: country,
child: Text(country.name!));
@ -178,39 +211,52 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
)
: Column(
children: [
FormBuilderDropdown(
//REGION DROPDOWN
FormBuilderDropdown<dynamic>(
// initialValue:state.eligibityCert.examAddress!.cityMunicipality!.province!.description!,
decoration: normalTextFieldStyle(
"Region", "Region"),
"Region", region ??
"Region*")
.copyWith(
hintStyle: const TextStyle(
color: Colors.black,
),
labelStyle: const TextStyle(
color: Colors.black)),
name: 'region',
items: [],
initialValue: widget
.eligibityCert
.examAddress
?.cityMunicipality
?.province
?.region
?.description ==
null
? 'region'
: 'region',
items: state.regions.map<
DropdownMenuItem<r.Region>>(
(r.Region region) {
return DropdownMenuItem<r.Region>(
value: region,
child: Text(
region.description!));
}).toList(),
),
const SizedBox(
height: 20,
),
//PROVINCE DROPDOWN
FormBuilderDropdown(
decoration: normalTextFieldStyle(
'Province', "Province"),
name: 'province',
items: [],
initialValue: widget
.eligibityCert
.examAddress
?.cityMunicipality
?.province
?.description ==
null
? 'region'
: 'pprovince'),
items: state.provinces.map<
DropdownMenuItem<
p.Province>>(
(p.Province province) {
return DropdownMenuItem(
value: province,
child: Text(
province.description!));
}).toList(),
decoration: normalTextFieldStyle(
"Province", province)
.copyWith(
hintStyle: const TextStyle(
color: Colors.black,
),
labelStyle: const TextStyle(
color: Colors.black),
)),
const SizedBox(
height: 20,
),
@ -257,6 +303,5 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
return Container();
},
);
;
}
}

View File

@ -3,6 +3,7 @@ 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_progress_hud/flutter_progress_hud.dart';
import 'package:fluttericon/font_awesome_icons.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
@ -32,113 +33,135 @@ class EligibiltyScreen extends StatelessWidget {
body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is EligibilityLoaded) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) {
String title =
state.eligibilities[index].eligibility!.title!;
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: screenWidth,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
return ProgressHUD(
child: BlocConsumer<ProfileBloc, ProfileState>(
listener: (context, state) {
if (state is EditEligibilityState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
// TODO: implement listener
},
builder: (context, state) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is EligibilityLoaded) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) {
String title = state
.eligibilities[index].eligibility!.title!;
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight.w500),
Container(
width: screenWidth,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500),
),
const Divider(),
const SizedBox(
height: 5,
),
Text(
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
style: Theme.of(context)
.textTheme
.titleSmall),
const SizedBox(
height: 3,
),
Text(
" : ${state.eligibilities[index].rating}.",
style: Theme.of(context)
.textTheme
.titleSmall)
]),
),
AppPopupMenu<int>(
offset: const Offset(-10, -10),
elevation: 3,
onSelected: (value) {
if (value == 2) {
confirmAlert(
context,
() => null,
"Delete?",
"Confirm Delete?");
}
if (value == 1) {
final progress =
ProgressHUD.of(context);
progress!
.showWithText("Loading...");
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert:
state.eligibilities[
index]));
}
},
menuItems: [
popMenuItem(
text: "Edit",
value: 1,
icon: Icons.edit),
popMenuItem(
text: "Delete",
value: 2,
icon: Icons.delete),
popMenuItem(
text: "Attachment",
value: 3,
icon: FontAwesome.attach)
],
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
),
const Divider(),
const SizedBox(
height: 5,
),
Text(
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
style: Theme.of(context)
.textTheme
.titleSmall),
const SizedBox(
height: 3,
),
Text(
" : ${state.eligibilities[index].rating}.",
style: Theme.of(context)
.textTheme
.titleSmall)
]),
),
AppPopupMenu<int>(
offset: const Offset(-10, -10),
elevation: 3,
onSelected: (value) {
if (value == 2) {
confirmAlert(context, () => null,
"Delete?", "Confirm Delete?");
}
if (value == 1) {
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert: state
.eligibilities[index]));
}
},
menuItems: [
popMenuItem(
text: "Edit",
value: 1,
icon: Icons.edit),
popMenuItem(
text: "Delete",
value: 2,
icon: Icons.delete),
popMenuItem(
text: "Attachment",
value: 3,
icon: FontAwesome.attach)
],
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
tooltip: "Options",
)
],
),
tooltip: "Options",
),
const SizedBox(
height: 5,
)
],
),
),
const SizedBox(
height: 5,
)
],
);
});
}
if (state is EditEligibilityState) {
return EditEligibilityScreen(
eligibityCert: state.eligibityCert);
}
return Container();
},
);
});
}
if (state is EditEligibilityState) {
return EditEligibilityScreen(
eligibityCert: state.eligibityCert);
}
return Container();
},
);
},
),
);
}
return Container();

View File

@ -230,8 +230,8 @@ class _UniT2LoginState extends State<UniT2Login> {
BlocProvider.of<UserBloc>(context)
.add(UserLogin(
username: "rjvincentlopeplopez",
password: "shesthequ33n",
username: "rodolfobacuinjr",
password: "nav071394",
// username: _formKey
// .currentState!
// .value['username'],

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:unit2/model/location/country.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/model/location/provinces.dart';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
@ -10,13 +11,16 @@ 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',
};
Future<List<Country>>getCountries()async{
List<Country> countries=[];
String path = Url.instance.getCounties();
// try{
http.Response response = await Request.instance.getRequest(path: path, param: {},headers: headers);
if(response.statusCode == 200){
@ -39,9 +43,7 @@ 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){
@ -58,4 +60,24 @@ Future<List<Region>>getRegions()async{
// }
return regions;
}
Future<List<Province>>getProvinces({required String regionCode})async{
List<Province> provinces = [];
String path = Url.instance.getProvinces()+regionCode;
try{
http.Response response = await Request.instance.getRequest(path: path,param:{},headers: headers);
Map data = jsonDecode(response.body);
if(data['data'] != null){
data['data'].forEach((var province){
Province newProvince = Province.fromJson(province);
provinces.add(newProvince);
});
}
}catch(e){
throw(e.toString());
}
return provinces;
}
}

View File

@ -26,4 +26,7 @@ String eligibilities(){
String getRegions(){
return "/api/web_app/location/region/";
}
String getProvinces(){
return "api/web_app/location/province/";
}
}