simrbrief integration
This commit is contained in:
@@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
|
||||
import 'comparison_page.dart';
|
||||
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';
|
||||
|
||||
class ExpectationInputPage extends StatefulWidget {
|
||||
final bool isDarkMode;
|
||||
@@ -30,6 +32,7 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
|
||||
TextEditingController();
|
||||
final TextEditingController _expectedFrequencyController =
|
||||
TextEditingController();
|
||||
final TextEditingController _simbriefIdController = TextEditingController();
|
||||
|
||||
// FocusNodes for each field
|
||||
final FocusNode _clearanceLimitFocusNode = FocusNode();
|
||||
@@ -53,6 +56,42 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchSimbriefData() async {
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse('https://www.simbrief.com/api/xml.fetcher.php?userid=${_simbriefIdController.text}&json=1'),
|
||||
);
|
||||
|
||||
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 = '';
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('SimBrief Daten erfolgreich geladen')),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Fehler beim Laden der SimBrief Daten: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToComparisonPage() {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
Navigator.push(
|
||||
@@ -225,6 +264,27 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _simbriefIdController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'SimBrief Pilot ID',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ElevatedButton(
|
||||
onPressed: _fetchSimbriefData,
|
||||
child: const Text('Lade SimBrief Daten'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
|
||||
Reference in New Issue
Block a user