diff --git a/buildandpush.sh b/buildandpush.sh new file mode 100644 index 0000000..a6bc18b --- /dev/null +++ b/buildandpush.sh @@ -0,0 +1 @@ +flutter build web --release && docker buildx build --platform linux/amd64 -t git.degnedict.de/bene/ifrbuddy --push . \ No newline at end of file diff --git a/lib/screens/expectation_input_page.dart b/lib/screens/expectation_input_page.dart index 3648d80..913ed2b 100644 --- a/lib/screens/expectation_input_page.dart +++ b/lib/screens/expectation_input_page.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer_const_constructors + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'comparison_page.dart'; @@ -5,6 +7,7 @@ import 'final_clearance_page.dart'; // Import final clearance page import '../utils/frequency_input_formatter.dart'; // Ensure this path is correct import 'package:http/http.dart' as http; import 'dart:convert'; +import 'package:shared_preferences/shared_preferences.dart'; class ExpectationInputPage extends StatefulWidget { final bool isDarkMode; @@ -41,6 +44,38 @@ class ExpectationInputPageState extends State { final FocusNode _frequencyFocusNode = FocusNode(); final FocusNode _squawkFocusNode = FocusNode(); + // Neue Variablen + bool _saveSimbriefId = false; + static const String _simbriefIdKey = 'simbrief_id'; + + @override + void initState() { + super.initState(); + _loadSavedSimbriefId(); + } + + // Methode zum Laden der gespeicherten ID + Future _loadSavedSimbriefId() async { + final prefs = await SharedPreferences.getInstance(); + final savedId = prefs.getString(_simbriefIdKey); + if (savedId != null) { + setState(() { + _simbriefIdController.text = savedId; + _saveSimbriefId = true; + }); + } + } + + // Methode zum Speichern der ID + Future _saveSimbriefIdToPrefs() async { + final prefs = await SharedPreferences.getInstance(); + if (_saveSimbriefId) { + await prefs.setString(_simbriefIdKey, _simbriefIdController.text); + } else { + await prefs.remove(_simbriefIdKey); + } + } + @override void dispose() { _expectedClearanceLimitController.dispose(); @@ -58,34 +93,36 @@ class ExpectationInputPageState extends State { Future _fetchSimbriefData() async { try { + if (_saveSimbriefId) { + await _saveSimbriefIdToPrefs(); + } final response = await http.get( Uri.parse('https://www.simbrief.com/api/xml.fetcher.php?userid=${_simbriefIdController.text}&json=1'), ); + // Prüfe ob Widget noch mounted ist + if (!mounted) return; + if (response.statusCode == 200) { final data = json.decode(response.body); - // Debug-Ausgabe - print('SimBrief API Response: ${response.body}'); - - // Extrahiere die komplette Route String fullRoute = data['general']['route'] ?? ''; - // Hole nur den ersten Teil der Route (SID) String sid = fullRoute.split(' ').first; setState(() { _expectedClearanceLimitController.text = data['destination']['icao_code'] ?? ''; _expectedRouteController.text = sid; - // Altitude und Frequency bleiben leer _expectedAltitudeController.text = ''; _expectedFrequencyController.text = ''; }); + if (!mounted) return; // Zweiter Check vor ScaffoldMessenger ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('SimBrief Daten erfolgreich geladen')), ); } } catch (e) { + if (!mounted) return; // Check vor Error-SnackBar ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Fehler beim Laden der SimBrief Daten: $e')), ); @@ -273,6 +310,20 @@ class ExpectationInputPageState extends State { ), ), const SizedBox(height: 10), + Row( + children: [ + Checkbox( + value: _saveSimbriefId, + onChanged: (bool? value) { + setState(() { + _saveSimbriefId = value ?? false; + }); + _saveSimbriefIdToPrefs(); + }, + ), + const Text('Save SimBrief ID'), + ], + ), SizedBox( width: double.infinity, child: ElevatedButton( @@ -303,7 +354,7 @@ class ExpectationInputPageState extends State { ), const SizedBox(height: 10), const Text( - 'Enter your expected clearance information below. ' + 'Enter your expected clearance information below (Or use the SimBrief import). ' 'Use the listening page or skip to the readback page.', style: TextStyle(fontSize: 16), textAlign: TextAlign.left, diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements index dddb8a3..8cb7022 100644 --- a/macos/Runner/DebugProfile.entitlements +++ b/macos/Runner/DebugProfile.entitlements @@ -8,5 +8,7 @@ com.apple.security.network.server + com.apple.security.network.client + diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements index 852fa1a..8b8899f 100644 --- a/macos/Runner/Release.entitlements +++ b/macos/Runner/Release.entitlements @@ -4,5 +4,8 @@ com.apple.security.app-sandbox + com.apple.security.network.client + + com.apple.security.network.serverw