Skip to content
Snippets Groups Projects
Commit d9b87bbc authored by Maximilian Betz's avatar Maximilian Betz
Browse files

selection of devices in configuration works now

parent c62aede3
No related branches found
No related tags found
No related merge requests found
......@@ -4,17 +4,40 @@ import 'package:http/http.dart' as http;
import 'dart:convert';
import 'datamodel.dart';
Future<List<Device>> updateDevices(int collectionId) async {
debugPrint("Start HTTP GET Collection Devices. Collection Id: " + collectionId.toString());
String url = 'https://sensor.awi.de/rest/sensors/collections/getItemsOfCollection/' + collectionId.toString();
Future<Collection> fetchCollection() async {
debugPrint("Start HTTP GET++##");
// Get Access to local device and current event store.
DeviceStoreInstance availableDevices = DeviceStoreInstance();
EventCurrentInstance currentEvent = EventCurrentInstance();
final response = await http
.get(Uri.parse('https://sensor.awi.de/rest/sensors/collections/getCollection/22'));
.get(Uri.parse(url));
debugPrint("Got something via Sensor Rest...");
List<Device> collectionDevices = [];
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
return Collection.fromJson(jsonDecode(response.body));
// If the server did return a 200 OK response, then parse the JSON.
List<dynamic> data = json.decode(response.body);
for (var entry in data) {
collectionDevices.add(Device.fromJson(entry));
}
debugPrint("Got the following devices: ");
for (var device in collectionDevices){
debugPrint(device.toString());
}
/*Update to local event store*/
availableDevices.store = collectionDevices;
//Update id and urn in add event widget
currentEvent.store.id = collectionDevices[0].id;
currentEvent.store.urn = collectionDevices[0].urn;
return collectionDevices;
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
......@@ -58,7 +81,7 @@ class _MyHomePageState extends State<Configuration> {
@override
void initState() {
super.initState();
futureCollection = fetchCollection();
//futureCollection = fetchCollection();
futureCollections = fetchCollections();
}
late Future<String> eventTypes;
......@@ -126,16 +149,19 @@ class _MyHomePageState extends State<Configuration> {
FloatingActionButton.extended(
heroTag: null,
tooltip: 'Request Collections from sensor.awi.de',
icon: Icon(Icons.download),
icon: const Icon(Icons.download),
label: const Text("Get Collections"),
onPressed: null,
onPressed: () {
},
),
FloatingActionButton.extended(
heroTag: null,
tooltip: 'Select Collection and download corresponding devices',
icon: Icon(Icons.save),
icon: const Icon(Icons.save),
label: const Text('Select'),
onPressed: null,
onPressed: () {
updateDevices(activeCollection.store.id);
},
),
],
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment