Learning and development refactor and create its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-02 16:22:31 +08:00
parent 61646bdcaa
commit 74c2c7ef59
8 changed files with 295 additions and 62 deletions

View File

@ -0,0 +1,28 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/profile/learningDevelopment_service.dart';
import '../../model/profile/learning_development.dart';
part 'learning_development_event.dart';
part 'learning_development_state.dart';
class LearningDevelopmentBloc
extends Bloc<LearningDevelopmentEvent, LearningDevelopmentState> {
LearningDevelopmentBloc() : super(LearningDevelopmentInitial()) {
List<LearningDevelopement> learningsAndDevelopments;
on<GetLearningDevelopments>((event, emit) async {
// try {
emit(LearningDevelopmentLoadingState());
List<LearningDevelopement> learnings = await LearningDevelopmentServices
.instance
.getLearningDevelopments(event.profileId, event.token);
learningsAndDevelopments = learnings;
emit(LearningDevelopmentLoadedState(
learningsAndDevelopment: learningsAndDevelopments));
// } catch (e) {
// emit(LeaningDevelopmentErrorState(message: e.toString()));
// }
});
}
}

View File

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

View File

@ -0,0 +1,28 @@
part of 'learning_development_bloc.dart';
abstract class LearningDevelopmentState extends Equatable {
const LearningDevelopmentState();
@override
List<Object> get props => [];
}
class LearningDevelopmentInitial extends LearningDevelopmentState {}
class LearningDevelopmentLoadedState extends LearningDevelopmentState{
final List<LearningDevelopement> learningsAndDevelopment;
const LearningDevelopmentLoadedState({required this.learningsAndDevelopment});
@override
List<Object> get props => [learningsAndDevelopment];
}
class LeaningDevelopmentErrorState extends LearningDevelopmentState{
final String message;
const LeaningDevelopmentErrorState({required this.message});
@override
List<Object> get props => [message];
}
class LearningDevelopmentLoadingState extends LearningDevelopmentState{
}

View File

@ -23,7 +23,7 @@ class LearningDevelopement {
final dynamic attachments;
final EdBy? sponsoredBy;
final ConductedTraining? conductedTraining;
final int? totalHoursAttended;
final double? totalHoursAttended;
factory LearningDevelopement.fromJson(Map<String, dynamic> json) => LearningDevelopement(
attachments: json["attachments"],

View File

@ -1,7 +1,13 @@
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:flutter_spinkit/flutter_spinkit.dart';
import 'package:intl/intl.dart';
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/learning_development.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
@ -9,62 +15,168 @@ import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';
import 'package:unit2/widgets/error_state.dart';
class LearningAndDevelopmentScreen extends StatelessWidget {
final List<LearningDevelopement> learningDevelopments;
const LearningAndDevelopmentScreen({super.key, required this.learningDevelopments});
const LearningAndDevelopmentScreen(
{super.key,});
@override
Widget build(BuildContext context) {
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
return Scaffold(
appBar: AppBar(title: const Text(learningAndDevelopmentScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: [AddLeading(onPressed: (){})],
),
body: learningDevelopments.isNotEmpty? ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10),
itemCount: learningDevelopments.length,
itemBuilder: (BuildContext context, int index){
String training = learningDevelopments[index].conductedTraining!.title!.title!;
String provider = learningDevelopments[index].conductedTraining!.conductedBy!.name!;
String start = dteFormat2.format(learningDevelopments[index].conductedTraining!.fromDate!);
String end = dteFormat2.format(learningDevelopments[index].conductedTraining!.toDate!);
String type = learningDevelopments[index].conductedTraining!.learningDevelopmentType!.title!;
return Column(
children: [
Container(
decoration: box1(),
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8),
width: screenWidth,
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(training,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),),
const Divider(),
const SizedBox(height: 5,),
Text(provider,style: Theme.of(context).textTheme.titleSmall,),
const SizedBox(height: 5,),
Text("$duration : $start TO $end",style: Theme.of(context).textTheme.labelMedium,),
const SizedBox(height: 5,),
Text("$type : $type",style: Theme.of(context).textTheme.labelMedium,),
]),
),
IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)),
],
),
),
const SizedBox(height: 8,),
],
);
}):const EmptyData(message: "You don't have any Learning and Development added. Please click + to add."),
);
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
return Scaffold(
appBar: AppBar(
title: const Text(learningAndDevelopmentScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: [AddLeading(onPressed: () {})],
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
indicatorWidget: const SpinKitFadingCircle(
color: Colors.white,
),
backgroundColor: Colors.black87,
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<LearningDevelopmentBloc,
LearningDevelopmentState>(
listener: (context, state) {
if (state is LearningDevelopmentLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is LearningDevelopmentLoadedState ||
state is LeaningDevelopmentErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
// TODO: implement listener
},
builder: (context, state) {
if (state is LearningDevelopmentLoadedState) {
if (state.learningsAndDevelopment.isNotEmpty) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount:
state.learningsAndDevelopment.length,
itemBuilder:
(BuildContext context, int index) {
String training = state
.learningsAndDevelopment[index]
.conductedTraining!
.title!
.title!;
String provider = state
.learningsAndDevelopment[index]
.conductedTraining!
.conductedBy!
.name!;
String start = dteFormat2.format(state
.learningsAndDevelopment[index]
.conductedTraining!
.fromDate!);
String end = dteFormat2.format(state
.learningsAndDevelopment[index]
.conductedTraining!
.toDate!);
String type = state
.learningsAndDevelopment[index]
.conductedTraining!
.learningDevelopmentType!
.title!;
return Column(
children: [
Container(
decoration: box1(),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Text(
training,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500),
),
const Divider(),
const SizedBox(
height: 5,
),
Text(
provider,
style: Theme.of(context)
.textTheme
.titleSmall,
),
const SizedBox(
height: 5,
),
Text(
"$duration : $start to $end'",
style: Theme.of(context)
.textTheme
.labelMedium,
),
const SizedBox(
height: 5,
),
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert)),
],
),
),
const SizedBox(
height: 8,
),
],
);
});
} else {
const EmptyData(
message:
"You don't have any Learning and Development added. Please click + to add.");
}
}
if (state is LeaningDevelopmentErrorState) {
return (SomethingWentWrong(
message: state.message, onpressed: () {}));
}
return Container();
},
);
}
return Container();
},
);
}
return Container();
},
),
));
}
}

