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

minor changes

parent 53074cde
No related branches found
No related tags found
No related merge requests found
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
......@@ -147,36 +149,51 @@ class _MyHomePageState extends State<Configuration> {
icon: const Icon(Icons.save),
label: const Text('Store'),
onPressed: () {
futureAuthToken.whenComplete((){
futureDevices.whenComplete(() {
//Update configuration with newly fetched data
futureDevices.then((value) => configuration.devices = value);
futureEventTypes.then((value) => configuration.eventTypes = value);
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');
}
futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function
debugPrint("Login credentials correct! Auth Token: " + value);
futureDevices.then((value) {
debugPrint("Device List complete");
configuration.devices = value;
futureEventTypes.then((value) {
debugPrint("Event Types List complete");
configuration.eventTypes = value;
debugPrint("EventType Json: " + jsonEncode(
configuration.eventTypes[0]));
debugPrint("Device Json: " + jsonEncode(
configuration.devices[0]));
debugPrint("Current Collection Json: " + jsonEncode(
configuration.currentCollection));
debugPrint("Sensor Login Json: " + jsonEncode(
configuration.loginInformation));
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 isoDate = date.toIso8601String();
events.currentEvent.startDate = isoDate;
events.currentEvent.endDate = isoDate;
configuration.initialized = true;
HapticFeedback.vibrate();
//TODO: display success user feedback
} catch (e) {
throw Exception('Something went wrong try again');
}
});
});
});
//TODO: display failed here somehow
//TODO: display failed as user feedback somehow
},
),
],
......
......@@ -49,7 +49,7 @@ class Device{
@override
String toString(){
return '{ ${this.id}, ${this.urn} }';
return urn;
}
}
......@@ -155,14 +155,14 @@ class EventType{
int id;
String name;
EventType(
this.id,
this.name
);
EventType({
required this.id,
required this.name
});
factory EventType.fromSensorJson(Map<String, dynamic> parsedJson){
return EventType(parsedJson['id'] as int, parsedJson['generalName'] as String);
}
EventType.fromSensorJson(Map<String, dynamic> json)
: id = json['id'],
name = json['generalName'];
EventType.fromJson(Map<String, dynamic> json)
: id = json['id'],
......@@ -172,6 +172,11 @@ class EventType{
'id': id,
'name': name,
};
@override
String toString(){
return name;
}
}
......@@ -184,14 +189,14 @@ class SensorLogin{
this.password,
);
String toJsonString() {
return '{ "username": $mail, "authPassword": $password }';
}
Map<String, dynamic> toJson() => {
"username": mail,
"authPassword": password
"mail": mail,
"password": password
};
SensorLogin.fromJson(Map<String, dynamic> json)
: mail = json['mail'],
password = json['password'];
}
......
......@@ -37,12 +37,16 @@ void main() {
events.reset(); // TODO: load configuration and events from shared preferences.
configuration.reset();
configuration.loginInformation.mail = 'admin'; // Sandbox.sensor.de admin account
configuration.loginInformation.password ='adminadmin'; //TODO: replace for productive version.
configuration.loginInformation = SensorLogin.fromJson({"mail":"admin","password":"adminadmin"}); //TODO: replace for productive version.
//Load data from storage:
//events.currentEvent = Event.fromJson({"id":102,"urn":"mooring:f9-12","label":"gg","type":"Calibration","typeId":15,"description":"gvg","status":"EXPORTED","startDate":"2022-03-25T09:24:48.856120Z","endDate":"2022-03-25T09:24:48.856120Z","latitude":"53.54388522","longitude":"8.58144825","elevation":"1.9925537109375"});
//events.events.add(Event.fromJson({"id":102,"urn":"mooring:f9-12","label":"gg","type":"Calibration","typeId":15,"description":"gvg","status":"EXPORTED","startDate":"2022-03-25T09:24:48.856120Z","endDate":"2022-03-25T09:24:48.856120Z","latitude":"53.54388522","longitude":"8.58144825","elevation":"1.9925537109375"}));
//configuration.devices.add(Device.fromJson({"id":102,"urn":"mooring:f9-12"}));
//configuration.eventTypes.add(EventType.fromJson({"id":15,"name":"Calibration"}));
//configuration.currentCollection = Collection.fromJson({"id":1,"description":"","collectionName":"FRAM"});
//configuration.initialized = true;
//events.events.add(Event.fromJson({id: 102, urn: mooring:f9-12, label: gg, type: Calibration, typeId: 15, description: ggg, status: EXPORTED, startDate: 2022-03-25T09:10:46.932955Z, endDate: 2022-03-25T09:10:46.932955Z, latitude: 53.54409252, longitude: 8.58022428, elevation: 52.7396240234375}
//));
runApp(MaterialApp(
title: 'Mobile Event Log',
......
......@@ -69,9 +69,14 @@ class SensorConnector {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
eventTypeList = (json.decode(response.body) as List)
.map((i) => EventType.fromSensorJson(i))
.toList();
//eventTypeList = (json.decode(response.body) as List)
// .map((i) => EventType.fromSensorJson(i))
// .toList();
List<dynamic> data = json.decode(response.body);
for (var entry in data) {
eventTypeList.add(EventType.fromSensorJson(entry));
}
debugPrint("Fetching Event Types Success: " + eventTypeList.toString());
} else{
throw Exception('Failed to fetch event types. '
......
......@@ -239,7 +239,7 @@ class _ViewEvents extends State<ViewEvents> {
label: const Text('Sync'),
onPressed: () {
for (var event in _events.events){
debugPrint("Event: " + event.toJson().toString());
debugPrint("Event: " + jsonEncode(event));
}
syncEvents();
......
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