From 999445ff9e69dd81d11805bd05971ee9d9a30f2a Mon Sep 17 00:00:00 2001 From: IanTapply22 Date: Wed, 16 Oct 2024 18:32:25 -0400 Subject: [PATCH] Fix popping allowed which caused accidents Fix team number setting being 0 all the time Fix camera closing and not reopening Fix CSV file not appending data --- lib/builders/PlatformRoute.dart | 46 ++++++++++--------- .../prematch/fields/PrematchFields.dart | 33 +++++++++---- .../qrcode/DriverStationScanStatusRoute.dart | 23 ++++++++-- lib/routes/qrcode/QRCodeScanningRoute.dart | 3 +- lib/utils/helpers/ScanningHelper.dart | 45 +++--------------- 5 files changed, 75 insertions(+), 75 deletions(-) diff --git a/lib/builders/PlatformRoute.dart b/lib/builders/PlatformRoute.dart index 4ce14ea..4fcb507 100644 --- a/lib/builders/PlatformRoute.dart +++ b/lib/builders/PlatformRoute.dart @@ -22,27 +22,29 @@ class _PlatformRouteState extends State { final scaffoldKey = GlobalKey(); @override Widget build(BuildContext context) { - return Scaffold( - key: scaffoldKey, - drawer: const NavigationSidebar(), - backgroundColor: UIHelper.getBackgroundColour(), - appBar: PreferredSize( - preferredSize: const Size.fromHeight(40.0), - child: AppBar( - backgroundColor: AppStyle.textInputColor, - title: Text( - widget.title, - textAlign: TextAlign.center, - style: - const TextStyle(fontFamily: 'Futura', color: Colors.white), - ), - leading: IconButton( - icon: const Icon(Icons.lunch_dining, color: Colors.white), - onPressed: () { - scaffoldKey.currentState!.openDrawer(); - }, - ), - )), - body: widget.body); + return PopScope( + canPop: false, + child: Scaffold( + key: scaffoldKey, + drawer: const NavigationSidebar(), + backgroundColor: UIHelper.getBackgroundColour(), + appBar: PreferredSize( + preferredSize: const Size.fromHeight(40.0), + child: AppBar( + backgroundColor: AppStyle.textInputColor, + title: Text( + widget.title, + textAlign: TextAlign.center, + style: const TextStyle( + fontFamily: 'Futura', color: Colors.white), + ), + leading: IconButton( + icon: const Icon(Icons.lunch_dining, color: Colors.white), + onPressed: () { + scaffoldKey.currentState!.openDrawer(); + }, + ), + )), + body: widget.body)); } } diff --git a/lib/routes/prematch/fields/PrematchFields.dart b/lib/routes/prematch/fields/PrematchFields.dart index e67a6e9..72ec822 100644 --- a/lib/routes/prematch/fields/PrematchFields.dart +++ b/lib/routes/prematch/fields/PrematchFields.dart @@ -50,22 +50,35 @@ class _PrematchFieldsState extends State { } } })); - // If all requirements are met to update the team number automatically, update it on page loade + + // Ensure match number is set before trying to fetch team number if (SettingValues.isTeamNumberReadOnly) { if (PrematchValues.matchNumber.text != "") { - // If it isn't null - Schedulehelper.getTeamNumberFromSchedule(int.parse( - // Get the team number from the schedule - PrematchValues.matchNumber.text)).then((teamNumber) { - // Once retrieved then set the team number to the text field - setState(() { - PrematchValues.teamNumber.text = teamNumber.toString(); - }); - }); + _updateTeamNumber(); // Call helper function to update team number } } } + void _updateTeamNumber() async { + int matchNumber; + try { + matchNumber = int.parse(PrematchValues.matchNumber.text); + } catch (e) { + // Handle invalid match number case + return; + } + + // Get the team number from the schedule + String teamNumber = + (await Schedulehelper.getTeamNumberFromSchedule(matchNumber)) as String; + + if (mounted) { + setState(() { + PrematchValues.teamNumber.text = teamNumber; + }); + } + } + /// Increments an integer in a controllers value by one void incrementNumber(TextEditingController controller) { if (!mounted) return; diff --git a/lib/routes/qrcode/DriverStationScanStatusRoute.dart b/lib/routes/qrcode/DriverStationScanStatusRoute.dart index 6329ae8..bac830d 100644 --- a/lib/routes/qrcode/DriverStationScanStatusRoute.dart +++ b/lib/routes/qrcode/DriverStationScanStatusRoute.dart @@ -51,14 +51,29 @@ class _DriverStationScanStatusRouteState )); } - // If there are scanned devices, add them to the list of scanned widgets if (ScanningHelper.scannedDevices.isNotEmpty) { - for (String item in ScanningHelper.scannedDevices) { - scannedWidgets.add(Text( - OptionConstants.availableDriverstations[int.parse(item)], + List scannedSpans = []; + for (int i = 0; i < ScanningHelper.scannedDevices.length; i++) { + String item = ScanningHelper.scannedDevices[i]; + String driverStation = + OptionConstants.availableDriverstations[int.parse(item)]; + + scannedSpans.add(TextSpan( + text: driverStation, style: const TextStyle(color: Colors.green, fontSize: 30.0), )); + + if (i != ScanningHelper.scannedDevices.length - 1) { + scannedSpans.add(const TextSpan( + text: ', ', + style: TextStyle(fontSize: 30.0, color: Colors.white), + )); + } } + + scannedWidgets.add(Text.rich( + TextSpan(children: scannedSpans), + )); } return PlatformRoute( diff --git a/lib/routes/qrcode/QRCodeScanningRoute.dart b/lib/routes/qrcode/QRCodeScanningRoute.dart index f6f5fda..9712d25 100644 --- a/lib/routes/qrcode/QRCodeScanningRoute.dart +++ b/lib/routes/qrcode/QRCodeScanningRoute.dart @@ -24,7 +24,8 @@ class QRCodeScanningRoute extends StatelessWidget { @override Widget build(BuildContext context) { - cameraController.start(); // Start camera + cameraController.stop(); + cameraController.start(); UIHelper.setBrightness(0.3); return PlatformRoute( diff --git a/lib/utils/helpers/ScanningHelper.dart b/lib/utils/helpers/ScanningHelper.dart index 0ec9446..1ef003f 100644 --- a/lib/utils/helpers/ScanningHelper.dart +++ b/lib/utils/helpers/ScanningHelper.dart @@ -1,5 +1,3 @@ -// ignore_for_file: file_names - import 'dart:io'; import 'package:csv/csv.dart'; @@ -38,9 +36,7 @@ class ScanningHelper { "Endgame Comments" ]; - static generateCsv( - // Scout/match data - List values) async { + static generateCsv(List values) async { // Request storage permission await Permission.storage.request(); @@ -52,7 +48,7 @@ class ScanningHelper { if (AppConstants.isDebug) print('Storage permission denied'); } - // File name for generated csv file + // File name for generated CSV file String fileName = SettingValues.getCurrentSavingSpreadsheetName(); Directory? directory; @@ -64,49 +60,22 @@ class ScanningHelper { final file = File('${directory?.path}/$fileName'); - // Check if the file already exists bool fileExists = await file.exists(); - // Add column names to data if the file doesn't exist + List> data = []; if (!fileExists) { - await writeToFile(fileName, - 'sep=^\n'); // Used to automatically determine the delimiter when opening the file in excel + await file.writeAsString('sep=^\n', mode: FileMode.append); data.add(csvColumnNames); + } else { + await file.writeAsString('\n', mode: FileMode.append); } data.add(values); - if (fileExists) { - await writeToFile(fileName, "\n"); - } - - // Convert data to csv data and add "^" as field delimiter String csv = const ListToCsvConverter(fieldDelimiter: "^").convert(data); - // Write QR code data/excel data to file - await writeToFile(fileName, csv); - } - - // Creates file in the app directory. - static Future createFileInAppDirectory(String fileName) async { - Directory? directory; - if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { - directory = await getDownloadsDirectory(); - } else { - directory = await getExternalStorageDirectory(); - } - final file = File('${directory?.path}/$fileName'); - await file.create(); - return file; - } - - // Creates and writes a string to a file in the app directory. - static Future writeToFile(String fileName, String fileContents) async { - final file = await createFileInAppDirectory(fileName); - return file.writeAsString(fileContents, - flush: true, - mode: FileMode.append); // write to file if exists, else create file + await file.writeAsString(csv, mode: FileMode.append, flush: true); } }