Changed questions, added export.
This commit is contained in:
parent
a83bf0d533
commit
78618aed9a
8 changed files with 277 additions and 173 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:laserscouter/core/api.dart';
|
||||
import 'notespage.dart';
|
||||
import 'package:to_csv/to_csv.dart' as csv_export;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:to_csv/to_csv.dart' as exportcsv;
|
||||
import 'notespage.dart'; // Import the new notes page file
|
||||
|
||||
|
||||
class TeamPicker extends StatefulWidget {
|
||||
final String eventCode;
|
||||
|
|
@ -22,16 +23,67 @@ class _TeamPickerState extends State<TeamPicker> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Call the new async method to fetch teams
|
||||
_fetchTeams();
|
||||
}
|
||||
|
||||
Future<void> _exportData() async {
|
||||
List<String> header = [];
|
||||
header.add('Team Number');
|
||||
header.add('Drivetrain Type');
|
||||
header.add('Has Vision');
|
||||
header.add('Climb Level');
|
||||
header.add('Trenchable');
|
||||
header.add('Fuel Capacity');
|
||||
header.add('Bot Position');
|
||||
header.add('Auton Rundown');
|
||||
header.add('General Observations');
|
||||
|
||||
List<List<String>> data = [];
|
||||
for (int i = 0; i < teamCodes.length; i++) {
|
||||
String generateKey(String field) {
|
||||
return '${teamCodes[i]}_${widget.eventCode}_$field';
|
||||
}
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
String? autonRundown = prefs.getString(generateKey('autonRundown'));
|
||||
String? botPosition = prefs.getString(generateKey('botPosition'));
|
||||
String? generalObservations = prefs.getString(generateKey('generalObservations'));
|
||||
String? driveTrainType = prefs.getString(generateKey('driveTrainType'));
|
||||
String? hasVision = prefs.getBool(generateKey('hasVision')).toString();
|
||||
String? climbLevel = prefs.getDouble(generateKey('climbLevel')).toString();
|
||||
String? trenchable = prefs.getBool(generateKey('trenchable')).toString();
|
||||
String? fuelCapacity = prefs.getDouble(generateKey('fuelCapacity')).toString();
|
||||
|
||||
if (hasVision == 'null') {
|
||||
hasVision = '';
|
||||
}
|
||||
if (climbLevel == 'null') {
|
||||
climbLevel = '';
|
||||
}
|
||||
if (trenchable == 'null') {
|
||||
trenchable = '';
|
||||
}
|
||||
if (fuelCapacity == 'null') {
|
||||
fuelCapacity = '';
|
||||
}
|
||||
|
||||
List<String> teamData = [];
|
||||
teamData.add(teamCodes[i]);
|
||||
teamData.add(driveTrainType ?? '');
|
||||
teamData.add(hasVision);
|
||||
teamData.add(climbLevel);
|
||||
teamData.add(trenchable);
|
||||
teamData.add(fuelCapacity);
|
||||
teamData.add(botPosition ?? '');
|
||||
teamData.add(autonRundown ?? '');
|
||||
teamData.add(generalObservations ?? '');
|
||||
data.add(teamData);
|
||||
}
|
||||
csv_export.myCSV(header, data, setHeadersInFirstRow: true, emptyRowsConfig: {1: 1}, fileName: 'laserscouter_${widget.eventCode}.csv');
|
||||
}
|
||||
|
||||
Future<void> _fetchTeams() async {
|
||||
try {
|
||||
// Await the result from the refactored API function
|
||||
final EventSearchResult result = await eventSearch(widget.eventCode);
|
||||
|
||||
// Check if the widget is still mounted before updating state
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
teamNames = result.teamNames;
|
||||
|
|
@ -40,7 +92,6 @@ class _TeamPickerState extends State<TeamPicker> {
|
|||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// If an error occurs, update the state to show an error message
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
errorMessage = "Failed to load teams. Please try again.";
|
||||
|
|
@ -50,46 +101,17 @@ class _TeamPickerState extends State<TeamPicker> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> makeCSV() async {
|
||||
List<String> header = [
|
||||
'Team Number',
|
||||
'Bot Position',
|
||||
'Auton Rundown',
|
||||
'Can Score Algae',
|
||||
'Coral Level'
|
||||
];
|
||||
List<List<String>> dataLists = [header];
|
||||
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
for (int i = 0; i < teamCodes.length; i++) {
|
||||
List<String> data = [];
|
||||
data.add(teamCodes[i]);
|
||||
String botPosition = prefs.getString('${teamCodes[i]}_${widget.eventCode}_note1') ?? '';
|
||||
String autonRundown = prefs.getString('${teamCodes[i]}_${widget.eventCode}_note2') ?? '';
|
||||
String canScoreAlgae = prefs.getString('${teamCodes[i]}_${widget.eventCode}_note3') ?? '';
|
||||
String coralLevel = prefs.getString('${teamCodes[i]}_${widget.eventCode}_note4') ?? '0.0';
|
||||
data.add(botPosition.trim());
|
||||
data.add(autonRundown);
|
||||
data.add(canScoreAlgae);
|
||||
data.add(coralLevel);
|
||||
dataLists.add(data);
|
||||
}
|
||||
exportcsv.myCSV(header, dataLists, fileName: '${widget.eventCode}-scouting-data');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Teams'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share),
|
||||
onPressed: isLoading || teamCodes.isEmpty ? null : makeCSV,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _buildBody(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _exportData,
|
||||
child: const Icon(Icons.share),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -140,4 +162,4 @@ class _TeamPickerState extends State<TeamPicker> {
|
|||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue