You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1017 B
Dart
29 lines
1017 B
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:test_sa/models/device/device.dart';
|
|
|
|
import '../controllers/api_routes/urls.dart';
|
|
import 'api_client.dart';
|
|
|
|
class DevicesApiClient {
|
|
static final DevicesApiClient _instance = DevicesApiClient._internal();
|
|
final List<Device> devices = [];
|
|
|
|
DevicesApiClient._internal();
|
|
|
|
factory DevicesApiClient() => _instance;
|
|
|
|
/// Fetch devices and insert the result into [devices] list
|
|
Future getEquipment(String hospitalId) async {
|
|
final response = await ApiClient().getJsonForResponse(URLs.host1 + URLs.getEquipment, queryParameters: {'client': hospitalId});
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
// client's request was successfully received
|
|
List equipmentListJson = json.decode(utf8.decode(response.bodyBytes));
|
|
devices.clear();
|
|
devices.addAll(equipmentListJson.map((device) => Device.fromJson(device)).toList());
|
|
debugPrint("devices : ${devices.length}");
|
|
}
|
|
}
|
|
}
|