42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
|
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;
|
||
|
}
|
||
|
}
|