Newer
Older
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'datamodel.dart';
import 'addevent.dart';
import 'viewevents.dart';
import 'overview.dart';
import 'configuration.dart';
import 'databaseconnector.dart';
Future<void> pathStuff() async {
//Directory downloadsDirectory = await DownloadsPathProvider.downloadsDirectory;
//Directory appDocDir = await getApplicationDocumentsDirectory();
//debugPrint(appDocDir.path.toString());
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
//prefs.setString('events', 'blabla');
final String? events = prefs.getString('events');
print('Shared Preferences: ' + events!);
//const storage = FlutterSecureStorage();
//Map<String, String> allValues = await storage.readAll();
//print('Secure Storage: ' + allValues.toString());
var database = DatabaseInstance();
await database.connect(); //Do once at start of APP!
Event event = Event.fromJson({"id":0,"urnId":102,"urn":"mooring:f9-12","label":"hggg","type":"Calibration",
"typeId":15,"description":"ggggg","status":"PENDING",
"startDate":"2022-03-28T07:00:02.712112Z",
"endDate":"2022-03-28T07:00:02.712112Z","latitude":"53.5440109",
"longitude":"8.58033187","elevation":"48.7139892578125"});
List<Event> tempEvents = [];
//Update second event in sql database
event.id = 2;
event.description = 'updated description1';
//database.updateEvent(event);
//debugPrint("Add Event to database: " + event.toString());
//debugPrint("Events row Id: " + rowId.toString());
tempEvents = await database.getEvents();
debugPrint("Events in SQL Database: ");
for (var event in tempEvents){
debugPrint(event.toString());
}
}
void main() {
pathStuff();
EventStoreInstance events = EventStoreInstance();
final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
events.reset(); // TODO: load configuration and events from shared preferences.
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.fromEventDump(
[
{"id":1,"urnId":102,"urn":"mooring:f9-12","label":"hggg","type":"Calibration",
"typeId":15,"description":"ggggg","status":"PENDING",
"startDate":"2022-03-28T07:00:02.712112Z",
"endDate":"2022-03-28T07:00:02.712112Z","latitude":"53.5440109",
"longitude":"8.58033187","elevation":"48.7139892578125"},
{"id":2,"urnId":102,"urn":"mooring:f9-12","label":"hggg","type":"Calibration",
"typeId":15,"description":"ggggg","status":"PENDING",
"startDate":"2022-03-28T07:00:03.828190Z",
"endDate":"2022-03-28T07:00:03.828190Z","latitude":"53.54401033",
"longitude":"8.58032778","elevation":"48.720947265625"},
]);
//events.fromEventDump([{"id":102,"urn":"mooring:f9-12","label":"cf","type":"Calibration","typeId":15,"description":"fd","status":"PENDING","startDate":"2022-03-25T12:47:30.659436Z","endDate":"2022-03-25T12:47:30.659436Z","latitude":"","longitude":"","elevation":""},{"id":102,"urn":"mooring:f9-12","label":"cf","type":"Calibration","typeId":15,"description":"fd","status":"PENDING","startDate":"2022-03-25T12:47:32.136009Z","endDate":"2022-03-25T12:47:32.136009Z","latitude":"","longitude":"","elevation":""}]);
runApp(MaterialApp(
title: 'Mobile Event Log',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (context) => const Overview(),
'/second': (context) => const AddEvent(),
'/third': (context) => const ViewEvents(),
'/forth': (context) => const Configuration(),