Implemented crud API for skills and hobbies screen

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-30 14:22:16 +08:00
parent 36bec39fb6
commit e686cd1f9f
10 changed files with 577 additions and 61 deletions

View File

@ -10,15 +10,106 @@ part 'hoobies_state.dart';
class HoobiesBloc extends Bloc<HobbiesEvent, HobbiesState> { class HoobiesBloc extends Bloc<HobbiesEvent, HobbiesState> {
HoobiesBloc() : super(HoobiesInitial()) { HoobiesBloc() : super(HoobiesInitial()) {
List<SkillsHobbies> skillsAndHobbies = []; List<SkillsHobbies> skillsAndHobbies = [];
on<GetSkillsHobbies>((event, emit)async { List<SkillsHobbies> allSkillsAndHobbies = [];
emit(HobbiesLoadingState()); List<String> mySkillsAndHobbies = [];
try{ on<GetSkillsHobbies>((event, emit) async {
List<SkillsHobbies> hobbies = await SkillsHobbiesServices.instance.getSkillsHobbies(event.profileId, event.token); emit(HobbiesLoadingState());
skillsAndHobbies = hobbies; try {
emit(HobbiesLoadedState(skillsAndHobbies: skillsAndHobbies)); List<SkillsHobbies> hobbies = await SkillsHobbiesServices.instance
}catch(e){ .getSkillsHobbies(event.profileId, event.token);
emit(HobbiesErrorState(message: e.toString())); skillsAndHobbies = hobbies;
} emit(HobbiesLoadedState(skillsAndHobbies: skillsAndHobbies));
} catch (e) {
emit(HobbiesErrorState(message: e.toString()));
}
});
on<LoadHobbiesSkills>((event,emit){
skillsAndHobbies = event.skillsHobbies;
emit(HobbiesLoadedState(skillsAndHobbies: skillsAndHobbies));
});
////SHOW ADD FORM
on<ShowHobbySkillAddForm>((event, emit) async {
emit(HobbiesLoadingState());
try {
if (allSkillsAndHobbies.isEmpty) {
allSkillsAndHobbies =
await SkillsHobbiesServices.instance.getAllSkillsHobbies();
}
for (var element in skillsAndHobbies) {
mySkillsAndHobbies.add(element.name!);
}
allSkillsAndHobbies.sort((a, b) => a.name!.compareTo(b.name!));
emit(AddHobbySkillState(
mySkillsAndHobbiesString: mySkillsAndHobbies,
allSkillsAndHobbies: allSkillsAndHobbies,
mySkillsAndHobbiesObject: skillsAndHobbies));
} catch (e) {
emit(HobbiesErrorState(message: e.toString()));
}
});
////GET ADDED SKILLS HOBBIES
on<GetAddedHobbiesSkills>((event, emit) {
emit(HobbiesLoadingState());
List<String> added = event.addedHobbiesSkills.split(",");
for (var element in added) {
if (element.isNotEmpty) {
SkillsHobbies newSkillsHobbies =
SkillsHobbies(id: null, name: element.toUpperCase());
skillsAndHobbies.add(newSkillsHobbies);
allSkillsAndHobbies.add(newSkillsHobbies);
}
}
for (var element in skillsAndHobbies) {
mySkillsAndHobbies.add(element.name!);
}
allSkillsAndHobbies.sort((a, b) => a.name!.compareTo(b.name!));
emit(AddHobbySkillState(
mySkillsAndHobbiesString: mySkillsAndHobbies,
allSkillsAndHobbies: allSkillsAndHobbies,
mySkillsAndHobbiesObject: skillsAndHobbies));
});
////SHOW ADD MODAL
on<ShowAddModal>((event, emit) {
emit(ShowAddModalState());
});
//// ADD
on<AddHobbyAndSkills>((event, emit) async {
emit(HobbiesLoadingState());
Map<dynamic, dynamic> response = await SkillsHobbiesServices.instance.add(
skillsHobbies: event.skillsHobbies,
profileId: event.profileId,
token: event.token);
List<SkillsHobbies> newSkillsHobbies = [];
if (response['success']) {
if (response['data']['skill_hobby'] != null) {
for (var element in response['data']['skill_hobby']) {
newSkillsHobbies.add(SkillsHobbies.fromJson(element));
}
}
skillsAndHobbies = newSkillsHobbies;
emit(HobbiesAndSkillsAddedState(
mySkillsAndHobbies: skillsAndHobbies, status: response));
} else {
emit(HobbiesAndSkillsAddedState(
mySkillsAndHobbies: skillsAndHobbies, status: response));
}
});
////DELETE
on<DeleteSkillHobbies>((event,emit)async{
emit(HobbiesLoadingState());
try{
bool success = await SkillsHobbiesServices.instance.delete(profileId: event.profileId, token: event.token, skillsHobbies: event.skillsHobbies);
if(success){
skillsAndHobbies.removeWhere((element) => element.id == event.skillsHobbies[0].id);
emit(HobbiesAndSkillsDeletedState(skillsHobbies: skillsAndHobbies, success: success));
}else{
emit(HobbiesAndSkillsDeletedState(skillsHobbies: skillsAndHobbies, success: success));
}
}catch(e){
emit (HobbiesErrorState(message: e.toString()));
}
}); });
} }
} }

