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; ...@@ -4,17 +4,40 @@ import 'package:http/http.dart' as http;
import 'dart:convert'; import 'dart:convert';
import 'datamodel.dart'; 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 { // Get Access to local device and current event store.
debugPrint("Start HTTP GET++##"); DeviceStoreInstance availableDevices = DeviceStoreInstance();
EventCurrentInstance currentEvent = EventCurrentInstance();
final response = await http 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 (response.statusCode == 200) {
// If the server did return a 200 OK response, // If the server did return a 200 OK response, then parse the JSON.
// then parse the JSON. List<dynamic> data = json.decode(response.body);
return Collection.fromJson(jsonDecode(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 { } else {
// If the server did not return a 200 OK response, // If the server did not return a 200 OK response,
// then throw an exception. // then throw an exception.
...@@ -58,7 +81,7 @@ class _MyHomePageState extends State<Configuration> { ...@@ -58,7 +81,7 @@ class _MyHomePageState extends State<Configuration> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
futureCollection = fetchCollection(); //futureCollection = fetchCollection();
futureCollections = fetchCollections(); futureCollections = fetchCollections();
} }
late Future<String> eventTypes; late Future<String> eventTypes;
...@@ -126,16 +149,19 @@ class _MyHomePageState extends State<Configuration> { ...@@ -126,16 +149,19 @@ class _MyHomePageState extends State<Configuration> {
FloatingActionButton.extended( FloatingActionButton.extended(
heroTag: null, heroTag: null,
tooltip: 'Request Collections from sensor.awi.de', tooltip: 'Request Collections from sensor.awi.de',
icon: Icon(Icons.download), icon: const Icon(Icons.download),
label: const Text("Get Collections"), label: const Text("Get Collections"),
onPressed: null, onPressed: () {
},
), ),
FloatingActionButton.extended( FloatingActionButton.extended(
heroTag: null, heroTag: null,
tooltip: 'Select Collection and download corresponding devices', tooltip: 'Select Collection and download corresponding devices',
icon: Icon(Icons.save), icon: const Icon(Icons.save),
label: const Text('Select'), 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