fixed saveFile
time time this time for real
This commit is contained in:
BIN
app-release.apk
BIN
app-release.apk
Binary file not shown.
@@ -48,21 +48,21 @@ class ExcursionDBHelper implements IDb {
|
||||
@override
|
||||
Future<int> addMainEntry(Map<String, String> excursion) async {
|
||||
var excursionDBClient = await dB;
|
||||
final existingID = await excursionDBClient.query(
|
||||
'excursion',
|
||||
where: 'ID = ?',
|
||||
whereArgs: [excursion['ID']],
|
||||
);
|
||||
// final existingID = await excursionDBClient.query(
|
||||
// 'excursion',
|
||||
// where: 'ID = ?',
|
||||
// whereArgs: [excursion['ID']],
|
||||
// );
|
||||
|
||||
if (existingID.isNotEmpty) {
|
||||
updateMainEntry(excursion);
|
||||
return existingID.first['ID'] as int; // Return existing ID
|
||||
}
|
||||
// if (existingID.isNotEmpty) {
|
||||
// updateMainEntry(excursion);
|
||||
// return existingID.first['ID'] as int; // Return existing ID
|
||||
// }
|
||||
|
||||
int id = await excursionDBClient.insert(
|
||||
'excursion',
|
||||
excursion,
|
||||
//conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
|
||||
return id; // Return the ID of the newly inserted entry
|
||||
|
||||
@@ -620,13 +620,14 @@ class _AddCamMainState extends State<AddCamMain> {
|
||||
}
|
||||
|
||||
bool empty = CheckRequired.checkRequired(rmap);
|
||||
// TODO for debugging always false
|
||||
empty = false;
|
||||
// for debugging always false
|
||||
// empty = false;
|
||||
|
||||
if (empty == true) {
|
||||
AddEntriesDialogHelper.showTemplateDialog(
|
||||
context,
|
||||
getFieldsText(),
|
||||
DatabasesEnum.place
|
||||
);
|
||||
return;
|
||||
} else if (empty == false) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
class FileDialogCancelled implements Exception {}
|
||||
@@ -462,16 +462,17 @@ class _ExcursionMainState extends State<ExcursionMain> {
|
||||
}
|
||||
|
||||
bool empty = CheckRequired.checkRequired(rmap);
|
||||
// TODO for debugging always false
|
||||
empty = false;
|
||||
// for debugging always false
|
||||
// empty = false;
|
||||
|
||||
if (empty == true) {
|
||||
if (empty) {
|
||||
AddEntriesDialogHelper.showTemplateDialog(
|
||||
context,
|
||||
getFieldsText(),
|
||||
DatabasesEnum.excursion
|
||||
);
|
||||
return;
|
||||
} else if (empty == false) {
|
||||
} else if (!empty) {
|
||||
await AddEntriesDialogHelper.showSaveOptionsDialog(
|
||||
context,
|
||||
getFieldsText(),
|
||||
|
||||
@@ -31,7 +31,7 @@ class _TrackingState extends State<Tracking> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO debugging (i guess)
|
||||
// debugging (i guess)
|
||||
// pathList.add(
|
||||
// LatLng(widget.startPosition.latitude, widget.startPosition.longitude),
|
||||
// );
|
||||
@@ -113,6 +113,7 @@ class _TrackingState extends State<Tracking> {
|
||||
if (position != null) {
|
||||
setState(() {
|
||||
pathList.add(LatLng(position.latitude, position.longitude));
|
||||
// Random value for debugging
|
||||
// pathList.add(LatLng(rand.nextInt(5) + 40, position.longitude));
|
||||
|
||||
locationMarkerPosition = LocationMarkerPosition(
|
||||
@@ -141,7 +142,9 @@ class _TrackingState extends State<Tracking> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.tracking),
|
||||
// leading: IconButton(onPressed: () {}, icon: Icon(Icons.arrow_back_rounded)),
|
||||
leading: IconButton(onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}, icon: Icon(Icons.arrow_back_rounded)),
|
||||
actions: [
|
||||
if (!positionStreamRunning)
|
||||
IconButton(
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:fforte/screens/sharedMethods/http_request.dart';
|
||||
import 'package:fforte/screens/sharedMethods/save_file.dart';
|
||||
import 'package:fforte/screens/sharedMethods/save_template.dart';
|
||||
import 'package:fforte/screens/sharedMethods/save_main_entry.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
@@ -13,6 +14,7 @@ class AddEntriesDialogHelper {
|
||||
static Future<void> showTemplateDialog(
|
||||
BuildContext context,
|
||||
Map<String, String> saveData,
|
||||
DatabasesEnum dbType,
|
||||
) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
@@ -29,7 +31,7 @@ class AddEntriesDialogHelper {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
saveTemplate(saveData, DatabasesEnum.place);
|
||||
saveTemplate(saveData, dbType);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/home',
|
||||
@@ -114,8 +116,7 @@ class AddEntriesDialogHelper {
|
||||
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible:
|
||||
false, // Verhindert das Schließen des Dialogs durch den Benutzer
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
@@ -136,7 +137,7 @@ class AddEntriesDialogHelper {
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
setState(() => isLoading = true);
|
||||
saveTemplate(saveData, DatabasesEnum.place);
|
||||
saveTemplate(saveData, dbType);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/home',
|
||||
@@ -191,17 +192,29 @@ class AddEntriesDialogHelper {
|
||||
isTemplate: isTemplate,
|
||||
dbType: dbType,
|
||||
);
|
||||
SaveFileMethod.saveFile(
|
||||
saveData,
|
||||
AppLocalizations.of(context)!.savefilefailed,
|
||||
saveData["CID"]!,
|
||||
);
|
||||
try {
|
||||
if (context.mounted) {
|
||||
await SaveFileMethod.saveFile(
|
||||
saveData,
|
||||
dbType == DatabasesEnum.place
|
||||
? AppLocalizations.of(context)!.justplace
|
||||
: AppLocalizations.of(context)!.excursion,
|
||||
dbType,
|
||||
);
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
}
|
||||
} catch (_) {
|
||||
// User cancelled the dialog
|
||||
}
|
||||
setState(() => isLoading = false);
|
||||
} catch (e) {
|
||||
SnackBarHelper.showSnackBarMessage(
|
||||
context,
|
||||
AppLocalizations.of(context)!.savefilefailed,
|
||||
);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
SnackBarHelper.showSnackBarMessage(
|
||||
context,
|
||||
AppLocalizations.of(context)!.savefilefailed,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.saveasfile),
|
||||
@@ -209,16 +222,20 @@ class AddEntriesDialogHelper {
|
||||
if (!isLoading)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData,
|
||||
isTemplate: isTemplate,
|
||||
dbType: dbType,
|
||||
);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/home',
|
||||
(route) => false,
|
||||
);
|
||||
try {
|
||||
SaveMainEntryMethod.saveEntry(
|
||||
entryData: saveData,
|
||||
isTemplate: isTemplate,
|
||||
dbType: dbType,
|
||||
);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/home',
|
||||
(route) => false,
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.justsave),
|
||||
),
|
||||
@@ -276,7 +293,9 @@ class AddEntriesDialogHelper {
|
||||
child: Text("Ok"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.cancel),
|
||||
),
|
||||
],
|
||||
@@ -310,9 +329,7 @@ class AddEntriesDialogHelper {
|
||||
child: Text("Ok"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => {
|
||||
Navigator.of(context).pop()
|
||||
},
|
||||
onPressed: () => {Navigator.of(context).pop()},
|
||||
child: Text(AppLocalizations.of(context)!.cancel),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,22 +1,37 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fforte/enums/databases.dart';
|
||||
import 'package:fforte/screens/excursion/exceptions/file_dialog_cancelled.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SaveFileMethod {
|
||||
static Future<void> saveFile(Map<String, String> place, String fileNameLocalization, String placeID) async {
|
||||
String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
String jsonPlace = jsonEncode(place);
|
||||
static Future<void> saveFile(
|
||||
Map<String, String> place,
|
||||
String fileNameLocalization,
|
||||
DatabasesEnum dbType,
|
||||
) async {
|
||||
try {
|
||||
String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
||||
|
||||
if (selectedDirectory == null) {
|
||||
return;
|
||||
if (selectedDirectory == null) {
|
||||
throw FileDialogCancelled();
|
||||
}
|
||||
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
String jsonPlace = jsonEncode(place);
|
||||
|
||||
await prefs.setString('saveDir', selectedDirectory);
|
||||
|
||||
File file = File(
|
||||
'$selectedDirectory/$fileNameLocalization-${dbType == DatabasesEnum.place ? place["CID"] : place["LogDat"]}.txt',
|
||||
);
|
||||
|
||||
await file.writeAsString(jsonPlace);
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
await prefs.setString('saveDir', selectedDirectory);
|
||||
|
||||
File file = File('$selectedDirectory/$fileNameLocalization-$placeID.txt');
|
||||
|
||||
await file.writeAsString(jsonPlace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class _ViewEntriesState extends State<ViewEntries> {
|
||||
Tab(text: AppLocalizations.of(context)!.map),
|
||||
],
|
||||
),
|
||||
title: Text(AppLocalizations.of(context)!.viewplacesappbar),
|
||||
title: widget.dbType == DatabasesEnum.place ? Text(AppLocalizations.of(context)!.viewplacesappbar) : Text(AppLocalizations.of(context)!.viewExcursionen) ,
|
||||
),
|
||||
body: TabBarView(
|
||||
children: [
|
||||
|
||||
12
pubspec.lock
12
pubspec.lock
@@ -133,10 +133,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: a222f231db4f822fc49e3b753674bda630e981873c84bf8604bceeb77fce0b24
|
||||
sha256: "77f8e81d22d2a07d0dee2c62e1dda71dc1da73bf43bb2d45af09727406167964"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.1.7"
|
||||
version: "10.1.9"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -174,14 +174,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.2"
|
||||
flutter_file_dialog:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_file_dialog
|
||||
sha256: "9344b8f07be6a1b6f9854b723fb0cf84a8094ba94761af1d213589d3cb087488"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
||||
@@ -27,8 +27,7 @@ dependencies:
|
||||
animations: ^2.0.11
|
||||
flutter_popup_card: ^0.0.5
|
||||
shared_preferences: ^2.2.2
|
||||
flutter_file_dialog: ^3.0.2
|
||||
file_picker: ^10.1.7
|
||||
file_picker: ^10.1.9
|
||||
http: ^1.2.1
|
||||
dio: ^5.4.1
|
||||
geocoding: ^3.0.0
|
||||
|
||||
Reference in New Issue
Block a user