From a902541591971fb9ee7467e4bdbff24e50dbc929 Mon Sep 17 00:00:00 2001 From: Nico Date: Sun, 24 Mar 2024 15:24:37 +0100 Subject: [PATCH] added last save location in settings --- Todo.txt | 6 ++--- lib/addCam/add_cam_main.dart | 48 +++++++++++++++++++----------------- lib/addCam/cam_widgets.dart | 40 ++++++++++++++++++++++++++++++ lib/l10n/app_de.arb | 4 ++- lib/l10n/app_en.arb | 10 ++++++++ lib/settings.dart | 36 ++++++++++++++++++++++++++- 6 files changed, 116 insertions(+), 28 deletions(-) diff --git a/Todo.txt b/Todo.txt index 6f751ac..3d4bcd5 100644 --- a/Todo.txt +++ b/Todo.txt @@ -1,9 +1,6 @@ todo: -add primary key maybe auch vorschläge aus templates in dropdown menüs anzeigen -beim nächsten schritt als template im englischen abändern -Überall absätze machen und textfeld größer wenn langer text gespeicherten ordner anzeigen zurückfeld in datenansicht überschriften für view cams @@ -22,6 +19,9 @@ eintrg in db wenn http response (in sent column) not to do: +Überall absätze machen und textfeld größer wenn langer text +beim nächsten schritt als template +add primary ke wenn alles ausgefüllt trotzdem als template speichern nach screenshots sortieren speichern funktion zum Abbrechen diff --git a/lib/addCam/add_cam_main.dart b/lib/addCam/add_cam_main.dart index 762cd45..e2d530e 100644 --- a/lib/addCam/add_cam_main.dart +++ b/lib/addCam/add_cam_main.dart @@ -237,33 +237,32 @@ class _AddCamMainState extends State { } Future showSaveOptionsDialog() async { - return - showDialog( + return showDialog( context: context, builder: (BuildContext context) { var dialogContext = context; return AlertDialog( title: Text(AppLocalizations.of(context)!.savemethod), actions: [ - - TextButton(onPressed: () async { - saveTemplate(); - Navigator.pushNamedAndRemoveUntil( - // ignore: use_build_context_synchronously - context, - '/home', - (route) => false); - }, child: Text(AppLocalizations.of(context)!.template)), - + TextButton( + onPressed: () async { + saveTemplate(); + Navigator.pushNamedAndRemoveUntil( + // ignore: use_build_context_synchronously + context, + '/home', + (route) => false); + }, + child: Text(AppLocalizations.of(context)!.template)), TextButton( onPressed: () async { saveFile(); _httpRequest(); - Navigator.pushNamedAndRemoveUntil( - // ignore: use_build_context_synchronously - context, - '/home', - (route) => false); + Navigator.pushNamedAndRemoveUntil( + // ignore: use_build_context_synchronously + context, + '/home', + (route) => false); }, child: Text(AppLocalizations.of(context)!.sendtoserver)), TextButton( @@ -278,9 +277,11 @@ class _AddCamMainState extends State { (route) => false); }, child: Text(AppLocalizations.of(context)!.saveasfile)), - TextButton(onPressed: () { - Navigator.pop(dialogContext); - }, child: Text(AppLocalizations.of(context)!.cancel)), + TextButton( + onPressed: () { + Navigator.pop(dialogContext); + }, + child: Text(AppLocalizations.of(context)!.cancel)), ], ); }); @@ -321,6 +322,8 @@ class _AddCamMainState extends State { Future saveFile() async { String? selectedDirectory = await FilePicker.platform.getDirectoryPath(); + SharedPreferences prefs = await SharedPreferences.getInstance(); + Map place = getPlace(); String jsonPlace = jsonEncode(place); @@ -328,6 +331,7 @@ class _AddCamMainState extends State { if (selectedDirectory == null) { return; } + await prefs.setString('saveDir', selectedDirectory); File file = File('$selectedDirectory/cam-${id.text}.txt'); @@ -340,7 +344,6 @@ class _AddCamMainState extends State { // checks if required fields are not empty. If one is the name will be returned List validateData() { - List emptyFields = []; Map fields = { @@ -649,8 +652,7 @@ class _AddCamMainState extends State { ), Align( alignment: Alignment.bottomLeft, - child: - SonstBem(sonstBemC: sonstBemC), + child: SonstBem(sonstBemC: sonstBemC), ), ], )), diff --git a/lib/addCam/cam_widgets.dart b/lib/addCam/cam_widgets.dart index 5b1fdac..a7e1feb 100644 --- a/lib/addCam/cam_widgets.dart +++ b/lib/addCam/cam_widgets.dart @@ -46,6 +46,8 @@ class _CamIdState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.camLink, enabledBorder: widget.id.text.isEmpty @@ -138,6 +140,8 @@ class _RudelState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.rudel, enabledBorder: widget.rudelC.text.isEmpty @@ -436,6 +440,8 @@ class _Adresse1State extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.adresse1, enabledBorder: widget.adresse1C.text.isEmpty @@ -526,6 +532,8 @@ class _Adresse2State extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.adresse2), controller: widget.adresse2C, @@ -604,6 +612,8 @@ class _Adresse3State extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.adresse3), controller: widget.adresse3C, @@ -693,6 +703,8 @@ class _BLandState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.bland, enabledBorder: widget.bLandC.text.isEmpty @@ -782,6 +794,8 @@ class _LkrState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.lkr, enabledBorder: widget.lkrC.text.isEmpty @@ -871,6 +885,8 @@ class _BeiOrtState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.beiort, enabledBorder: widget.beiOrtC.text.isEmpty @@ -960,6 +976,8 @@ class _OrtInfoState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.ortinfo, ), @@ -1160,6 +1178,8 @@ class _FFTypState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.fftyp, enabledBorder: widget.ffTypC.text.isEmpty @@ -1500,6 +1520,8 @@ class _KSchloNrState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.kschlonr), controller: widget.kSchloNrC, @@ -1755,6 +1777,8 @@ class _AuftragState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.auftrag), controller: widget.auftragC, @@ -1831,6 +1855,8 @@ class _KontAbspState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.kontabsp), controller: widget.kontAbspC, @@ -1907,6 +1933,8 @@ class _SonstBemState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.sonstbemerkungen), controller: widget.sonstBemC, @@ -1983,6 +2011,8 @@ class _FKontakt1State extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.fkontakt1), controller: widget.fKontakt1C, @@ -2059,6 +2089,8 @@ class _FKontakt2State extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.fkontakt2), controller: widget.fKontakt2C, @@ -2135,6 +2167,8 @@ class _FKontakt3State extends State { Expanded( flex: 3, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.fkontakt3), controller: widget.fKontakt3C, @@ -2211,6 +2245,8 @@ class _StandortState extends State { Expanded( flex: 3, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.altstort, enabledBorder: widget.standortC.text.isEmpty @@ -2385,6 +2421,8 @@ class _IntKommState extends State { Expanded( flex: 2, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.intkomm), controller: widget.intKommC, @@ -2461,6 +2499,8 @@ class _BetreuungState extends State { Expanded( flex: 3, child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, decoration: InputDecoration( hintText: AppLocalizations.of(context)!.betreuung), controller: widget.betreuungC, diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index c6e2595..c322b32 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -80,5 +80,7 @@ "viewplaces": "Standorte anzeigen", "showloginscreen": "Login-Bildschirm Anzeigen", "apiaddress": "Api-Adresse", - "benutzername": "Benutzername" + "benutzername": "Benutzername", + "filelocation": "Ort der zuletzt gespeicherten Datei:", + "open": "öffnen" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 94647ea..8db0779 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -388,6 +388,16 @@ "benutzername": "Username", "@benutzername": { "description": "intro screen benutzername hint" + }, + + "filelocation": "Location of the last saved file:", + "@filelocation": { + "description": "settings file location header" + }, + + "open": "Open", + "@open": { + "description": "open button" } } \ No newline at end of file diff --git a/lib/settings.dart b/lib/settings.dart index 3fc3000..a2f1796 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class Settings extends StatefulWidget { const Settings({super.key}); @@ -8,8 +10,40 @@ class Settings extends StatefulWidget { } class _SettingsState extends State { + + + Future _getSaveDir() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + + final String saveDir = prefs.getString('saveDir') ?? ""; + + return saveDir; + } + + + + @override Widget build(BuildContext context) { - return const Placeholder(); + return Scaffold( + appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings),), + body: Center( + child: Column( + children: [ + Text(AppLocalizations.of(context)!.filelocation, style: const TextStyle(fontSize: 20),), + FutureBuilder(future: _getSaveDir(), builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return Text(snapshot.data ?? ""); + } else { + return const CircularProgressIndicator(); + } + }), + ElevatedButton(onPressed: () { + + }, child: Text(AppLocalizations.of(context)!.open)) + ], + ), + ), + ); } } \ No newline at end of file