outsourced all methods and dialogs as far as possible (I think)
This commit is contained in:
@@ -18,7 +18,7 @@ class HomePage extends StatelessWidget {
|
|||||||
File file = File(result.files.single.path!);
|
File file = File(result.files.single.path!);
|
||||||
String content = await file.readAsString();
|
String content = await file.readAsString();
|
||||||
|
|
||||||
HttpRequest().httpRequest(content);
|
HttpRequest.httpRequest(saveDataString: content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:fforte/screens/Excursion/excursion_main.dart';
|
import 'package:fforte/screens/excursion/excursion_main.dart';
|
||||||
import 'package:fforte/screens/addCam/add_cam_main.dart';
|
import 'package:fforte/screens/addCam/add_cam_main.dart';
|
||||||
import 'package:fforte/screens/intro_screen.dart';
|
import 'package:fforte/screens/intro_screen.dart';
|
||||||
import 'package:fforte/screens/settings.dart';
|
import 'package:fforte/screens/settings.dart';
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:fforte/enums/databases.dart';
|
import 'package:fforte/enums/databases.dart';
|
||||||
import 'package:fforte/screens/addCam/cam_widgets.dart';
|
import 'package:fforte/screens/addCam/cam_widgets.dart';
|
||||||
import 'package:fforte/methods/place_db_helper.dart';
|
import 'package:fforte/screens/helper/dialog_helper.dart';
|
||||||
|
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
||||||
import 'package:fforte/screens/sharedMethods/http_request.dart';
|
import 'package:fforte/screens/sharedMethods/http_request.dart';
|
||||||
import 'package:fforte/screens/addCam/exceptions/location_disabled_exception.dart';
|
import 'package:fforte/screens/addCam/exceptions/location_disabled_exception.dart';
|
||||||
import 'package:fforte/screens/addCam/exceptions/location_forbidden_exception.dart';
|
import 'package:fforte/screens/addCam/exceptions/location_forbidden_exception.dart';
|
||||||
import 'package:fforte/screens/addCam/services/geolocator_service.dart';
|
import 'package:fforte/screens/addCam/services/geolocator_service.dart';
|
||||||
import 'package:fforte/screens/sharedMethods/save_file.dart';
|
import 'package:fforte/screens/sharedMethods/save_file.dart';
|
||||||
|
import 'package:fforte/screens/sharedMethods/save_main_entry.dart';
|
||||||
import 'package:fforte/screens/sharedMethods/save_template.dart';
|
import 'package:fforte/screens/sharedMethods/save_template.dart';
|
||||||
import 'package:fforte/screens/sharedWidgets/datum.dart';
|
import 'package:fforte/screens/sharedWidgets/datum.dart';
|
||||||
import 'package:fforte/screens/sharedWidgets/var_text_field.dart';
|
import 'package:fforte/screens/sharedWidgets/var_text_field.dart';
|
||||||
@@ -166,9 +167,9 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
GeolocatorService.deteterminePosition()
|
GeolocatorService.deteterminePosition()
|
||||||
.then((result) => currentPosition = result);
|
.then((result) => currentPosition = result);
|
||||||
} on LocationDisabledException {
|
} on LocationDisabledException {
|
||||||
showSnackBarMessage(AppLocalizations.of(context)!.locationDisabled);
|
SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.locationDisabled);
|
||||||
} on LocationForbiddenException {
|
} on LocationForbiddenException {
|
||||||
showSnackBarMessage(AppLocalizations.of(context)!.locationForbidden);
|
SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.locationForbidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a template is edited this fills in the existing values
|
// If a template is edited this fills in the existing values
|
||||||
@@ -212,207 +213,203 @@ class _AddCamMainState extends State<AddCamMain> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSnackBarMessage(String message) {
|
// void showSnackBarMessage(String message) {
|
||||||
ScaffoldMessenger.of(context)
|
// ScaffoldMessenger.of(context)
|
||||||
.showSnackBar(SnackBar(content: Text(message)));
|
// .showSnackBar(SnackBar(content: Text(message)));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Function to show the dialog where the user has to choose if he want to safe his values as a template
|
// Function to show the dialog where the user has to choose if he want to safe his values as a template
|
||||||
Future<void> showTemplateDialog(List<String> emptyField) async {
|
// Future<void> showTemplateDialog(List<String> emptyField) async {
|
||||||
return showDialog(
|
// return showDialog(
|
||||||
context: context,
|
// context: context,
|
||||||
barrierDismissible: false,
|
// barrierDismissible: false,
|
||||||
builder: (BuildContext context) {
|
// builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
// return AlertDialog(
|
||||||
title: Text(AppLocalizations.of(context)!.fieldEmpty),
|
// title: Text(AppLocalizations.of(context)!.fieldEmpty),
|
||||||
content: SingleChildScrollView(
|
// content: SingleChildScrollView(
|
||||||
child: ListBody(children: <Widget>[Text(emptyField.join("; "))]),
|
// child: ListBody(children: <Widget>[Text(emptyField.join("; "))]),
|
||||||
),
|
// ),
|
||||||
actions: <Widget>[
|
// actions: <Widget>[
|
||||||
TextButton(
|
// TextButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
Navigator.of(context).pop();
|
// Navigator.of(context).pop();
|
||||||
},
|
// },
|
||||||
child: Text(AppLocalizations.of(context)!.cancel)),
|
// child: Text(AppLocalizations.of(context)!.cancel)),
|
||||||
TextButton(
|
// TextButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
saveTemplate(
|
// saveTemplate(
|
||||||
getPlace(), DatabasesEnum.place, widget.isTemplate);
|
// getPlace(), DatabasesEnum.place, widget.isTemplate);
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
// Navigator.pushNamedAndRemoveUntil(
|
||||||
context, '/home', (route) => false);
|
// context, '/home', (route) => false);
|
||||||
},
|
// },
|
||||||
child: Text(AppLocalizations.of(context)!.template))
|
// child: Text(AppLocalizations.of(context)!.template))
|
||||||
],
|
// ],
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
Future<dynamic> _showServerErrorDialog() {
|
// Future<dynamic> _showServerErrorDialog() {
|
||||||
bool isLoading = false;
|
// bool isLoading = false;
|
||||||
|
//
|
||||||
|
// return showDialog(
|
||||||
|
// context: context,
|
||||||
|
// builder: (context) {
|
||||||
|
// return StatefulBuilder(
|
||||||
|
// builder: (BuildContext context, StateSetter setState) {
|
||||||
|
// return AlertDialog(
|
||||||
|
// title: Text(AppLocalizations.of(context)!.servererrortitle),
|
||||||
|
// content: isLoading
|
||||||
|
// ? const SizedBox(
|
||||||
|
// height: 100,
|
||||||
|
// child: Center(child: CircularProgressIndicator()))
|
||||||
|
// : null,
|
||||||
|
// actions: [
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () async {
|
||||||
|
// setState(() => isLoading = true);
|
||||||
|
// int errorCode = await HttpRequest.httpRequest(saveDataMap: getPlace());
|
||||||
|
// setState(() => isLoading = false);
|
||||||
|
//
|
||||||
|
// if (errorCode != 201 && context.mounted) {
|
||||||
|
// _showServerErrorDialog();
|
||||||
|
// } else {
|
||||||
|
// if (context.mounted) Navigator.pop(context);
|
||||||
|
// // saveData(true);
|
||||||
|
// SaveMainEntryMethod.saveEntry(entryData: getPlace(), isTemplate: widget.isTemplate);
|
||||||
|
// _showSuccessDialog();
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.sendagain)),
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () {
|
||||||
|
// Navigator.pop(context);
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.cancel))
|
||||||
|
// ],
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
return showDialog(
|
// Future<void> showSaveOptionsDialog() async {
|
||||||
context: context,
|
// bool isLoading = false;
|
||||||
builder: (context) {
|
//
|
||||||
return StatefulBuilder(
|
// return showDialog(
|
||||||
builder: (BuildContext context, StateSetter setState) {
|
// context: context,
|
||||||
return AlertDialog(
|
// barrierDismissible:
|
||||||
title: Text(AppLocalizations.of(context)!.servererrortitle),
|
// false, // Verhindert das Schließen des Dialogs durch den Benutzer
|
||||||
content: isLoading
|
// builder: (BuildContext context) {
|
||||||
? const SizedBox(
|
// return StatefulBuilder(
|
||||||
height: 100,
|
// builder: (context, setState) {
|
||||||
child: Center(child: CircularProgressIndicator()))
|
// return AlertDialog(
|
||||||
: null,
|
// title: isLoading
|
||||||
actions: [
|
// ? Text(AppLocalizations.of(context)!.loading)
|
||||||
if (!isLoading)
|
// : Text(AppLocalizations.of(context)!.savemethod),
|
||||||
TextButton(
|
// content: isLoading
|
||||||
onPressed: () async {
|
// ? const SizedBox(
|
||||||
setState(() => isLoading = true);
|
// height: 100,
|
||||||
int errorCode = await _httpRequest();
|
// child: Center(child: CircularProgressIndicator()))
|
||||||
setState(() => isLoading = false);
|
// : null,
|
||||||
|
// actions: [
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () async {
|
||||||
|
// setState(() => isLoading = true);
|
||||||
|
// saveTemplate(getPlace(), DatabasesEnum.place,
|
||||||
|
// widget.isTemplate);
|
||||||
|
// Navigator.pushNamedAndRemoveUntil(
|
||||||
|
// context, '/home', (route) => false);
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.template)),
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () async {
|
||||||
|
// setState(() => isLoading = true);
|
||||||
|
// int errorCode = await HttpRequest.httpRequest(saveDataMap: getPlace());
|
||||||
|
// setState(() => isLoading = false);
|
||||||
|
//
|
||||||
|
// if (errorCode != 201 || !context.mounted) {
|
||||||
|
// SaveMainEntryMethod.saveEntry(entryData: getPlace(), isTemplate: widget.isTemplate);
|
||||||
|
// if (context.mounted) DialogHelper.showServerErrorDialog(context, getPlace(), widget.isTemplate);
|
||||||
|
// } else {
|
||||||
|
// SaveMainEntryMethod.saveEntry(entryData: getPlace(), isTemplate: widget.isTemplate, sent: true);
|
||||||
|
// _showSuccessDialog();
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// child:
|
||||||
|
// Text(AppLocalizations.of(context)!.sendtoserver)),
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () async {
|
||||||
|
// setState(() => isLoading = true);
|
||||||
|
// SaveMainEntryMethod.saveEntry(entryData: getPlace(), isTemplate: widget.isTemplate);
|
||||||
|
// _saveFile();
|
||||||
|
// setState(() => isLoading = false);
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.saveasfile)),
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () {
|
||||||
|
// SaveMainEntryMethod.saveEntry(entryData: getPlace(), isTemplate: widget.isTemplate);
|
||||||
|
// Navigator.pushNamedAndRemoveUntil(
|
||||||
|
// context, '/home', (route) => false);
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.justsave)),
|
||||||
|
// if (!isLoading)
|
||||||
|
// TextButton(
|
||||||
|
// onPressed: () {
|
||||||
|
// Navigator.pop(context);
|
||||||
|
// },
|
||||||
|
// child: Text(AppLocalizations.of(context)!.cancel)),
|
||||||
|
// ],
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
if (errorCode != 201 && context.mounted) {
|
// Future<void> _showSuccessDialog() async {
|
||||||
_showServerErrorDialog();
|
// return showDialog(
|
||||||
} else {
|
// context: context,
|
||||||
if (context.mounted) Navigator.pop(context);
|
// builder: (context) {
|
||||||
saveData(true);
|
// return AlertDialog(
|
||||||
_showSuccessDialog();
|
// title: Text(AppLocalizations.of(context)!.successful),
|
||||||
}
|
// actions: [
|
||||||
},
|
// TextButton(
|
||||||
child: Text(AppLocalizations.of(context)!.sendagain)),
|
// onPressed: () {
|
||||||
if (!isLoading)
|
// Navigator.pushNamedAndRemoveUntil(
|
||||||
TextButton(
|
// context, '/home', (route) => false);
|
||||||
onPressed: () {
|
// },
|
||||||
Navigator.pop(context);
|
// child: Text(AppLocalizations.of(context)!.continueB))
|
||||||
},
|
// ],
|
||||||
child: Text(AppLocalizations.of(context)!.cancel))
|
// );
|
||||||
],
|
// });
|
||||||
);
|
// }
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> showSaveOptionsDialog() async {
|
// Future<int> _httpRequest() async {
|
||||||
bool isLoading = false;
|
// Map<String, dynamic> place = getPlace();
|
||||||
|
//
|
||||||
|
// HttpRequest method = HttpRequest();
|
||||||
|
//
|
||||||
|
// await method.httpRequest(jsonEncode(place));
|
||||||
|
//
|
||||||
|
// return method.errorCode;
|
||||||
|
// }
|
||||||
|
|
||||||
return showDialog(
|
// void _saveFile() {
|
||||||
context: context,
|
// try {
|
||||||
barrierDismissible:
|
// SaveMainEntryMethod.saveEntry(
|
||||||
false, // Verhindert das Schließen des Dialogs durch den Benutzer
|
// getPlace(), AppLocalizations.of(context)!.justplace, standortC.text);
|
||||||
builder: (BuildContext context) {
|
// // TODO change to fileSaved. Also in SaveFileMethod class
|
||||||
return StatefulBuilder(
|
// SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.savefilefailed);
|
||||||
builder: (context, setState) {
|
// Navigator.pushNamedAndRemoveUntil(context, '/home', (route) => false);
|
||||||
return AlertDialog(
|
// } catch (e) {
|
||||||
title: isLoading
|
// SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.savefilefailed);
|
||||||
? Text(AppLocalizations.of(context)!.loading)
|
// }
|
||||||
: Text(AppLocalizations.of(context)!.savemethod),
|
// }
|
||||||
content: isLoading
|
|
||||||
? const SizedBox(
|
|
||||||
height: 100,
|
|
||||||
child: Center(child: CircularProgressIndicator()))
|
|
||||||
: null,
|
|
||||||
actions: [
|
|
||||||
if (!isLoading)
|
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
setState(() => isLoading = true);
|
|
||||||
saveTemplate(getPlace(), DatabasesEnum.place,
|
|
||||||
widget.isTemplate);
|
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
|
||||||
context, '/home', (route) => false);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.template)),
|
|
||||||
if (!isLoading)
|
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
setState(() => isLoading = true);
|
|
||||||
int errorCode = await _httpRequest();
|
|
||||||
setState(() => isLoading = false);
|
|
||||||
|
|
||||||
if (errorCode != 201 || !context.mounted) {
|
|
||||||
saveData();
|
|
||||||
_showServerErrorDialog();
|
|
||||||
} else {
|
|
||||||
saveData(true);
|
|
||||||
_showSuccessDialog();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child:
|
|
||||||
Text(AppLocalizations.of(context)!.sendtoserver)),
|
|
||||||
if (!isLoading)
|
|
||||||
TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
setState(() => isLoading = true);
|
|
||||||
saveData();
|
|
||||||
_saveFile();
|
|
||||||
setState(() => isLoading = false);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.saveasfile)),
|
|
||||||
if (!isLoading)
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
saveData();
|
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
|
||||||
context, '/home', (route) => false);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.justsave)),
|
|
||||||
if (!isLoading)
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.cancel)),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _showSuccessDialog() async {
|
|
||||||
return showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: Text(AppLocalizations.of(context)!.successful),
|
|
||||||
actions: [
|
|
||||||
/* TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.back)), */
|
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
|
||||||
context, '/home', (route) => false);
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.continueB))
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<int> _httpRequest() async {
|
|
||||||
Map<String, dynamic> place = getPlace();
|
|
||||||
|
|
||||||
HttpRequest method = HttpRequest();
|
|
||||||
|
|
||||||
await method.httpRequest(jsonEncode(place));
|
|
||||||
|
|
||||||
return method.errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _saveFile() {
|
|
||||||
try {
|
|
||||||
saveFile(
|
|
||||||
getPlace(), AppLocalizations.of(context)!.justplace, standortC.text);
|
|
||||||
// TODO change to fileSaved
|
|
||||||
showSnackBarMessage(AppLocalizations.of(context)!.savefilefailed);
|
|
||||||
Navigator.pushNamedAndRemoveUntil(context, '/home', (route) => false);
|
|
||||||
} catch (e) {
|
|
||||||
showSnackBarMessage(AppLocalizations.of(context)!.savefilefailed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// checks if required fields are not empty. If one is the name will be returned
|
// checks if required fields are not empty. If one is the name will be returned
|
||||||
// TODO rewrite
|
// TODO rewrite
|
||||||
@@ -469,21 +466,21 @@ child: Text(AppLocalizations.of(context)!.back)), */
|
|||||||
// TODO FINISHED HERE
|
// TODO FINISHED HERE
|
||||||
// If the user has filled all needed values this function will be called to safe them in the database
|
// If the user has filled all needed values this function will be called to safe them in the database
|
||||||
// * also creates a json string to send it to the server later
|
// * also creates a json string to send it to the server later
|
||||||
void saveData([bool sent = false]) async {
|
// void saveData([bool sent = false]) async {
|
||||||
var placeDB = PlaceDBHelper();
|
// var placeDB = PlaceDBHelper();
|
||||||
Map<String, dynamic> place = getPlace();
|
// Map<String, dynamic> place = getPlace();
|
||||||
|
//
|
||||||
// Get the ID of the newly added or updated place
|
// // Get the ID of the newly added or updated place
|
||||||
int newPlaceId = await placeDB.addMainEntry(place);
|
// int newPlaceId = await placeDB.addMainEntry(place);
|
||||||
|
//
|
||||||
if (sent == true) {
|
// if (sent == true) {
|
||||||
placeDB.updateSent(newPlaceId); // Update 'Sent' using the correct ID
|
// placeDB.updateSent(newPlaceId); // Update 'Sent' using the correct ID
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (widget.isTemplate) {
|
// if (widget.isTemplate) {
|
||||||
await placeDB.deleteTemplateById(cid.text);
|
// await placeDB.deleteTemplateById(cid.text);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// The widget tree which gets the shown widget from the ./cam_widgets.dart file
|
// The widget tree which gets the shown widget from the ./cam_widgets.dart file
|
||||||
// The names of the widgets should be self-explaining
|
// The names of the widgets should be self-explaining
|
||||||
@@ -922,10 +919,10 @@ child: Text(AppLocalizations.of(context)!.back)), */
|
|||||||
Navigator.pushNamedAndRemoveUntil(
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
context, '/home', (route) => false);
|
context, '/home', (route) => false);
|
||||||
} else if (empty == true) {
|
} else if (empty == true) {
|
||||||
showTemplateDialog(emptyFields);
|
DialogHelper.showTemplateDialog(context, emptyFields, getPlace() );
|
||||||
return;
|
return;
|
||||||
} else if (empty == false) {
|
} else if (empty == false) {
|
||||||
await showSaveOptionsDialog();
|
await DialogHelper.showSaveOptionsDialog(context, getPlace(), widget.isTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import 'package:animations/animations.dart';
|
import 'package:animations/animations.dart';
|
||||||
import 'package:fforte/enums/databases.dart';
|
import 'package:fforte/enums/databases.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/anzahlen.dart';
|
import 'package:fforte/screens/excursion/widgets/anzahlen.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/bima_nutzer.dart';
|
import 'package:fforte/screens/excursion/widgets/bima_nutzer.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/hinweise.dart';
|
import 'package:fforte/screens/excursion/widgets/hinweise.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/hund_u_leine.dart';
|
import 'package:fforte/screens/excursion/widgets/hund_u_leine.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/letzter_niederschlag.dart';
|
import 'package:fforte/screens/excursion/widgets/letzter_niederschlag.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/spur_gefunden.dart';
|
import 'package:fforte/screens/excursion/widgets/spur_gefunden.dart';
|
||||||
import 'package:fforte/screens/Excursion/widgets/strecke_u_spurbedingungen.dart';
|
import 'package:fforte/screens/excursion/widgets/strecke_u_spurbedingungen.dart';
|
||||||
import 'package:fforte/screens/sharedWidgets/datum.dart';
|
import 'package:fforte/screens/sharedWidgets/datum.dart';
|
||||||
import 'package:fforte/screens/sharedWidgets/var_text_field.dart';
|
import 'package:fforte/screens/sharedWidgets/var_text_field.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
206
lib/screens/helper/dialog_helper.dart
Normal file
206
lib/screens/helper/dialog_helper.dart
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
import 'package:fforte/enums/databases.dart';
|
||||||
|
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
||||||
|
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:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class DialogHelper {
|
||||||
|
// Function to show the dialog where the user has to choose if he want to safe his values as a template
|
||||||
|
static Future<void> showTemplateDialog(BuildContext context,
|
||||||
|
List<String> emptyField, Map<String, dynamic> saveData) async {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.fieldEmpty),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: ListBody(children: <Widget>[Text(emptyField.join("; "))]),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel)),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
saveTemplate(saveData, DatabasesEnum.place, true);
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context, '/home', (route) => false);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.template))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<dynamic> showServerErrorDialog(
|
||||||
|
BuildContext context, Map<String, dynamic> saveData, bool isTemplate) {
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return StatefulBuilder(
|
||||||
|
builder: (BuildContext context, StateSetter setState) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.servererrortitle),
|
||||||
|
content: isLoading
|
||||||
|
? const SizedBox(
|
||||||
|
height: 100,
|
||||||
|
child: Center(child: CircularProgressIndicator()))
|
||||||
|
: null,
|
||||||
|
actions: [
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() => isLoading = true);
|
||||||
|
int errorCode = await HttpRequest.httpRequest(
|
||||||
|
saveDataMap: saveData);
|
||||||
|
setState(() => isLoading = false);
|
||||||
|
|
||||||
|
if (errorCode != 201 && context.mounted) {
|
||||||
|
showServerErrorDialog(
|
||||||
|
context, saveData, isTemplate);
|
||||||
|
} else {
|
||||||
|
if (context.mounted) Navigator.pop(context);
|
||||||
|
// saveData(true);
|
||||||
|
SaveMainEntryMethod.saveEntry(
|
||||||
|
entryData: saveData, isTemplate: isTemplate);
|
||||||
|
if (context.mounted) showSuccessDialog(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.sendagain)),
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> showSaveOptionsDialog(BuildContext context,
|
||||||
|
Map<String, dynamic> saveData, bool isTemplate) async {
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible:
|
||||||
|
false, // Verhindert das Schließen des Dialogs durch den Benutzer
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: isLoading
|
||||||
|
? Text(AppLocalizations.of(context)!.loading)
|
||||||
|
: Text(AppLocalizations.of(context)!.savemethod),
|
||||||
|
content: isLoading
|
||||||
|
? const SizedBox(
|
||||||
|
height: 100,
|
||||||
|
child: Center(child: CircularProgressIndicator()))
|
||||||
|
: null,
|
||||||
|
actions: [
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() => isLoading = true);
|
||||||
|
saveTemplate(
|
||||||
|
saveData, DatabasesEnum.place, isTemplate);
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context, '/home', (route) => false);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.template)),
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() => isLoading = true);
|
||||||
|
int errorCode = await HttpRequest.httpRequest(
|
||||||
|
saveDataMap: saveData);
|
||||||
|
setState(() => isLoading = false);
|
||||||
|
|
||||||
|
if (errorCode != 201 || !context.mounted) {
|
||||||
|
SaveMainEntryMethod.saveEntry(
|
||||||
|
entryData: saveData, isTemplate: isTemplate);
|
||||||
|
if (context.mounted) {
|
||||||
|
DialogHelper.showServerErrorDialog(
|
||||||
|
context, saveData, isTemplate);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SaveMainEntryMethod.saveEntry(
|
||||||
|
entryData: saveData,
|
||||||
|
isTemplate: isTemplate,
|
||||||
|
sent: true);
|
||||||
|
showSuccessDialog(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child:
|
||||||
|
Text(AppLocalizations.of(context)!.sendtoserver)),
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() => isLoading = true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
SaveMainEntryMethod.saveEntry(
|
||||||
|
entryData: saveData, isTemplate: isTemplate);
|
||||||
|
SaveFileMethod.saveFile(
|
||||||
|
saveData,
|
||||||
|
AppLocalizations.of(context)!.savefilefailed,
|
||||||
|
saveData["CID"]);
|
||||||
|
setState(() => isLoading = false);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
SnackBarHelper.showSnackBarMessage(context, AppLocalizations.of(context)!.savefilefailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.saveasfile)),
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
SaveMainEntryMethod.saveEntry(
|
||||||
|
entryData: saveData, isTemplate: isTemplate);
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context, '/home', (route) => false);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.justsave)),
|
||||||
|
if (!isLoading)
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> showSuccessDialog(BuildContext context) async {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.successful),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context, '/home', (route) => false);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.continueB))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
8
lib/screens/helper/snack_bar_helper.dart
Normal file
8
lib/screens/helper/snack_bar_helper.dart
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SnackBarHelper {
|
||||||
|
static void showSnackBarMessage(BuildContext context, String message) {
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(SnackBar(content: Text(message)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,37 +6,26 @@ import 'package:dio/dio.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class HttpRequest {
|
class HttpRequest {
|
||||||
int? _errorCode;
|
static Future<int> httpRequest({Map<String, dynamic>? saveDataMap, String? saveDataString}) async {
|
||||||
|
|
||||||
|
|
||||||
int get errorCode => _errorCode ?? 0;
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> httpRequest(String httpData) async {
|
|
||||||
// print(jsonEncode(place));
|
// print(jsonEncode(place));
|
||||||
|
|
||||||
final dio = Dio();
|
final dio = Dio();
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
dio.options
|
dio.options
|
||||||
..connectTimeout = const Duration(seconds: 5)
|
..connectTimeout = const Duration(seconds: 5)
|
||||||
..receiveTimeout = const Duration(seconds: 5)
|
..receiveTimeout = const Duration(seconds: 5)
|
||||||
..responseType = ResponseType.plain;
|
..responseType = ResponseType.plain;
|
||||||
Response response = Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
|
Response response =
|
||||||
|
Response(requestOptions: RequestOptions(path: ''), statusCode: 400);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await dio.post(prefs.getString('apiAddress') ?? "",
|
response = await dio.post(prefs.getString('apiAddress') ?? "",
|
||||||
data: jsonEncode(httpData));
|
data: saveDataMap == null ? saveDataString : jsonEncode(saveDataMap));
|
||||||
|
|
||||||
// ignore: unused_catch_clause
|
return response.statusCode!;
|
||||||
} on DioException catch (e) {
|
} on DioException {
|
||||||
_errorCode = response.statusCode;
|
return response.statusCode ?? 400;
|
||||||
print('is hier. var: $_errorCode');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
_errorCode = response.statusCode;
|
|
||||||
print('is hier 2. var: $_errorCode');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,18 +4,19 @@ import 'dart:io';
|
|||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
Future<void> saveFile(
|
class SaveFileMethod {
|
||||||
Map place, String fileNameLocalization, String placeID) async {
|
static Future<void> saveFile(Map<String, dynamic> place, String fileNameLocalization, String placeID) async {
|
||||||
String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
String? selectedDirectory = await FilePicker.platform.getDirectoryPath();
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
String jsonPlace = jsonEncode(place);
|
String jsonPlace = jsonEncode(place);
|
||||||
|
|
||||||
if (selectedDirectory == null) {
|
if (selectedDirectory == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
await prefs.setString('saveDir', selectedDirectory);
|
||||||
|
|
||||||
|
File file = File('$selectedDirectory/$fileNameLocalization-$placeID.txt');
|
||||||
|
|
||||||
|
await file.writeAsString(jsonPlace);
|
||||||
}
|
}
|
||||||
await prefs.setString('saveDir', selectedDirectory);
|
|
||||||
|
|
||||||
File file = File('$selectedDirectory/$fileNameLocalization-$placeID.txt');
|
|
||||||
|
|
||||||
await file.writeAsString(jsonPlace);
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
lib/screens/sharedMethods/save_main_entry.dart
Normal file
21
lib/screens/sharedMethods/save_main_entry.dart
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:fforte/methods/place_db_helper.dart';
|
||||||
|
|
||||||
|
class SaveMainEntryMethod {
|
||||||
|
static void saveEntry(
|
||||||
|
{required Map<String, dynamic> entryData,
|
||||||
|
required bool isTemplate,
|
||||||
|
bool sent = false}) async {
|
||||||
|
var placeDB = PlaceDBHelper();
|
||||||
|
|
||||||
|
// Get the ID of the newly added or updated place
|
||||||
|
int newPlaceId = await placeDB.addMainEntry(entryData);
|
||||||
|
|
||||||
|
if (sent == true) {
|
||||||
|
placeDB.updateSent(newPlaceId); // Update 'Sent' using the correct ID
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTemplate) {
|
||||||
|
await placeDB.deleteTemplateById(entryData["CID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user