passo_mobile_app/lib/sevices/roles/rbac_operations/station_services.dart

39 lines
1.4 KiB
Dart

import 'dart:convert';
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart';
import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices{
static final RbacStationServices _instance = RbacStationServices();
static RbacStationServices get instance => _instance;
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RbacStation>> getStations({required int agencyId})async{
List<RbacStation> stations = [];
String path = Url.instance.getStation();
Map<String,String> param = {"government_agency_id":agencyId.toString()};
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
try{
http.Response response = await Request.instance.getRequest(param: param,path: path,headers: headers);
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
if(data['data'] != null){
for(var station in data['data']){
RbacStation area = RbacStation.fromJson(station);
stations.add(area);
}
}
}
}catch(e){
throw e.toString();
}
return stations;
}
}