This commit is contained in:
2024-10-19 14:17:37 +02:00
parent 9f98189983
commit ec76a028cb
53 changed files with 495 additions and 607 deletions

View File

@@ -12,7 +12,8 @@ class ComparisonPage extends StatefulWidget {
final bool isDarkMode;
final Function toggleDarkMode;
const ComparisonPage({super.key,
const ComparisonPage({
super.key,
required this.expectedClearanceLimit,
required this.expectedRoute,
required this.expectedAltitude,
@@ -159,130 +160,130 @@ class ComparisonPageState extends State<ComparisonPage> {
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('IFR Buddy'), // Global title
actions: [
IconButton(
icon: Icon(widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
onPressed: () {
widget.toggleDarkMode();
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
// Explanation Text Card
const Card(
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Use this Page while receiving your clearance. The arrow button copies the excpected value. Same if left empty.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
),
),
const SizedBox(height: 16),
// Main content side-by-side
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Expected Clearance Column
Expanded(
child: Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Expected',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
const Divider(),
buildExpectedClearanceField('Clearance Limit', widget.expectedClearanceLimit),
buildExpectedClearanceField('Route', widget.expectedRoute),
buildExpectedClearanceField('Altitude', widget.expectedAltitude),
buildExpectedClearanceField('Transponder (Squawk)', widget.expectedSquawk),
buildExpectedClearanceField('Frequency', widget.expectedFrequency),
],
),
),
),
),
const SizedBox(width: 16), // Spacer between columns
// Actual Clearance Column
Expanded(
child: Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Clearance',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
const Divider(),
buildActualClearanceField(
'Clearance Limit',
_actualClearanceLimitController,
widget.expectedClearanceLimit,
),
buildActualClearanceField(
'Route',
_actualRouteController,
widget.expectedRoute,
),
buildActualClearanceField(
'Altitude',
_actualAltitudeController,
widget.expectedAltitude,
focusNode: _actualAltitudeFocusNode,
),
buildActualClearanceField(
'Transponder (Squawk)',
_actualSquawkController,
widget.expectedSquawk,
formatterList: [
FilteringTextInputFormatter.allow(RegExp(r'[0-7]')),
LengthLimitingTextInputFormatter(4),
],
),
buildActualClearanceField(
'Frequency',
_actualFrequencyController,
widget.expectedFrequency,
formatterList: [FrequencyInputFormatter()],
),
],
),
),
),
),
],
),
const SizedBox(height: 20),
// Proceed Button
ElevatedButton(
onPressed: _navigateToFinalClearance,
child: const Text('Proceed to Clearance Display'),
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('IFR Buddy'), // Global title
actions: [
IconButton(
icon: Icon(widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
onPressed: () {
widget.toggleDarkMode();
},
),
],
),
),
);
}
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
// Explanation Text Card
const Card(
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Use this Page while receiving your clearance. The arrow button copies the expected value. Same if left empty.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
),
),
const SizedBox(height: 16),
// Main content side-by-side
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Expected Clearance Column
Expanded(
child: Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Expected',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
const Divider(),
buildExpectedClearanceField('Clearance Limit', widget.expectedClearanceLimit),
buildExpectedClearanceField('Route', widget.expectedRoute),
buildExpectedClearanceField('Altitude', widget.expectedAltitude),
buildExpectedClearanceField('Frequency', widget.expectedFrequency),
buildExpectedClearanceField('Transponder (Squawk)', widget.expectedSquawk),
],
),
),
),
),
const SizedBox(width: 16), // Spacer between columns
// Actual Clearance Column
Expanded(
child: Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Clearance',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
const Divider(),
buildActualClearanceField(
'Clearance Limit',
_actualClearanceLimitController,
widget.expectedClearanceLimit,
),
buildActualClearanceField(
'Route',
_actualRouteController,
widget.expectedRoute,
),
buildActualClearanceField(
'Altitude',
_actualAltitudeController,
widget.expectedAltitude,
focusNode: _actualAltitudeFocusNode,
),
buildActualClearanceField(
'Frequency',
_actualFrequencyController,
widget.expectedFrequency,
formatterList: [FrequencyInputFormatter()],
),
buildActualClearanceField(
'Transponder (Squawk)',
_actualSquawkController,
widget.expectedSquawk,
formatterList: [
FilteringTextInputFormatter.allow(RegExp(r'[0-7]')),
LengthLimitingTextInputFormatter(4),
],
),
],
),
),
),
),
],
),
const SizedBox(height: 20),
// Proceed Button
ElevatedButton(
onPressed: _navigateToFinalClearance,
child: const Text('Proceed to Clearance Display'),
),
],
),
),
);
}
}