View File

@ -13,4 +13,40 @@ class GetSkillsHobbies extends HobbiesEvent{
const GetSkillsHobbies({required this.profileId, required this.token}); const GetSkillsHobbies({required this.profileId, required this.token});
@override @override
List<Object> get props => [profileId,token]; List<Object> get props => [profileId,token];
}
class ShowHobbySkillAddForm extends HobbiesEvent{
final List<SkillsHobbies> mySkillsAndHobbies;
const ShowHobbySkillAddForm({required this.mySkillsAndHobbies});
}
class AddHobbyAndSkills extends HobbiesEvent{
final int profileId;
final String token;
final List<SkillsHobbies> skillsHobbies;
const AddHobbyAndSkills({required this.profileId,required this.token, required this.skillsHobbies});
@override
List<Object> get props => [profileId,token];
}
class GetAddedHobbiesSkills extends HobbiesEvent{
final String addedHobbiesSkills;
const GetAddedHobbiesSkills({required this.addedHobbiesSkills});
@override
List<Object> get props => [addedHobbiesSkills];
}
class ShowAddModal extends HobbiesEvent{
}
class LoadHobbiesSkills extends HobbiesEvent{
final List<SkillsHobbies> skillsHobbies;
const LoadHobbiesSkills({required this.skillsHobbies});
}
class DeleteSkillHobbies extends HobbiesEvent{
final int profileId;
final String token;
final List<SkillsHobbies> skillsHobbies;
const DeleteSkillHobbies({required this.profileId, required this.skillsHobbies, required this.token});
} }

View File

@ -23,7 +23,33 @@ class HobbiesErrorState extends HobbiesState{
List<Object> get props => [message]; List<Object> get props => [message];
} }
class AddHobbySkillState extends HobbiesState{
final List<String> mySkillsAndHobbiesString;
final List<SkillsHobbies> allSkillsAndHobbies;
final List<SkillsHobbies> mySkillsAndHobbiesObject;
const AddHobbySkillState({required this.mySkillsAndHobbiesString,required this.allSkillsAndHobbies,required this.mySkillsAndHobbiesObject});
@override
List<Object> get props => [mySkillsAndHobbiesString,allSkillsAndHobbies,mySkillsAndHobbiesObject];
}
class HobbiesLoadingState extends HobbiesState{ class HobbiesLoadingState extends HobbiesState{
} }
class ShowAddModalState extends HobbiesState{
}
class HobbiesAndSkillsAddedState extends HobbiesState{
final List<SkillsHobbies> mySkillsAndHobbies;
final Map<dynamic,dynamic> status;
const HobbiesAndSkillsAddedState({required this.mySkillsAndHobbies, required this.status});
@override
List<Object> get props => [mySkillsAndHobbies,status];
}
class HobbiesAndSkillsDeletedState extends HobbiesState{
final bool success;
final List<SkillsHobbies> skillsHobbies;
const HobbiesAndSkillsDeletedState({required this.skillsHobbies,required this.success});
}

View File

