passo_mobile_app/lib/sevices/profile/family_services.dart

38 lines
1.1 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:unit2/utils/request.dart';
import '../../model/profile/family_backround.dart';
import '../../utils/urls.dart';
import 'package:http/http.dart' as http;
class FamilyService{
static final FamilyService _instance = FamilyService();
static FamilyService get instance => _instance;
Future< List<FamilyBackground>> getFamilies(int profileId, String token)async{
List<FamilyBackground> families = [];
String authToken = "Token $token";
String path = "${Url.instance.getFamilies()}$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 family){
FamilyBackground familyBackground = FamilyBackground.fromJson(family);
families.add(familyBackground);
});
}
}
}catch(e){
throw e.toString();
}
return families;
}
}