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

some more changes in configuration

parent 3067ca4d
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'datamodel.dart';
import 'sensorconnector.dart';
class Configuration extends StatefulWidget {
const Configuration({Key? key}) : super(key: key);
......@@ -31,7 +28,9 @@ class _MyHomePageState extends State<Configuration> {
//Start fetching all possible sensor data as soon as possible:
futureCollections = connector.fetchCollections();
futureEventTypes = connector.fetchEventTypes();
futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
if (configuration.currentCollection.id != -1) {
futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
}
futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
}
late Future<String> eventTypes;
......@@ -99,6 +98,7 @@ class _MyHomePageState extends State<Configuration> {
collection if not initialized yet*/
if(configuration.currentCollection.id == -1){
configuration.currentCollection = configuration.collections[0];
futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
}
return DropdownButtonFormField(
......@@ -142,7 +142,6 @@ class _MyHomePageState extends State<Configuration> {
},
),
FloatingActionButton.extended(
heroTag: null,
tooltip: 'Select Collection and download corresponding devices',
icon: const Icon(Icons.save),
......@@ -153,29 +152,31 @@ class _MyHomePageState extends State<Configuration> {
//Update configuration with newly fetched data
futureDevices.then((value) => configuration.devices = value);
futureEventTypes.then((value) => configuration.eventTypes = value);
//Update id and urn for the add event widget with some initial data
events.currentEvent.id = configuration.devices[0].id;
events.currentEvent.urn = configuration.devices[0].urn;
events.currentEvent.description = '';
events.currentEvent.label = '';
events.currentEvent.type = configuration.eventTypes[0].name;
var date = DateTime.now().toUtc();
var isodata = date.toIso8601String();
events.currentEvent.startDate = isodata;
events.currentEvent.endDate = isodata;
configuration.initialized = true;
HapticFeedback.vibrate();
print("Devices: " + configuration.devices.toString()); //Still empty on first execution Why?
// TODO: Move fetchCollectionDevices to an own future and set configuration inside on finish!
try {
//Update id and urn for the add event widget with some initial data
events.currentEvent.id = configuration.devices[0].id; //TODO: fix if devices are an empty list.
events.currentEvent.urn = configuration.devices[0].urn;
events.currentEvent.description = '';
events.currentEvent.label = '';
events.currentEvent.type = configuration.eventTypes[0].name;
var date = DateTime.now().toUtc();
var isodata = date.toIso8601String();
events.currentEvent.startDate = isodata;
events.currentEvent.endDate = isodata;
configuration.initialized = true;
HapticFeedback.vibrate();
//TODO: display success
} catch(e){
throw Exception('Something went wrong try again');
}
});
});
//login();
//fetchEventTypes();
//updateDevices(configuration.currentCollection.id);
//HapticFeedback.vibrate();
//TODO: display failed here somehow
},
),
],
......
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
class Collection {
int id;
......
import 'package:flutter/material.dart';
import 'datamodel.dart';
import 'addevent.dart';
import 'viewevents.dart';
......
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Overview extends StatelessWidget {
......
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'datamodel.dart';
import 'package:http/http.dart' as http;
......@@ -318,11 +316,6 @@ class _ViewEvents extends State<ViewEvents> {
],
);
}
}
//TODO: allow editing fields here. Check validation of input value!
\ No newline at end of file
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