View File

@ -10,6 +10,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:fluttericon/modern_pictograms_icons.dart';
import 'package:unit2/bloc/education/education_bloc.dart';
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/workHistory/workHistory_bloc.dart';
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
@ -215,13 +216,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
icon: Elusive.lightbulb,
title: "Learning & Development",
onTap: () {
// Navigator.push(context, MaterialPageRoute(
// builder: (BuildContext context) {
// return LearningAndDevelopmentScreen(
// learningDevelopments: state
// .profileInformation
// .learningsAndDevelopment);
// }));
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => LearningDevelopmentBloc()..add(GetLearningDevelopments(profileId: profileId!, token: token!)),
child: const LearningAndDevelopmentScreen(),
);
}));
},
),
const Divider(),

View File

@ -0,0 +1,41 @@
import 'dart:convert';
import 'package:unit2/utils/request.dart';
import '../../model/profile/learning_development.dart';
import '../../utils/urls.dart';
import 'package:http/http.dart' as http;
class LearningDevelopmentServices {
static final LearningDevelopmentServices _instance =
LearningDevelopmentServices();
static LearningDevelopmentServices get instance => _instance;
Future<List<LearningDevelopement>> getLearningDevelopments(
int profileId, String token) async {
List<LearningDevelopement> learningsAndDevelopments = [];
String authToken = "Token $token";
String path = "${Url.instance.getLearningAndDevelopments()}$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 learnings) {
LearningDevelopement learningDevelopement =
LearningDevelopement.fromJson(learnings);
learningsAndDevelopments.add(learningDevelopement);
});
}
}
// } catch (e) {
// throw e.toString();
// }
return learningsAndDevelopments;
}
}

View File

@ -5,8 +5,8 @@ class Url {
String host() {
// // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph';
// return "192.168.10.219:3000";
return "devweb.agusandelnorte.gov.ph";
return "192.168.10.219:3000";
// return "devweb.agusandelnorte.gov.ph";
// return 'devapi.agusandelnorte.gov.ph:3004';
}
@ -51,6 +51,12 @@ String getEducationalBackgrounds(){
return "/api/jobnet_app/profile/pds/education/";
}
//// learning and development paths
String getLearningAndDevelopments(){
return "api/jobnet_app/profile/pds/learning_development/";
}
// location utils path
String getCounties(){
return "/api/jobnet_app/countries/";