View File

@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:keyboard_actions/keyboard_actions.dart'; // Correct package import
import 'comparison_page.dart';
import 'final_clearance_page.dart'; // Import final clearance page
import '../utils/frequency_input_formatter.dart';
import '../utils/frequency_input_formatter.dart'; // Ensure this path is correct
class ExpectationInputPage extends StatefulWidget {
final bool isDarkMode;
@@ -32,7 +31,7 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
final TextEditingController _expectedFrequencyController =
TextEditingController();
// Reintroduce FocusNodes
// FocusNodes for each field
final FocusNode _clearanceLimitFocusNode = FocusNode();
final FocusNode _routeFocusNode = FocusNode();
final FocusNode _altitudeFocusNode = FocusNode();
@@ -93,7 +92,7 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
}
}
// Updated method to build a text field with optional input
// Method to build a text field with optional input and standard keyboard
Widget buildTextField({
required String label,
required TextEditingController controller,
@@ -120,20 +119,15 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
onFieldSubmitted: (_) {
if (isLastField) {
// If it's the last field, unfocus to close the keyboard
// If it's the last field, unfocus to close the keyboard and submit
currentFocus.unfocus();
// Optionally, you can trigger form submission here
// _navigateToComparisonPage();
_navigateToComparisonPage();
} else if (nextFocus != null) {
FocusScope.of(context).requestFocus(nextFocus);
}
},
// Updated validator to allow empty inputs
// Validator allows empty inputs but validates if input is present
validator: (value) {
// If you want to perform validation only when input is not empty,
// you can add conditional checks here.
// Example: Validate numerical fields if they are not empty
if (value != null && value.isNotEmpty) {
if (keyboardType == TextInputType.number ||
keyboardType == const TextInputType.numberWithOptions(decimal: true)) {
@@ -144,7 +138,7 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
// Add more specific validations if needed
}
// Example: Validate Transponder (Squawk) field
// Validate Transponder (Squawk) field
if (label == 'Transponder (Squawk)') {
if (!RegExp(r'^[0-7]{1,4}$').hasMatch(value)) {
return 'Squawk must be 1-4 digits between 0 and 7';
@@ -165,105 +159,6 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
);
}
// Configure KeyboardActions
KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardSeparatorColor: Colors.grey, // Optional: Customize the separator color
nextFocus: true, // Automatically handle next focus
actions: [
// Define actions for each FocusNode
KeyboardActionsItem(
focusNode: _clearanceLimitFocusNode,
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.nextFocus(),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Next",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
);
}
],
),
KeyboardActionsItem(
focusNode: _routeFocusNode,
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.nextFocus(),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Next",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
);
}
],
),
KeyboardActionsItem(
focusNode: _altitudeFocusNode,
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.nextFocus(),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Next",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
);
}
],
),
KeyboardActionsItem(
focusNode: _squawkFocusNode,
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.nextFocus(),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Next",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
);
}
],
),
KeyboardActionsItem(
focusNode: _frequencyFocusNode,
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () {
node.unfocus(); // Dismiss the keyboard
_navigateToComparisonPage(); // Optionally, submit the form
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Done",
style: TextStyle(color: Colors.blue, fontSize: 16),
),
),
);
}
],
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -282,142 +177,151 @@ class ExpectationInputPageState extends State<ExpectationInputPage> {
body: GestureDetector(
// Dismiss the keyboard when tapping outside
onTap: () => FocusScope.of(context).unfocus(),
child: KeyboardActions(
config: _buildConfig(context), // Apply KeyboardActionsConfig
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Card(
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Welcome to IFR Buddy!',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
),
SizedBox(height: 10),
Text(
'Just an easy tool for writing down IFR clearances without a pen.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.left,
),
],
),
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Card(
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Welcome to IFR Buddy!',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
),
SizedBox(height: 10),
Text(
'Just an easy tool for writing down IFR clearances without a pen.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.left,
),
],
),
),
const SizedBox(height: 16),
Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Expected Clearance',
style: TextStyle(
fontSize: 22, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Expected Clearance',
style: TextStyle(
fontSize: 22, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
const Text(
'Enter your expected clearance information below. '
'Use the listening page or skip to the readback page.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.left,
),
const SizedBox(height: 16),
Form(
key: _formKey,
child: Column(
children: [
buildTextField(
label: 'Clearance Limit',
controller: _expectedClearanceLimitController,
currentFocus: _clearanceLimitFocusNode,
nextFocus: _routeFocusNode,
keyboardType: TextInputType.text, // Standard keyboard
inputFormatters: [
// Allow letters, numbers, spaces, and hyphens
FilteringTextInputFormatter.allow(
RegExp(r'[A-Za-z0-9\s\-]')),
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Route/Sid',
controller: _expectedRouteController,
currentFocus: _routeFocusNode,
nextFocus: _altitudeFocusNode,
keyboardType: TextInputType.text, // Standard keyboard
inputFormatters: [
// Allow letters, numbers, spaces, and hyphens
FilteringTextInputFormatter.allow(
RegExp(r'[A-Za-z0-9\s\-]')),
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Altitude',
controller: _expectedAltitudeController,
currentFocus: _altitudeFocusNode,
nextFocus: _squawkFocusNode,
keyboardType: TextInputType.text, // Standard keyboard
inputFormatters: null, // No restrictions
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Transponder (Squawk)',
controller: _expectedSquawkController,
currentFocus: _squawkFocusNode,
nextFocus: _frequencyFocusNode,
keyboardType: TextInputType.text, // Standard keyboard
inputFormatters: [
// Allow only digits 0-7 and limit to 4 characters
FilteringTextInputFormatter.allow(
RegExp(r'[0-7]')),
LengthLimitingTextInputFormatter(4),
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Departure Frequency',
controller: _expectedFrequencyController,
currentFocus: _frequencyFocusNode,
isLastField: true,
keyboardType: TextInputType.text, // Standard keyboard
inputFormatters: [
FrequencyInputFormatter(), // Handles decimal inputs
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _navigateToComparisonPage,
child: const Text('Next'),
),
const SizedBox(height: 10),
TextButton(
onPressed: _skipReadback,
child: const Text('Skip to end'),
),
],
),
const SizedBox(height: 10),
const Text(
'Enter your expected clearance information below. '
'Use the listening page or skip to the readback page.',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.left,
),
const SizedBox(height: 16),
Form(
key: _formKey,
child: Column(
children: [
buildTextField(
label: 'Clearance Limit',
controller: _expectedClearanceLimitController,
currentFocus: _clearanceLimitFocusNode,
nextFocus: _routeFocusNode,
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Route/Sid',
controller: _expectedRouteController,
currentFocus: _routeFocusNode,
nextFocus: _altitudeFocusNode,
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Altitude',
controller: _expectedAltitudeController,
currentFocus: _altitudeFocusNode,
nextFocus: _squawkFocusNode,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Transponder (Squawk)',
controller: _expectedSquawkController,
currentFocus: _squawkFocusNode,
nextFocus: _frequencyFocusNode,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'[0-7]')),
LengthLimitingTextInputFormatter(4),
],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
buildTextField(
label: 'Departure Frequency',
controller: _expectedFrequencyController,
currentFocus: _frequencyFocusNode,
isLastField: true,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
inputFormatters: [FrequencyInputFormatter()],
enableAutocorrect: false, // Disable autocorrect
enableSuggestions: false, // Disable suggestions
enableIMEPersonalizedLearning:
false, // iOS-specific
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _skipReadback,
child: const Text('Skip to Readback'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: _navigateToComparisonPage,
child: const Text('Navigate to Comparison Page'),
),
],
),
),
],
),
),
],
),
),
],
),
),
],
),
),
),

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'expectation_input_page.dart';
import 'edit_clearance_page.dart'; // Import the edit clearance page
// Import the edit clearance page
import '../widgets/clearance_field.dart';
class FinalClearanceDisplay extends StatefulWidget {
@@ -44,33 +44,6 @@ class FinalClearanceDisplayState extends State<FinalClearanceDisplay> {
}
// Navigate to Edit Clearance Page and handle returned data
Future<void> _navigateToEditClearance() async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditClearancePage(
clearanceLimit: clearanceLimit,
route: route,
altitude: altitude,
squawk: squawk,
frequency: frequency,
isDarkMode: widget.isDarkMode,
toggleDarkMode: widget.toggleDarkMode,
),
),
);
// If the result contains updated data, update the state with the new values
if (result != null && mounted) {
setState(() {
clearanceLimit = result['clearanceLimit'];
route = result['route'];
altitude = result['altitude'];
squawk = result['squawk'];
frequency = result['frequency'];
});
}
}
// Navigate back to the first page (ExpectationInputPage)
void _navigateHome(BuildContext context) {
@@ -97,18 +70,7 @@ class FinalClearanceDisplayState extends State<FinalClearanceDisplay> {
_navigateHome(context);
},
),
actions: [
IconButton(
icon: const Icon(Icons.edit), // Edit button
onPressed: _navigateToEditClearance,
),
IconButton(
icon: Icon(widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
onPressed: () {
widget.toggleDarkMode();
},
),
],
actions: const [],
),
body: Center(
child: SingleChildScrollView(