import 'package:flutter/material.dart'; import 'package:pocketbase/pocketbase.dart'; // Import the PocketBase package import 'expectation_input_page.dart'; 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 { late String clearanceLimit; late String route; late String altitude; late String squawk; late String frequency; final PocketBase pb = PocketBase('https://backend.degnedict.de'); // Initialize PocketBase @override void initState() { super.initState(); clearanceLimit = widget.clearanceLimit; route = widget.route; altitude = widget.altitude; squawk = widget.squawk; frequency = widget.frequency; _createPageViewRecord(); // Create a record with the current timestamp } // Function to create a new record with a timestamp in epoch milliseconds in your PocketBase collection Future _createPageViewRecord() async { try { // Get the current time in epoch milliseconds int currentTimeInMillis = DateTime.now().millisecondsSinceEpoch; // Create a new record in the collection with the current epoch time await pb.collection('IFRbuddyUsage').create(body: { 'timestamp': currentTimeInMillis, // Save current timestamp as epoch time (milliseconds) }); } catch (e) { } } // 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 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: const [], ), 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('Frequency', frequency), buildClearanceField('Transponder (Squawk)', squawk), ], ), ), ), ), ), ); } }