@ -4,9 +4,12 @@ import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:simple_chips_input/simple_chips_input.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart'; import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart';
import 'package:unit2/screens/profile/components/other_information/skills_hobbies/add_modal.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart'; import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
@ -14,19 +17,35 @@ import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';
import '../../../../bloc/profile/other_information/hobbies/hoobies_bloc.dart'; import '../../../../bloc/profile/other_information/hobbies/hoobies_bloc.dart';
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../utils/alerts.dart';
class SkillHobbiesScreen extends StatelessWidget { class SkillHobbiesScreen extends StatelessWidget {
const SkillHobbiesScreen({super.key}); const SkillHobbiesScreen({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String token;
int profileId;
final bloc = BlocProvider.of<HoobiesBloc>(context);
List<SkillsHobbies>? mySkillsAndHobbies;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text(skillAndHobbiesTitle), title: const Text(skillAndHobbiesTitle),
backgroundColor: primary, backgroundColor: primary,
centerTitle: true, centerTitle: true,
actions: [AddLeading(onPressed: () {})], actions: context.watch<HoobiesBloc>().state is AddHobbySkillState
), ? [
AddLeading(onPressed: () {
context.read<HoobiesBloc>().add(ShowAddModal());
})
]
: [
AddLeading(onPressed: () {
context.read<HoobiesBloc>().add(ShowHobbySkillAddForm(
mySkillsAndHobbies: mySkillsAndHobbies!));
})
]),
body: ProgressHUD( body: ProgressHUD(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87, backgroundColor: Colors.black87,
@ -34,6 +53,8 @@ class SkillHobbiesScreen extends StatelessWidget {
child: BlocBuilder<UserBloc, UserState>( child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token!;
profileId = state.userData!.user!.login!.user!.profileId!;
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) { builder: (context, state) {
if (state is ProfileLoaded) { if (state is ProfileLoaded) {
@ -42,16 +63,65 @@ class SkillHobbiesScreen extends StatelessWidget {
if (state is HobbiesLoadingState) { if (state is HobbiesLoadingState) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait..."); progress!.showWithText("Please wait...");
}if(state is HobbiesLoadedState || state is HobbiesErrorState){ }
final progress = ProgressHUD.of(context); if (state is HobbiesLoadedState ||
progress!.dismiss(); state is HobbiesErrorState ||
state is AddHobbySkillState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
////ADDED STATE
if (state is HobbiesAndSkillsAddedState) {
if (state.status['success']) {
successAlert(context, "Adding Successfull!",
state.status['message'], () {
Navigator.of(context).pop();
context.read<HoobiesBloc>().add(
LoadHobbiesSkills(
skillsHobbies:
state.mySkillsAndHobbies));
});
} else {
errorAlert(context, "Adding Failed",
"Something went wrong. Please try again.",
() {
Navigator.of(context).pop();
context.read<HoobiesBloc>().add(
LoadHobbiesSkills(
skillsHobbies:
state.mySkillsAndHobbies));
});
}
}
//// DELETED STATE
if (state is HobbiesAndSkillsDeletedState) {
if (state.success) {
successAlert(context, "Delete Successfull!",
"Skill/Hobby Deleted Successfully", () {
Navigator.of(context).pop();
context.read<HoobiesBloc>().add(
LoadHobbiesSkills(
skillsHobbies: state.skillsHobbies));
});
} else {
errorAlert(context, "Deletion Failed",
"Something went wrong. Please try again.",
() {
Navigator.of(context).pop();
context.read<HoobiesBloc>().add(
LoadHobbiesSkills(
skillsHobbies: state.skillsHobbies));
});
}
} }
}, },
builder: (context, state) { builder: (context, state) {
if (state is HobbiesLoadedState) { if (state is HobbiesLoadedState) {
mySkillsAndHobbies = state.skillsAndHobbies;
if (state.skillsAndHobbies.isNotEmpty) { if (state.skillsAndHobbies.isNotEmpty) {
return Padding( return Padding(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(12),
child: Wrap( child: Wrap(
spacing: 8, spacing: 8,
runSpacing: 8, runSpacing: 8,
@ -61,17 +131,51 @@ class SkillHobbiesScreen extends StatelessWidget {
crossAxisAlignment: crossAxisAlignment:
WrapCrossAlignment.start, WrapCrossAlignment.start,
direction: Axis.horizontal, direction: Axis.horizontal,
children: children: state.skillsAndHobbies
state.skillsAndHobbies.map((SkillsHobbies sh) { .map((SkillsHobbies sh) {
return FittedBox( return Wrap(
child: Row( children: [
children: [ Container(
Text(sh.name!), padding: const EdgeInsets.only(
IconButton( left: 6),
onPressed: () {},
icon: const Icon(Icons.close)), child: Wrap(
], clipBehavior: Clip.antiAlias,
), alignment: WrapAlignment.center,
crossAxisAlignment:
WrapCrossAlignment.center,
runAlignment: WrapAlignment.center,
children: [
Text(
sh.name!,
style: Theme.of(context)
.textTheme
.labelMedium,
),
IconButton(
onPressed: () {
confirmAlert(
context,
() => context.read<HoobiesBloc>().add(DeleteSkillHobbies(
profileId:
profileId,
skillsHobbies: [
sh
],
token:
token)),
"Delete",
"Confirm Delete");
},
icon:const Icon(
Icons.delete,
size: 16,
color: second,
))
]),
)
],
); );
}).toList()), }).toList()),
); );
@ -81,6 +185,15 @@ class SkillHobbiesScreen extends StatelessWidget {
"You don't have any Skills and Hobbies added. Please click + to add"); "You don't have any Skills and Hobbies added. Please click + to add");
} }
} }
if (state is AddHobbySkillState) {
return AddHobbiesAndSkillsScreen(
profileId: profileId,
token: token,
);
}
if (state is ShowAddModalState) {
return AddModal(bloc: bloc);
}
return Container(); return Container();
}, },
); );
@ -95,3 +208,84 @@ class SkillHobbiesScreen extends StatelessWidget {
)); ));
} }
} }
class AddModal extends StatefulWidget {
final HoobiesBloc bloc;
const AddModal({super.key, required this.bloc});
@override
State<AddModal> createState() => _AddModalState();
}
String output = '';
String? deletedChip, deletedChipIndex;
final keySimpleChipsInput = GlobalKey<FormState>();
final FocusNode focusNode = FocusNode();
class _AddModalState extends State<AddModal> {
@override
Widget build(BuildContext context) {
return BlocBuilder<HoobiesBloc, HobbiesState>(
builder: (context, state) {
return AlertDialog(
title: const Text("Add Skills and Hobbies"),
content: SimpleChipsInput(
separatorCharacter: ",",
createCharacter: ",",
focusNode: focusNode,
validateInput: true,
autoFocus: true,
formKey: keySimpleChipsInput,
onSubmitted: (p0) {
setState(() {
output = p0;
});
},
onChipDeleted: (p0, p1) {
setState(() {
deletedChip = p0;
deletedChipIndex = p1.toString();
});
},
onSaved: ((p0) {
setState(() {
output = p0;
});
}),
chipTextStyle: const TextStyle(
color: Colors.white,
fontSize: 16,
),
deleteIcon: const Icon(
Icons.delete,
size: 14.0,
color: second,
),
widgetContainerDecoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.0),
border: Border.all(color: Colors.blue[100]!),
),
chipContainerDecoration: BoxDecoration(
color: second,
borderRadius: BorderRadius.circular(50),
),
placeChipsSectionAbove: false,
),
actions: [
ElevatedButton(
onPressed: () {
keySimpleChipsInput.currentState!.save();
context
.read<HoobiesBloc>()
.add(GetAddedHobbiesSkills(addedHobbiesSkills: output));
},
style: mainBtnStyle(primary, Colors.transparent, second),
child: const Text(submit),
)
],
);
},
);
}
}

