Initial
This commit is contained in:
73
lib/main.dart
Normal file
73
lib/main.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'screens/expectation_input_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const IFRClearanceApp());
|
||||
}
|
||||
|
||||
class IFRClearanceApp extends StatefulWidget {
|
||||
const IFRClearanceApp({super.key});
|
||||
|
||||
@override
|
||||
IFRClearanceAppState createState() => IFRClearanceAppState();
|
||||
}
|
||||
|
||||
class IFRClearanceAppState extends State<IFRClearanceApp> {
|
||||
bool _isDarkMode = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadDarkModeSetting();
|
||||
}
|
||||
|
||||
// Load the dark mode setting from shared preferences
|
||||
Future<void> _loadDarkModeSetting() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_isDarkMode = prefs.getBool('isDarkMode') ?? false; // Default to false if not set
|
||||
});
|
||||
}
|
||||
|
||||
// Save the dark mode setting to shared preferences
|
||||
Future<void> _saveDarkModeSetting(bool isDarkMode) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setBool('isDarkMode', isDarkMode);
|
||||
}
|
||||
|
||||
// Toggle dark mode and save the setting
|
||||
void _toggleDarkMode() {
|
||||
setState(() {
|
||||
_isDarkMode = !_isDarkMode;
|
||||
});
|
||||
_saveDarkModeSetting(_isDarkMode); // Save the new dark mode setting
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'IFR Buddy',
|
||||
themeMode: _isDarkMode ? ThemeMode.dark : ThemeMode.light,
|
||||
theme: ThemeData(
|
||||
scaffoldBackgroundColor: const Color.fromRGBO(191, 191, 191, 1), // Light mode background color
|
||||
appBarTheme: const AppBarTheme(
|
||||
color: Color.fromRGBO(135, 135, 135, 1), // Light mode AppBar color
|
||||
),
|
||||
cardColor: Colors.white, // Light mode card color
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
scaffoldBackgroundColor: Colors.black87, // Dark mode background color
|
||||
appBarTheme: const AppBarTheme(
|
||||
color: Color.fromRGBO(41, 41, 41, 1), // Dark mode AppBar color
|
||||
),
|
||||
cardColor: Colors.grey[800], // Dark mode card color
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
home: ExpectationInputPage(
|
||||
isDarkMode: _isDarkMode,
|
||||
toggleDarkMode: _toggleDarkMode,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
288
lib/screens/comparison_page.dart
Normal file
288
lib/screens/comparison_page.dart
Normal file
@@ -0,0 +1,288 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../utils/frequency_input_formatter.dart';
|
||||
import 'final_clearance_page.dart';
|
||||
|
||||
class ComparisonPage extends StatefulWidget {
|
||||
final String expectedClearanceLimit;
|
||||
final String expectedRoute;
|
||||
final String expectedAltitude;
|
||||
final String expectedSquawk;
|
||||
final String expectedFrequency;
|
||||
final bool isDarkMode;
|
||||
final Function toggleDarkMode;
|
||||
|
||||
const ComparisonPage({super.key,
|
||||
required this.expectedClearanceLimit,
|
||||
required this.expectedRoute,
|
||||
required this.expectedAltitude,
|
||||
required this.expectedSquawk,
|
||||
required this.expectedFrequency,
|
||||
required this.isDarkMode,
|
||||
required this.toggleDarkMode,
|
||||
});
|
||||
|
||||
@override
|
||||
ComparisonPageState createState() => ComparisonPageState();
|
||||
}
|
||||
|
||||
class ComparisonPageState extends State<ComparisonPage> {
|
||||
final TextEditingController _actualClearanceLimitController = TextEditingController();
|
||||
final TextEditingController _actualRouteController = TextEditingController();
|
||||
final TextEditingController _actualAltitudeController = TextEditingController();
|
||||
final TextEditingController _actualSquawkController = TextEditingController();
|
||||
final TextEditingController _actualFrequencyController = TextEditingController();
|
||||
final FocusNode _actualAltitudeFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_actualAltitudeFocusNode.addListener(() {
|
||||
if (!_actualAltitudeFocusNode.hasFocus) {
|
||||
_formatAltitude(_actualAltitudeController);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_actualClearanceLimitController.dispose();
|
||||
_actualRouteController.dispose();
|
||||
_actualAltitudeController.dispose();
|
||||
_actualSquawkController.dispose();
|
||||
_actualFrequencyController.dispose();
|
||||
_actualAltitudeFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _formatAltitude(TextEditingController controller) {
|
||||
String text = controller.text.trim();
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.startsWith('FL') || text.endsWith('ft')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (RegExp(r'^\d{2,3}$').hasMatch(text)) {
|
||||
controller.text = 'FL$text';
|
||||
} else if (RegExp(r'^\d{4,}$').hasMatch(text)) {
|
||||
controller.text = '$text ft';
|
||||
}
|
||||
}
|
||||
|
||||
void _validateFrequency() {
|
||||
String text = _actualFrequencyController.text;
|
||||
if (text.isEmpty) {
|
||||
_actualFrequencyController.text = widget.expectedFrequency;
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToFinalClearance() {
|
||||
_validateFrequency();
|
||||
|
||||
if (_actualClearanceLimitController.text.isEmpty) {
|
||||
_actualClearanceLimitController.text = widget.expectedClearanceLimit;
|
||||
}
|
||||
if (_actualRouteController.text.isEmpty) {
|
||||
_actualRouteController.text = widget.expectedRoute;
|
||||
}
|
||||
if (_actualAltitudeController.text.isEmpty) {
|
||||
_actualAltitudeController.text = widget.expectedAltitude;
|
||||
}
|
||||
if (_actualSquawkController.text.isEmpty) {
|
||||
_actualSquawkController.text = widget.expectedSquawk;
|
||||
}
|
||||
if (_actualFrequencyController.text.isEmpty) {
|
||||
_actualFrequencyController.text = widget.expectedFrequency;
|
||||
}
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FinalClearanceDisplay(
|
||||
clearanceLimit: _actualClearanceLimitController.text,
|
||||
route: _actualRouteController.text,
|
||||
altitude: _actualAltitudeController.text,
|
||||
squawk: _actualSquawkController.text,
|
||||
frequency: _actualFrequencyController.text,
|
||||
isDarkMode: widget.isDarkMode,
|
||||
toggleDarkMode: widget.toggleDarkMode,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildExpectedClearanceField(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
initialValue: value,
|
||||
readOnly: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildActualClearanceField(
|
||||
String label,
|
||||
TextEditingController controller,
|
||||
String expectedValue, {
|
||||
List<TextInputFormatter>? formatterList,
|
||||
FocusNode? focusNode,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.arrow_forward),
|
||||
tooltip: 'Use Expected Value',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
controller.text = expectedValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
inputFormatters: formatterList,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
204
lib/screens/edit_clearance_page.dart
Normal file
204
lib/screens/edit_clearance_page.dart
Normal file
@@ -0,0 +1,204 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../utils/frequency_input_formatter.dart';
|
||||
|
||||
class EditClearancePage extends StatefulWidget {
|
||||
final String clearanceLimit;
|
||||
final String route;
|
||||
final String altitude;
|
||||
final String squawk;
|
||||
final String frequency;
|
||||
final bool isDarkMode;
|
||||
final Function toggleDarkMode;
|
||||
|
||||
const EditClearancePage({super.key,
|
||||
required this.clearanceLimit,
|
||||
required this.route,
|
||||
required this.altitude,
|
||||
required this.squawk,
|
||||
required this.frequency,
|
||||
required this.isDarkMode,
|
||||
required this.toggleDarkMode,
|
||||
});
|
||||
|
||||
@override
|
||||
EditClearancePageState createState() => EditClearancePageState();
|
||||
}
|
||||
|
||||
class EditClearancePageState extends State<EditClearancePage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
late TextEditingController _clearanceLimitController;
|
||||
late TextEditingController _routeController;
|
||||
late TextEditingController _altitudeController;
|
||||
late TextEditingController _squawkController;
|
||||
late TextEditingController _frequencyController;
|
||||
|
||||
final FocusNode _altitudeFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_clearanceLimitController = TextEditingController(text: widget.clearanceLimit);
|
||||
_routeController = TextEditingController(text: widget.route);
|
||||
_altitudeController = TextEditingController(text: widget.altitude);
|
||||
_squawkController = TextEditingController(text: widget.squawk);
|
||||
_frequencyController = TextEditingController(text: widget.frequency);
|
||||
|
||||
_altitudeFocusNode.addListener(() {
|
||||
if (!_altitudeFocusNode.hasFocus) {
|
||||
_formatAltitude(_altitudeController);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_clearanceLimitController.dispose();
|
||||
_routeController.dispose();
|
||||
_altitudeController.dispose();
|
||||
_squawkController.dispose();
|
||||
_frequencyController.dispose();
|
||||
_altitudeFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _formatAltitude(TextEditingController controller) {
|
||||
String text = controller.text.trim();
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.startsWith('FL') || text.endsWith('ft')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (RegExp(r'^\d{2,3}$').hasMatch(text)) {
|
||||
controller.text = 'FL$text';
|
||||
} else if (RegExp(r'^\d{4,}$').hasMatch(text)) {
|
||||
controller.text = '$text ft';
|
||||
}
|
||||
}
|
||||
|
||||
void _submitForm() {
|
||||
Navigator.pop(
|
||||
context,
|
||||
{
|
||||
'clearanceLimit': _clearanceLimitController.text,
|
||||
'route': _routeController.text,
|
||||
'altitude': _altitudeController.text,
|
||||
'squawk': _squawkController.text,
|
||||
'frequency': _frequencyController.text,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTextField(String label, TextEditingController controller) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildAltitudeField(TextEditingController controller, FocusNode focusNode) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Altitude',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildSquawkField(TextEditingController controller) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Transponder (Squawk)',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[0-7]')),
|
||||
LengthLimitingTextInputFormatter(4),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildFrequencyField(TextEditingController controller) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Frequency',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
inputFormatters: [
|
||||
FrequencyInputFormatter(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('IFR Buddy'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
|
||||
onPressed: () {
|
||||
widget.toggleDarkMode();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Card(
|
||||
elevation: 4,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
children: [
|
||||
buildTextField('Clearance Limit', _clearanceLimitController),
|
||||
buildTextField('Route', _routeController),
|
||||
buildAltitudeField(_altitudeController, _altitudeFocusNode),
|
||||
buildSquawkField(_squawkController),
|
||||
buildFrequencyField(_frequencyController),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _submitForm,
|
||||
child: const Text('Submit Edited Clearance'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
426
lib/screens/expectation_input_page.dart
Normal file
426
lib/screens/expectation_input_page.dart
Normal file
@@ -0,0 +1,426 @@
|
||||
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';
|
||||
|
||||
class ExpectationInputPage extends StatefulWidget {
|
||||
final bool isDarkMode;
|
||||
final Function toggleDarkMode;
|
||||
|
||||
const ExpectationInputPage({
|
||||
super.key,
|
||||
required this.isDarkMode,
|
||||
required this.toggleDarkMode,
|
||||
});
|
||||
|
||||
@override
|
||||
ExpectationInputPageState createState() => ExpectationInputPageState();
|
||||
}
|
||||
|
||||
class ExpectationInputPageState extends State<ExpectationInputPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final TextEditingController _expectedClearanceLimitController =
|
||||
TextEditingController();
|
||||
final TextEditingController _expectedRouteController = TextEditingController();
|
||||
final TextEditingController _expectedAltitudeController =
|
||||
TextEditingController();
|
||||
final TextEditingController _expectedSquawkController =
|
||||
TextEditingController();
|
||||
final TextEditingController _expectedFrequencyController =
|
||||
TextEditingController();
|
||||
|
||||
// Reintroduce FocusNodes
|
||||
final FocusNode _clearanceLimitFocusNode = FocusNode();
|
||||
final FocusNode _routeFocusNode = FocusNode();
|
||||
final FocusNode _altitudeFocusNode = FocusNode();
|
||||
final FocusNode _squawkFocusNode = FocusNode();
|
||||
final FocusNode _frequencyFocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_expectedClearanceLimitController.dispose();
|
||||
_expectedRouteController.dispose();
|
||||
_expectedAltitudeController.dispose();
|
||||
_expectedSquawkController.dispose();
|
||||
_expectedFrequencyController.dispose();
|
||||
_clearanceLimitFocusNode.dispose();
|
||||
_routeFocusNode.dispose();
|
||||
_altitudeFocusNode.dispose();
|
||||
_squawkFocusNode.dispose();
|
||||
_frequencyFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _navigateToComparisonPage() {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ComparisonPage(
|
||||
expectedClearanceLimit: _expectedClearanceLimitController.text,
|
||||
expectedRoute: _expectedRouteController.text,
|
||||
expectedAltitude: _expectedAltitudeController.text,
|
||||
expectedSquawk: _expectedSquawkController.text,
|
||||
expectedFrequency: _expectedFrequencyController.text,
|
||||
isDarkMode: widget.isDarkMode,
|
||||
toggleDarkMode: widget.toggleDarkMode,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to skip directly to final clearance page
|
||||
void _skipReadback() {
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FinalClearanceDisplay(
|
||||
clearanceLimit: _expectedClearanceLimitController.text,
|
||||
route: _expectedRouteController.text,
|
||||
altitude: _expectedAltitudeController.text,
|
||||
squawk: _expectedSquawkController.text,
|
||||
frequency: _expectedFrequencyController.text,
|
||||
isDarkMode: widget.isDarkMode,
|
||||
toggleDarkMode: widget.toggleDarkMode,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Updated method to build a text field with optional input
|
||||
Widget buildTextField({
|
||||
required String label,
|
||||
required TextEditingController controller,
|
||||
required FocusNode currentFocus,
|
||||
FocusNode? nextFocus,
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
List<TextInputFormatter>? inputFormatters,
|
||||
bool isLastField = false,
|
||||
bool enableAutocorrect = false, // To disable autocorrect
|
||||
bool enableSuggestions = false, // To disable suggestions
|
||||
bool enableIMEPersonalizedLearning = false, // iOS-specific
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
focusNode: currentFocus,
|
||||
keyboardType: keyboardType,
|
||||
textInputAction:
|
||||
isLastField ? TextInputAction.done : TextInputAction.next,
|
||||
inputFormatters: inputFormatters,
|
||||
autocorrect: enableAutocorrect,
|
||||
enableSuggestions: enableSuggestions,
|
||||
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
|
||||
onFieldSubmitted: (_) {
|
||||
if (isLastField) {
|
||||
// If it's the last field, unfocus to close the keyboard
|
||||
currentFocus.unfocus();
|
||||
// Optionally, you can trigger form submission here
|
||||
// _navigateToComparisonPage();
|
||||
} else if (nextFocus != null) {
|
||||
FocusScope.of(context).requestFocus(nextFocus);
|
||||
}
|
||||
},
|
||||
// Updated validator to allow empty inputs
|
||||
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 == TextInputType.numberWithOptions(decimal: true)) {
|
||||
final number = double.tryParse(value);
|
||||
if (number == null) {
|
||||
return 'Please enter a valid number';
|
||||
}
|
||||
// Add more specific validations if needed
|
||||
}
|
||||
|
||||
// Example: 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';
|
||||
}
|
||||
}
|
||||
|
||||
// Add other conditional validations as necessary
|
||||
}
|
||||
|
||||
// If no issues, return null
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 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(
|
||||
appBar: AppBar(
|
||||
title: const Text('IFR Buddy'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
|
||||
onPressed: () {
|
||||
widget.toggleDarkMode();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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,
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
142
lib/screens/final_clearance_page.dart
Normal file
142
lib/screens/final_clearance_page.dart
Normal file
@@ -0,0 +1,142 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'expectation_input_page.dart';
|
||||
import 'edit_clearance_page.dart'; // Import the edit clearance page
|
||||
import '../widgets/clearance_field.dart';
|
||||
|
||||
class FinalClearanceDisplay extends StatefulWidget {
|
||||
final String clearanceLimit;
|
||||
final String route;
|
||||
final String altitude;
|
||||
final String squawk;
|
||||
final String frequency;
|
||||
final bool isDarkMode;
|
||||
final Function toggleDarkMode;
|
||||
|
||||
const FinalClearanceDisplay({super.key,
|
||||
required this.clearanceLimit,
|
||||
required this.route,
|
||||
required this.altitude,
|
||||
required this.squawk,
|
||||
required this.frequency,
|
||||
required this.isDarkMode,
|
||||
required this.toggleDarkMode,
|
||||
});
|
||||
|
||||
@override
|
||||
FinalClearanceDisplayState createState() => FinalClearanceDisplayState();
|
||||
}
|
||||
|
||||
class FinalClearanceDisplayState extends State<FinalClearanceDisplay> {
|
||||
late String clearanceLimit;
|
||||
late String route;
|
||||
late String altitude;
|
||||
late String squawk;
|
||||
late String frequency;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
clearanceLimit = widget.clearanceLimit;
|
||||
route = widget.route;
|
||||
altitude = widget.altitude;
|
||||
squawk = widget.squawk;
|
||||
frequency = widget.frequency;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ExpectationInputPage(
|
||||
isDarkMode: widget.isDarkMode,
|
||||
toggleDarkMode: widget.toggleDarkMode,
|
||||
),
|
||||
),
|
||||
(Route<dynamic> route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('IFR Buddy'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.home), // Home button
|
||||
onPressed: () {
|
||||
_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();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Card(
|
||||
elevation: 4,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Clearance Summary',
|
||||
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
buildClearanceField('Clearance Limit', clearanceLimit),
|
||||
buildClearanceField('Route', route),
|
||||
buildClearanceField('Altitude', altitude),
|
||||
buildClearanceField('Transponder (Squawk)', squawk),
|
||||
buildClearanceField('Frequency', frequency),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
29
lib/utils/frequency_input_formatter.dart
Normal file
29
lib/utils/frequency_input_formatter.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class FrequencyInputFormatter extends TextInputFormatter {
|
||||
static const int maxDigits = 5;
|
||||
|
||||
@override
|
||||
TextEditingValue formatEditUpdate(
|
||||
TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
String digitsOnly = newValue.text.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
|
||||
if (digitsOnly.length > maxDigits) {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
String formatted = digitsOnly;
|
||||
if (digitsOnly.length > 3) {
|
||||
formatted = '${digitsOnly.substring(0, 3)}.${digitsOnly.substring(3)}';
|
||||
}
|
||||
|
||||
if (formatted.endsWith('.') && digitsOnly.length <= 3) {
|
||||
formatted = formatted.substring(0, formatted.length - 1);
|
||||
}
|
||||
|
||||
return TextEditingValue(
|
||||
text: formatted,
|
||||
selection: TextSelection.collapsed(offset: formatted.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
21
lib/widgets/clearance_field.dart
Normal file
21
lib/widgets/clearance_field.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget buildClearanceField(String label, String value) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: TextFormField(
|
||||
initialValue: value,
|
||||
readOnly: true,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: InputBorder.none,
|
||||
labelStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user