non academic recognition refactor created its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-06 14:16:49 +08:00
parent acc74653d1
commit 2a57e7453b
11 changed files with 246 additions and 48 deletions

View File

@ -0,0 +1,24 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/profile/non_academic_services.dart';
import '../../model/profile/other_information/non_acedimic_recognition.dart';
part 'non_academic_recognition_event.dart';
part 'non_academic_recognition_state.dart';
class NonAcademicRecognitionBloc extends Bloc<NonAcademicRecognitionEvent, NonAcademicRecognitionState> {
NonAcademicRecognitionBloc() : super(NonAcademicRecognitionInitial()) {
List<NonAcademicRecognition> nonAcademicRecognitions = [];
on<GetNonAcademicRecognition>((event, emit)async {
emit(NonAcademicRecognitionLoadingState());
try{
List<NonAcademicRecognition> recognitions = await NonAcademicRecognitionServices.instance.getNonAcademicRecognition(event.profileId, event.token);
nonAcademicRecognitions = recognitions;
emit(NonAcademicRecognitionLoadedState(nonAcademicRecognition: nonAcademicRecognitions));
}catch(e){
emit(NonAcademicRecognitionErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,16 @@
part of 'non_academic_recognition_bloc.dart';
abstract class NonAcademicRecognitionEvent extends Equatable {
const NonAcademicRecognitionEvent();
@override
List<Object> get props => [];
}
class GetNonAcademicRecognition extends NonAcademicRecognitionEvent{
final int profileId;
final String token;
const GetNonAcademicRecognition({required this.profileId, required this.token});
@override
List<Object> get props => [profileId,token];
}

View File

@ -0,0 +1,28 @@
part of 'non_academic_recognition_bloc.dart';
abstract class NonAcademicRecognitionState extends Equatable {
const NonAcademicRecognitionState();
@override
List<Object> get props => [];
}
class NonAcademicRecognitionInitial extends NonAcademicRecognitionState {}
class NonAcademicRecognitionLoadingState extends NonAcademicRecognitionState{
}
class NonAcademicRecognitionLoadedState extends NonAcademicRecognitionState{
final List<NonAcademicRecognition> nonAcademicRecognition;
const NonAcademicRecognitionLoadedState({required this.nonAcademicRecognition});
@override
List<Object> get props => [];
}
class NonAcademicRecognitionErrorState extends NonAcademicRecognitionState{
final String message;
const NonAcademicRecognitionErrorState({required this.message});
@override
List<Object> get props => [];
}

View File

@ -1,5 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:unit2/model/profile/other_information/non_acedimic_recognition.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:unit2/bloc/non_academic_recognition.dart/non_academic_recognition_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/theme-data.dart/box_shadow.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';
@ -8,44 +13,120 @@ import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';
class NonAcademicRecognitionScreen extends StatelessWidget { class NonAcademicRecognitionScreen extends StatelessWidget {
final List<NonAcademicRecognition> nonAcademicRecognitions; const NonAcademicRecognitionScreen({
const NonAcademicRecognitionScreen({super.key, required this.nonAcademicRecognitions}); super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text(nonAcademicRecTitle), centerTitle: true, backgroundColor: primary,actions: [AddLeading(onPressed: (){})],), appBar: AppBar(
body: nonAcademicRecognitions.isNotEmpty?ListView.builder( title: const Text(nonAcademicRecTitle),
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10), centerTitle: true,
itemCount: nonAcademicRecognitions.length, backgroundColor: primary,
itemBuilder: (BuildContext context, int index){ actions: [AddLeading(onPressed: () {})],
String award = nonAcademicRecognitions[index].title!; ),
String presenter = nonAcademicRecognitions[index].presenter!.name!; body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<NonAcademicRecognitionBloc,
NonAcademicRecognitionState>(
listener: (context, state) {
if (state is NonAcademicRecognitionLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is NonAcademicRecognitionLoadedState ||
state is NonAcademicRecognitionErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
if (state is NonAcademicRecognitionLoadedState) {
if (state.nonAcademicRecognition.isNotEmpty) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount:
state.nonAcademicRecognition.length,
itemBuilder:
(BuildContext context, int index) {
String award = state
.nonAcademicRecognition[index].title!;
String presenter = state
.nonAcademicRecognition[index]
.presenter!
.name!;
return Column( return Column(
children: [ children: [
Container( Container(
width: screenWidth, width: screenWidth,
decoration: box1(), decoration: box1(),
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Row( child: Row(
children: [ children: [
Expanded(child: Column( Expanded(
mainAxisAlignment: MainAxisAlignment.start, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Text(award,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),), Text(
award,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500),
),
const Divider(), const Divider(),
Text(presenter), Text(presenter),
],)), ],
)),
IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert,color: Colors.grey,)) IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
], ],
), ),
), ),
const SizedBox(height: 5,), const SizedBox(
height: 5,
),
], ],
); );
}): const EmptyData(message: "You don't have any Non Academic Recognition added. Please click + to add"), });
} else {
const EmptyData(
message:
"You don't have any Non Academic Recognition added. Please click + to add");
}
}
return Container();
},
); );
} }
return Container();
},
);
}
return Container();
},
),
));
}
} }

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.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:unit2/bloc/bloc/organization_membership_bloc.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/organization_memberships.dart'; import 'package:unit2/model/profile/other_information/organization_memberships.dart';
@ -12,6 +11,7 @@ import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';
import '../../../../bloc/org_membership/organization_membership_bloc.dart';
import '../../../../utils/global.dart'; import '../../../../utils/global.dart';
class OrgMembershipsScreen extends StatelessWidget { class OrgMembershipsScreen extends StatelessWidget {

View File

@ -8,11 +8,11 @@ import 'package:fluttericon/elusive_icons.dart';
import 'package:fluttericon/entypo_icons.dart'; import 'package:fluttericon/entypo_icons.dart';
import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:fluttericon/modern_pictograms_icons.dart'; import 'package:fluttericon/modern_pictograms_icons.dart';
import 'package:unit2/bloc/bloc/organization_membership_bloc.dart';
import 'package:unit2/bloc/education/education_bloc.dart'; import 'package:unit2/bloc/education/education_bloc.dart';
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart'; import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
import 'package:unit2/bloc/hobbies/hoobies_bloc.dart'; import 'package:unit2/bloc/hobbies/hoobies_bloc.dart';
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart'; import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
import 'package:unit2/bloc/non_academic_recognition.dart/non_academic_recognition_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/references/references_bloc.dart'; import 'package:unit2/bloc/references/references_bloc.dart';
import 'package:unit2/bloc/voluntary_works/voluntary_work_bloc.dart'; import 'package:unit2/bloc/voluntary_works/voluntary_work_bloc.dart';
@ -35,6 +35,7 @@ import 'package:unit2/screens/profile/components/references_screen.dart';
import 'package:unit2/screens/profile/components/work_history_screen.dart'; import 'package:unit2/screens/profile/components/work_history_screen.dart';
import 'package:unit2/screens/profile/components/voluntary_works_screen.dart'; import 'package:unit2/screens/profile/components/voluntary_works_screen.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import '../../bloc/org_membership/organization_membership_bloc.dart';
import '../../bloc/user/user_bloc.dart'; import '../../bloc/user/user_bloc.dart';
import 'components/main_menu.dart'; import 'components/main_menu.dart';
import 'components/submenu.dart'; import 'components/submenu.dart';
@ -298,14 +299,16 @@ class _ProfileInfoState extends State<ProfileInfo> {
subMenu(Entypo.doc_text, subMenu(Entypo.doc_text,
"Non-Academic Recognitions", () { "Non-Academic Recognitions", () {
// Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
// builder: (BuildContext context) { builder: (BuildContext context) {
// return NonAcademicRecognitionScreen( return BlocProvider(
// nonAcademicRecognitions: state create: (context) => NonAcademicRecognitionBloc()
// .profileInformation ..add(GetNonAcademicRecognition(
// .otherInformation profileId: profileId!,
// .nonAcademicRecognition); token: token!)),
// })); child: const NonAcademicRecognitionScreen(),
);
}));
}), }),
]), ]),
ExpandableGroup( ExpandableGroup(

View File

@ -0,0 +1,41 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';
import '../../model/profile/other_information/non_acedimic_recognition.dart';
import '../../utils/urls.dart';
class NonAcademicRecognitionServices {
static final NonAcademicRecognitionServices _instance =
NonAcademicRecognitionServices();
static NonAcademicRecognitionServices get instance => _instance;
Future<List<NonAcademicRecognition>> getNonAcademicRecognition(
int profileId, String token) async {
List<NonAcademicRecognition> nonAcademicRecognitions = [];
String authToken = "Token $token";
String path = "${Url.instance.getNonAcademicRecognition()}$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);
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
if (data['data'] != null) {
data['data'].forEach((var recognition) {
NonAcademicRecognition nonAcademicRecognition =
NonAcademicRecognition.fromJson(recognition);
nonAcademicRecognitions.add(nonAcademicRecognition);
});
}
}
} catch (e) {
throw e.toString();
}
return nonAcademicRecognitions;
}
}

View File

@ -77,6 +77,11 @@ String getOrgMemberShips(){
return "/api/jobnet_app/profile/pds/other/org_membership/"; return "/api/jobnet_app/profile/pds/other/org_membership/";
} }
////non academic recognition
String getNonAcademicRecognition(){
return "/api/jobnet_app/profile/pds/other/non_acad_recognition/";
}
// location utils path // location utils path
String getCounties(){ String getCounties(){
return "/api/jobnet_app/countries/"; return "/api/jobnet_app/countries/";