View File

@ -0,0 +1,73 @@
import 'dart:math';
import 'package:filter_list/filter_list.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:unit2/bloc/profile/other_information/hobbies/hoobies_bloc.dart';
import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart';
import 'package:unit2/theme-data.dart/colors.dart';
class AddHobbiesAndSkillsScreen extends StatefulWidget {
final int profileId;
final String token;
const AddHobbiesAndSkillsScreen({super.key,required this.profileId, required this.token});
@override
State<AddHobbiesAndSkillsScreen> createState() =>
_AddHobbiesAndSkillsScreenState();
}
class _AddHobbiesAndSkillsScreenState extends State<AddHobbiesAndSkillsScreen> {
@override
Widget build(BuildContext context) {
return BlocBuilder<HoobiesBloc, HobbiesState>(
builder: (context, state) {
if(state is AddHobbySkillState){
final List<SkillsHobbies> selectedList= state.mySkillsAndHobbiesString.map((var element){
return state.allSkillsAndHobbies.firstWhere((var data) => data.name == element );
}).toList();
return FilterListWidget<SkillsHobbies>(
themeData: FilterListThemeData(context,choiceChipTheme: const ChoiceChipThemeData(selectedBackgroundColor: primary)),
hideSelectedTextCount: true,
listData: state.allSkillsAndHobbies,
selectedListData: selectedList,
onApplyButtonClick: (list) {
// Navigator.pop(context, list);
context.read<HoobiesBloc>().add(AddHobbyAndSkills(profileId: widget.profileId, token: widget.token, skillsHobbies: selectedList));
},
choiceChipLabel: (item) {
return item!.name;
},
// choiceChipBuilder: (context, item, isSelected) {
// return Container(
// padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
// margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// decoration: BoxDecoration(
// border: Border.all(
// color: isSelected! ? Colors.blue[300]! : Colors.grey[300]!,
// )),
// child: Text(item.name),
// );
// },
validateSelectedItem: (list, val) {
/// identify if item is selected or not
return list!.contains(val);
},
onItemSearch: (user, query) {
/// When search query change in search bar then this method will be called
///
/// Check if items contains query
return user.name!.toLowerCase().contains(query.toLowerCase());
},
);
}
return Container();
},
);
}
}

