Implemented crud API for skills and hobbies screen
parent
36bec39fb6
commit
e686cd1f9f
|
@ -10,15 +10,106 @@ part 'hoobies_state.dart';
|
|||
class HoobiesBloc extends Bloc<HobbiesEvent, HobbiesState> {
|
||||
HoobiesBloc() : super(HoobiesInitial()) {
|
||||
List<SkillsHobbies> skillsAndHobbies = [];
|
||||
List<SkillsHobbies> allSkillsAndHobbies = [];
|
||||
List<String> mySkillsAndHobbies = [];
|
||||
on<GetSkillsHobbies>((event, emit) async {
|
||||
emit(HobbiesLoadingState());
|
||||
try {
|
||||
List<SkillsHobbies> hobbies = await SkillsHobbiesServices.instance.getSkillsHobbies(event.profileId, event.token);
|
||||
List<SkillsHobbies> hobbies = await SkillsHobbiesServices.instance
|
||||
.getSkillsHobbies(event.profileId, event.token);
|
||||
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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,3 +14,39 @@ class GetSkillsHobbies extends HobbiesEvent{
|
|||
@override
|
||||
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});
|
||||
}
|
|
@ -23,7 +23,33 @@ class HobbiesErrorState extends HobbiesState{
|
|||
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 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});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,9 +4,12 @@ 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: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/user/user_bloc.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/utils/global.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 '../../../../bloc/profile/other_information/hobbies/hoobies_bloc.dart';
|
||||
import '../../../../theme-data.dart/btn-style.dart';
|
||||
import '../../../../utils/alerts.dart';
|
||||
|
||||
class SkillHobbiesScreen extends StatelessWidget {
|
||||
const SkillHobbiesScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String token;
|
||||
int profileId;
|
||||
final bloc = BlocProvider.of<HoobiesBloc>(context);
|
||||
List<SkillsHobbies>? mySkillsAndHobbies;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(skillAndHobbiesTitle),
|
||||
backgroundColor: primary,
|
||||
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(
|
||||
padding: const EdgeInsets.all(24),
|
||||
backgroundColor: Colors.black87,
|
||||
|
@ -34,6 +53,8 @@ class SkillHobbiesScreen extends StatelessWidget {
|
|||
child: BlocBuilder<UserBloc, UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is UserLoggedIn) {
|
||||
token = state.userData!.user!.login!.token!;
|
||||
profileId = state.userData!.user!.login!.user!.profileId!;
|
||||
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||
builder: (context, state) {
|
||||
if (state is ProfileLoaded) {
|
||||
|
@ -42,16 +63,65 @@ class SkillHobbiesScreen extends StatelessWidget {
|
|||
if (state is HobbiesLoadingState) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.showWithText("Please wait...");
|
||||
}if(state is HobbiesLoadedState || state is HobbiesErrorState){
|
||||
}
|
||||
if (state is HobbiesLoadedState ||
|
||||
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) {
|
||||
if (state is HobbiesLoadedState) {
|
||||
mySkillsAndHobbies = state.skillsAndHobbies;
|
||||
if (state.skillsAndHobbies.isNotEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
|
@ -61,17 +131,51 @@ class SkillHobbiesScreen extends StatelessWidget {
|
|||
crossAxisAlignment:
|
||||
WrapCrossAlignment.start,
|
||||
direction: Axis.horizontal,
|
||||
children:
|
||||
state.skillsAndHobbies.map((SkillsHobbies sh) {
|
||||
return FittedBox(
|
||||
child: Row(
|
||||
children: state.skillsAndHobbies
|
||||
.map((SkillsHobbies sh) {
|
||||
return Wrap(
|
||||
children: [
|
||||
Text(sh.name!),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.close)),
|
||||
],
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 6),
|
||||
|
||||
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()),
|
||||
);
|
||||
|
@ -81,6 +185,15 @@ class SkillHobbiesScreen extends StatelessWidget {
|
|||
"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();
|
||||
},
|
||||
);
|
||||
|
@ -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),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ class WorkHistoryService {
|
|||
}
|
||||
|
||||
|
||||
//delete workhistory
|
||||
////delete workhistory
|
||||
Future<bool> delete(
|
||||
{required int profileId,
|
||||
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{
|
||||
Map<dynamic, dynamic>? statusResponse={};
|
||||
String authtoken = "Token $token";
|
||||
|
@ -111,7 +111,7 @@ class WorkHistoryService {
|
|||
"_oldAgencyId":oldWorkHistory.agency!.id,
|
||||
"oldFromDate":oldWorkHistory.fromDate?.toString(),
|
||||
};
|
||||
// try{
|
||||
try{
|
||||
http.Response response = await Request.instance.putRequest(path: path, headers: headers, body: body, param: {});
|
||||
if(response.statusCode == 200 ){
|
||||
Map data = jsonDecode(response.body);
|
||||
|
@ -120,12 +120,12 @@ class WorkHistoryService {
|
|||
statusResponse.addAll({'success':false});
|
||||
}
|
||||
return statusResponse;
|
||||
// }catch(e){
|
||||
// throw e.toString();
|
||||
// }
|
||||
}catch(e){
|
||||
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{
|
||||
String authtoken = "Token $token";
|
||||
String path = '${Url.instance.workhistory()}$profileId/';
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:unit2/utils/request.dart';
|
||||
|
@ -7,21 +5,23 @@ import 'package:unit2/utils/request.dart';
|
|||
import '../model/profile/other_information/skills_and_hobbies.dart';
|
||||
import '../utils/urls.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class SkillsHobbiesServices {
|
||||
static final SkillsHobbiesServices _instance = SkillsHobbiesServices();
|
||||
static SkillsHobbiesServices get instance => _instance;
|
||||
|
||||
Future<List<SkillsHobbies>> getSkillsHobbies(int profileId, String token)async{
|
||||
|
||||
////GET
|
||||
Future<List<SkillsHobbies>> getSkillsHobbies(
|
||||
int profileId, String token) async {
|
||||
List<SkillsHobbies> skillsAndHobbies = [];
|
||||
String authToken = "Token $token";
|
||||
String path = "${Url.instance.getSkillsHobbies()}$profileId/";
|
||||
String path = "${Url.instance.skillsHobbies()}$profileId/";
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': authToken
|
||||
};
|
||||
try {
|
||||
http.Response response = await Request.instance.getRequest(path: path,param: {},headers: headers);
|
||||
http.Response response = await Request.instance
|
||||
.getRequest(path: path, param: {}, headers: headers);
|
||||
if (response.statusCode == 200) {
|
||||
Map data = jsonDecode(response.body);
|
||||
if (data['data']['skill_hobby'] != null) {
|
||||
|
@ -36,5 +36,89 @@ class SkillsHobbiesServices{
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ class Url {
|
|||
String host() {
|
||||
// return '192.168.10.221:3003';
|
||||
// return 'agusandelnorte.gov.ph';
|
||||
// return "192.168.10.219:3000";
|
||||
return "192.168.10.219:3000";
|
||||
// return "devweb.agusandelnorte.gov.ph";
|
||||
return 'devapi.agusandelnorte.gov.ph:3004';
|
||||
// return 'devapi.agusandelnorte.gov.ph:3004';
|
||||
}
|
||||
|
||||
String authentication() {
|
||||
|
@ -82,9 +82,12 @@ String getVoluntaryWorks(){
|
|||
}
|
||||
|
||||
//// skills hobbies
|
||||
String getSkillsHobbies(){
|
||||
String skillsHobbies(){
|
||||
return "/api/jobnet_app/profile/pds/other/skill_hobby/";
|
||||
}
|
||||
String getAllSkillsHobbies(){
|
||||
return "/api/jobnet_app/skill_hobby/";
|
||||
}
|
||||
//// orgmemberships
|
||||
String getOrgMemberShips(){
|
||||
return "/api/jobnet_app/profile/pds/other/org_membership/";
|
||||
|
|
|
@ -853,6 +853,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
|
|
@ -72,6 +72,7 @@ dependencies:
|
|||
modal_progress_hud_nsn: ^0.3.0
|
||||
searchfield: ^0.7.5
|
||||
filter_list: ^1.0.2
|
||||
simple_chips_input: ^1.0.0
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
|
Loading…
Reference in New Issue