diff --git a/lib/addevent.dart b/lib/addevent.dart index 53e1fbdec09fa6e1b3d1a7cb3fd2a371949867f5..c798fb3e2db3b961db5f95906d95bee5f1cfa125 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -143,7 +143,7 @@ class _AddEventPageState extends State<AddEvent> { if (RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch( eventStore.currentEvent.label)) { if (RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch( - eventStore.currentEvent.description)) { + eventStore.currentEvent.description) || eventStore.currentEvent.description == '') { if(_validateLatitude(eventStore.currentEvent.latitude)){ if(_validateLongitude(eventStore.currentEvent.longitude)){ if(_validateElevation(eventStore.currentEvent.elevation)){ @@ -282,9 +282,11 @@ class _AddEventPageState extends State<AddEvent> { validator: (value) { if (!RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch( value!)) { + if(value == ''){ + return null; //An empty description is also allowed. + } return "Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :"; } else { - //eventStore.currentEvent.label = value; return null; // Entered Text is valid } }, @@ -486,7 +488,7 @@ class _AddEventPageState extends State<AddEvent> { //child: const Icon(Icons.check), ) ), - const SizedBox(width: 10.0), + const SizedBox(width: 5.0), ], ), ); diff --git a/lib/configuration.dart b/lib/configuration.dart index e9a32f2d96757ced3a307305fe59323b327e637b..2c9bfa2a83a7c6665a5ecfde594ee0cf8fe20d3e 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -1,10 +1,13 @@ import 'dart:convert'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'datamodel.dart'; import 'sensorconnector.dart'; import 'databaseconnector.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; class Configuration extends StatefulWidget { const Configuration({Key? key}) : super(key: key); @@ -19,10 +22,37 @@ class _MyHomePageState extends State<Configuration> { late Future<List<EventType>> futureEventTypes; late Future<List<Device>> futureDevices; late Future<String> futureAuthToken; - + var database = DatabaseInstance(); SensorConnector connector = SensorConnector(); final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); + + Future<void> dumpToFile() async{ + var date = DateTime.now().toUtc(); + var isoDate = date.toIso8601String(); + + String filename = + date.year.toString().padLeft(4, '0') + + date.month.toString().padLeft(2, '0') + + date.day.toString().padLeft(2, '0') + + date.hour.toString().padLeft(2, '0') + + date.minute.toString().padLeft(2, '0') + + date.second.toString().padLeft(2, '0') + + '_events.json'; + + String eventsJson = await database.eventDump(); + + final Directory? directory = await getExternalStorageDirectory(); + if(directory != null) { + String filepath = join(directory.path, filename); + + final File file = File(filepath); + await file.writeAsString(eventsJson); + debugPrint('Stored file at: ' + filepath); + } + } + + Future<void> updateConfiguration() async { final EventStoreInstance event = EventStoreInstance(); @@ -197,18 +227,19 @@ class _MyHomePageState extends State<Configuration> { child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - const SizedBox(width: 10.0), + //const SizedBox(width: 10.0), FloatingActionButton.extended( heroTag: null, - tooltip: 'Reset all data', - icon: const Icon(Icons.cancel), - label: const Text('Reset all'), + tooltip: 'Export events to local .json file', + icon: const Icon(Icons.download), + label: const Text('Export Events'), onPressed: () { - //events.reset(); //TODO: remove before release! - var db = DatabaseInstance(); - db.delete(); + dumpToFile(); - configuration.reset(); //TODO: remove before release this is not a real use case! + //events.reset(); //TODO: remove before release this is not a real use case! + //var db = DatabaseInstance(); + //db.delete(); + //configuration.reset(); }, ), const SizedBox(width: 50), @@ -222,7 +253,7 @@ class _MyHomePageState extends State<Configuration> { //TODO: display failed as user feedback somehow }, ), - const SizedBox(width: 10.0), + const SizedBox(width: 5.0), ], ), ) diff --git a/lib/viewevents.dart b/lib/viewevents.dart index 5704da022ab71f6f0b1f55aa36220f5a05f42794..00a9fd5ae7b5be41db86d903082f0b9a66e3d542 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -1,10 +1,8 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:path_provider/path_provider.dart'; import 'datamodel.dart'; import 'sensorconnector.dart'; import 'databaseconnector.dart'; -import 'package:path/path.dart'; class ViewEvents extends StatefulWidget { const ViewEvents({Key? key}) : super(key: key); @@ -34,24 +32,6 @@ class _ViewEvents extends State<ViewEvents> { setState(() {}); //Got events from database, so update UI } - Future<void> dumpToFile() async{ - //localEvents = await database.getEvents(); - var date = DateTime.now().toUtc(); - var isoDate = date.toIso8601String(); - - String eventsJson = await database.eventDump(); - - final Directory? directory = await getExternalStorageDirectory(); - if(directory != null) { - String filename = 'time_event_dump.json'; - String filepath = join(directory.path, filename); - - final File file = File(filepath); - await file.writeAsString(eventsJson); - debugPrint('Stored file at: ' + filepath); - } - } - @override void initState() { _syncStatus = ''; @@ -279,8 +259,6 @@ class _ViewEvents extends State<ViewEvents> { label: const Text('Sync'), onPressed: () { syncEvents(); - - dumpToFile(); //TODO. Move to right button. }, ), ), @@ -291,4 +269,3 @@ class _ViewEvents extends State<ViewEvents> { } } //TODO: allow editing fields here. Check validation of input value! -//TODO: dump events to json for local backups in the field. "dumpToFile" \ No newline at end of file