View File

@ -43,7 +43,7 @@ class WorkHistoryService {
} }
//delete workhistory ////delete workhistory
Future<bool> delete( Future<bool> delete(
{required int profileId, {required int profileId,
required String token, required String token,
@ -84,7 +84,7 @@ class WorkHistoryService {
} }
//edit work history ////edit work history
Future<Map<dynamic,dynamic>> update({required WorkHistory oldWorkHistory, required WorkHistory newWorkHistory, required String token, required String profileId})async{ Future<Map<dynamic,dynamic>> update({required WorkHistory oldWorkHistory, required WorkHistory newWorkHistory, required String token, required String profileId})async{
Map<dynamic, dynamic>? statusResponse={}; Map<dynamic, dynamic>? statusResponse={};
String authtoken = "Token $token"; String authtoken = "Token $token";
@ -111,7 +111,7 @@ class WorkHistoryService {
"_oldAgencyId":oldWorkHistory.agency!.id, "_oldAgencyId":oldWorkHistory.agency!.id,
"oldFromDate":oldWorkHistory.fromDate?.toString(), "oldFromDate":oldWorkHistory.fromDate?.toString(),
}; };
// try{ try{
http.Response response = await Request.instance.putRequest(path: path, headers: headers, body: body, param: {}); http.Response response = await Request.instance.putRequest(path: path, headers: headers, body: body, param: {});
if(response.statusCode == 200 ){ if(response.statusCode == 200 ){
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
@ -120,12 +120,12 @@ class WorkHistoryService {
statusResponse.addAll({'success':false}); statusResponse.addAll({'success':false});
} }
return statusResponse; return statusResponse;
// }catch(e){ }catch(e){
// throw e.toString(); throw e.toString();
// } }
} }
//Add work history ////Add work history
Future<Map<dynamic, dynamic>>add({required WorkHistory workHistory, required String token, required int profileId , required bool isPrivate})async{ Future<Map<dynamic, dynamic>>add({required WorkHistory workHistory, required String token, required int profileId , required bool isPrivate})async{
String authtoken = "Token $token"; String authtoken = "Token $token";
String path = '${Url.instance.workhistory()}$profileId/'; String path = '${Url.instance.workhistory()}$profileId/';

View File

@ -1,5 +1,3 @@
import 'dart:convert'; import 'dart:convert';
import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/request.dart';
@ -7,34 +5,120 @@ import 'package:unit2/utils/request.dart';
import '../model/profile/other_information/skills_and_hobbies.dart'; import '../model/profile/other_information/skills_and_hobbies.dart';
import '../utils/urls.dart'; import '../utils/urls.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
class SkillsHobbiesServices{
class SkillsHobbiesServices {
static final SkillsHobbiesServices _instance = SkillsHobbiesServices(); static final SkillsHobbiesServices _instance = SkillsHobbiesServices();
static SkillsHobbiesServices get instance => _instance; static SkillsHobbiesServices get instance => _instance;
////GET
Future<List<SkillsHobbies>> getSkillsHobbies(int profileId, String token)async{ Future<List<SkillsHobbies>> getSkillsHobbies(
int profileId, String token) async {
List<SkillsHobbies> skillsAndHobbies = []; List<SkillsHobbies> skillsAndHobbies = [];
String authToken = "Token $token"; String authToken = "Token $token";
String path = "${Url.instance.getSkillsHobbies()}$profileId/"; String path = "${Url.instance.skillsHobbies()}$profileId/";
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authToken 'Authorization': authToken
}; };
try{ try {
http.Response response = await Request.instance.getRequest(path: path,param: {},headers: headers); http.Response response = await Request.instance
if(response.statusCode == 200){ .getRequest(path: path, param: {}, headers: headers);
Map data = jsonDecode(response.body); if (response.statusCode == 200) {
if(data['data']['skill_hobby'] != null){ Map data = jsonDecode(response.body);
data['data']['skill_hobby'].forEach((var hobby){ if (data['data']['skill_hobby'] != null) {
SkillsHobbies skillsHobby = SkillsHobbies.fromJson(hobby); data['data']['skill_hobby'].forEach((var hobby) {
skillsAndHobbies.add(skillsHobby); SkillsHobbies skillsHobby = SkillsHobbies.fromJson(hobby);
}); skillsAndHobbies.add(skillsHobby);
});
}
} }
} catch (e) {
throw e.toString();
} }
}catch(e){ return skillsAndHobbies;
throw e.toString();
} }
return skillsAndHobbies;
////ADD
Future<Map<dynamic, dynamic>> add(
{required List<SkillsHobbies> skillsHobbies,
required int profileId,
required String token}) async {
String authToken = "Token $token";
String path = "${Url.instance.skillsHobbies()}$profileId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authToken
};
Map body = {"skill_hobby": skillsHobbies};
Map<dynamic, dynamic> statusResponse = {};
try {
http.Response response = await Request.instance
.postRequest(path: path, param: {}, headers: headers, body: body);
if (response.statusCode == 201) {
Map data = jsonDecode(response.body);
statusResponse = data;
} else {
statusResponse.addAll({'success': false});
}
} catch (e) {
throw e.toString();
}
return statusResponse;
}
Future<bool> delete(
{required int profileId,
required String token,
required List<SkillsHobbies> skillsHobbies}) async {
String authToken = "Token $token";
bool success = false;
String path = "${Url.instance.skillsHobbies()}$profileId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authToken
};
Map body = {
"skill_hobby": [skillsHobbies]
};
try {
http.Response response = await Request.instance.deleteRequest(
path: path, headers: headers, body: body, param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
success = data['success'];
}
} catch (e) {
throw e.toString();
}
return success;
}
////GET ALL
Future<List<SkillsHobbies>> getAllSkillsHobbies() async {
List<SkillsHobbies> skillsAndHobbies = [];
String path = Url.instance.getAllSkillsHobbies();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
};
try {
http.Response response = await Request.instance.getRequest(
param: {},
path: path,
headers: headers,
);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
data['data'].forEach((var element) {
SkillsHobbies skillsHobbies = SkillsHobbies.fromJson(element);
skillsAndHobbies.add(skillsHobbies);
});
}
}
} catch (e) {
throw e.toString();
}
return skillsAndHobbies;
} }
} }

