Skip to content

Commit

Permalink
Fix popping allowed which caused accidents
Browse files Browse the repository at this point in the history
Fix team number setting being 0 all the time

Fix camera closing and not reopening

Fix CSV file not appending data
  • Loading branch information
IanTapply22 committed Oct 16, 2024
1 parent 97a111d commit 999445f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 75 deletions.
46 changes: 24 additions & 22 deletions lib/builders/PlatformRoute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,29 @@ class _PlatformRouteState extends State<PlatformRoute> {
final scaffoldKey = GlobalKey<ScaffoldState>();
@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));
}
}
33 changes: 23 additions & 10 deletions lib/routes/prematch/fields/PrematchFields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,35 @@ class _PrematchFieldsState extends State<PrematchFields> {
}
}
}));
// 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;
Expand Down
23 changes: 19 additions & 4 deletions lib/routes/qrcode/DriverStationScanStatusRoute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<InlineSpan> 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(
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/qrcode/QRCodeScanningRoute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 7 additions & 38 deletions lib/utils/helpers/ScanningHelper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: file_names

import 'dart:io';

import 'package:csv/csv.dart';
Expand Down Expand Up @@ -38,9 +36,7 @@ class ScanningHelper {
"Endgame Comments"
];

static generateCsv(
// Scout/match data
List<String> values) async {
static generateCsv(List<String> values) async {
// Request storage permission
await Permission.storage.request();

Expand All @@ -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;
Expand All @@ -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<List<String>> 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<File> 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<File> 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);
}
}

0 comments on commit 999445f

Please sign in to comment.