View File

@ -5,9 +5,9 @@ class Url {
String host() { String host() {
// return '192.168.10.221:3003'; // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph'; // return 'agusandelnorte.gov.ph';
// return "192.168.10.219:3000"; return "192.168.10.219:3000";
// return "devweb.agusandelnorte.gov.ph"; // return "devweb.agusandelnorte.gov.ph";
return 'devapi.agusandelnorte.gov.ph:3004'; // return 'devapi.agusandelnorte.gov.ph:3004';
} }
String authentication() { String authentication() {
@ -82,9 +82,12 @@ String getVoluntaryWorks(){
} }
//// skills hobbies //// skills hobbies
String getSkillsHobbies(){ String skillsHobbies(){
return "/api/jobnet_app/profile/pds/other/skill_hobby/"; return "/api/jobnet_app/profile/pds/other/skill_hobby/";
} }
String getAllSkillsHobbies(){
return "/api/jobnet_app/skill_hobby/";
}
//// orgmemberships //// orgmemberships
String getOrgMemberShips(){ String getOrgMemberShips(){
return "/api/jobnet_app/profile/pds/other/org_membership/"; return "/api/jobnet_app/profile/pds/other/org_membership/";

View File

@ -853,6 +853,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.3.0" version: "5.3.0"
simple_chips_input:
dependency: "direct main"
description:
name: simple_chips_input
sha256: "522b2e715fe67f325693e003acfd09fc0b8ab25a2c0c87fb8e5ce5b23a8a2ec1"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter

View File

@ -72,6 +72,7 @@ dependencies:
modal_progress_hud_nsn: ^0.3.0 modal_progress_hud_nsn: ^0.3.0
searchfield: ^0.7.5 searchfield: ^0.7.5
filter_list: ^1.0.2 filter_list: ^1.0.2
simple_chips_input: ^1.0.0
dev_dependencies: dev_dependencies: