Rewrote pretty much all of it. New logo/icons. Overall did alot tbh.

This commit is contained in:
Raktbastr 2026-01-22 22:44:02 -06:00
parent 5858a4a231
commit d128768478
142 changed files with 968 additions and 3875 deletions

69
lib/core/api.dart Normal file
View file

@ -0,0 +1,69 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
String proxyURL = "https://laserscouter.halfheart.net/";
class TeamSearchResult {
final List<String> eventNames;
final List<String> eventCodes;
TeamSearchResult({required this.eventNames, required this.eventCodes});
}
class EventSearchResult {
final List<String> teamNames;
final List<String> teamCodes;
EventSearchResult({required this.teamNames, required this.teamCodes});
}
Future<TeamSearchResult> teamSearch(String teamNumber) async {
try {
final response = await http.get(
Uri.parse('${proxyURL}teamsearch/$teamNumber'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
List<String> eventNames = [];
List<String> eventCodes = [];
for (var event in data) {
eventNames.add(event['name']);
eventCodes.add(event['key']);
}
return TeamSearchResult(eventNames: eventNames, eventCodes: eventCodes);
} else {
throw Exception('Failed to load events. Status code: ${response.statusCode}');
}
} catch (e) {
debugPrint('Error in teamSearch: $e');
rethrow;
}
}
Future<EventSearchResult> eventSearch(String eventCode) async {
try {
final response = await http.get(
Uri.parse('${proxyURL}eventsearch/$eventCode'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
List<String> teamNames = [];
List<String> teamCodes = [];
for (var event in data) {
teamNames.add(event['nickname']);
teamCodes.add(event['team_number'].toString());
}
return EventSearchResult(teamNames: teamNames, teamCodes: teamCodes);
} else {
throw Exception('Failed to load teams. Status code: ${response.statusCode}');
}
} catch (e) {
debugPrint('Error in eventSearch: $e');
rethrow;
}
}

128
lib/core/theme.dart Normal file
View file

@ -0,0 +1,128 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
final ThemeData laserTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF00245D),
primary: const Color(0xFF00245D),
brightness: Brightness.dark,
),
textTheme: TextTheme(
displayLarge: GoogleFonts.aldrich(
fontSize: 57,
fontWeight: FontWeight.w700,
),
displayMedium: GoogleFonts.aldrich(
fontSize: 45,
fontWeight: FontWeight.w600,
),
displaySmall: GoogleFonts.aldrich(
fontSize: 36,
fontWeight: FontWeight.w500,
),
titleLarge: GoogleFonts.openSans(
fontSize: 22,
fontWeight: FontWeight.w700,
),
titleMedium: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
titleSmall: GoogleFonts.openSans(
fontSize: 14,
fontWeight: FontWeight.w500,
),
bodyLarge: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w400,
),
bodyMedium: GoogleFonts.openSans(
fontSize: 14,
fontWeight: FontWeight.w400,
),
bodySmall: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w400,
),
labelLarge: GoogleFonts.openSans(
fontSize: 14,
fontWeight: FontWeight.w600,
),
labelMedium: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w500,
),
labelSmall: GoogleFonts.openSans(
fontSize: 11,
fontWeight: FontWeight.w500,
),
),
appBarTheme: AppBarTheme(
titleTextStyle: GoogleFonts.aldrich(
fontSize: 36,
fontWeight: FontWeight.w500,
color: Colors.white
),
backgroundColor: const Color(0xFF00245D),
elevation: 4,
centerTitle: false,
iconTheme: const IconThemeData(color: Colors.white),
),
inputDecorationTheme: const InputDecorationTheme(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color(0xFF00245D), width: 2.0),
),
floatingLabelStyle: TextStyle(color: Colors.white),
hintStyle: TextStyle(color: Colors.white54),
),
sliderTheme: SliderThemeData(
activeTrackColor: const Color(0xFF00245D),
thumbColor: const Color(0xFF00245D),
inactiveTrackColor: Colors.grey.shade800,
),
checkboxTheme: CheckboxThemeData(
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return const Color(0xFF00245D);
}
return null;
}),
checkColor: WidgetStateProperty.all(Colors.white),
),
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return const Color(0xFF00245D);
}
return null;
}),
trackColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return const Color(0xFF00245D).withValues(alpha: 0.5);
}
return null;
}),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.grey.shade800),
)
);

View file

@ -1,4 +1,3 @@
// eventpicker.dart
import 'package:flutter/material.dart';
import 'teampicker.dart';
@ -6,16 +5,12 @@ class EventPicker extends StatelessWidget {
final List<String> eventNames;
final List<String> eventCodes;
EventPicker({required this.eventNames, required this.eventCodes});
const EventPicker({super.key, required this.eventNames, required this.eventCodes});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Event', style: TextStyle(color: Colors.white)),
backgroundColor: const Color.fromARGB(255, 19, 81, 179),
iconTheme: const IconThemeData(color: Colors.white),
),
appBar: AppBar(title: const Text('Event')),
body: ListView.builder(
itemCount: eventNames.length,
itemBuilder: (context, index) {
@ -25,7 +20,7 @@ class EventPicker extends StatelessWidget {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TeamPicker(
builder: (context) => TeamPicker(
eventCode: eventCodes[index],
),
),

View file

@ -1,28 +1,9 @@
import 'package:flutter/material.dart';
import 'eventpicker.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'core/api.dart';
import 'core/theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
void getData(String teamNumber, Function(List<String>, List<String>) callback) async {
final response = await http.get(
Uri.parse('https://laserscouter.halfheart.net/teamsearch/$teamNumber'),
);
if (response.statusCode == 200) {
String data = response.body;
var decodedData = jsonDecode(data);
List<String> eventNames = [];
List<String> eventCodes = [];
for (var event in decodedData) {
eventNames.add(event['name']);
eventCodes.add(event['key']);
}
callback(eventNames, eventCodes);
} else {
print(response.statusCode);
}
}
import 'eventpicker.dart';
import 'settings.dart';
void main() {
runApp(const MyApp());
@ -35,14 +16,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login Page',
theme: ThemeData(
useMaterial3: true,
primaryColor: const Color.fromARGB(255, 19, 81, 179),
appBarTheme: const AppBarTheme(
backgroundColor: Color.fromARGB(255, 19, 81, 179),
iconTheme: IconThemeData(color: Colors.white),
),
),
theme: laserTheme,
home: const LoginPage(),
);
}
@ -52,12 +26,11 @@ class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
_LoginPageState createState() => _LoginPageState();
}
State<LoginPage> createState() => _LoginPageState();}
class _LoginPageState extends State<LoginPage> {
final TextEditingController _teamNumberController = TextEditingController();
final TextEditingController _apiKeyController = TextEditingController();
bool _isLoading = false;
@override
void initState() {
@ -67,29 +40,25 @@ class _LoginPageState extends State<LoginPage> {
Future<void> _loadSavedData() async {
final prefs = await SharedPreferences.getInstance();
_teamNumberController.text = prefs.getString('teamNumber') ?? '';
_apiKeyController.text = prefs.getString('apiKey') ?? '';
}
if (mounted) {
_teamNumberController.text = prefs.getString('teamNumber') ?? '';
} }
Future<void> _saveData() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('teamNumber', _teamNumberController.text);
await prefs.setString('apiKey', _apiKeyController.text);
}
@override
void dispose() {
_teamNumberController.dispose();
_apiKeyController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Login', style: TextStyle(color: Colors.white)),
backgroundColor: const Color.fromARGB(255, 19, 81, 179),
title: const Text('Login'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
@ -107,26 +76,67 @@ class _LoginPageState extends State<LoginPage> {
),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: () async {
await _saveData();
String teamNumber = _teamNumberController.text;
getData(teamNumber, (eventNames, eventCodes) {
Navigator.push(
context,
onPressed: _isLoading
? null
: () async {
final navigator = Navigator.of(context);
final scaffoldMessenger = ScaffoldMessenger.of(context);
setState(() {
_isLoading = true;
});
try {
await _saveData();
String teamNumber = _teamNumberController.text;
final result = await teamSearch(teamNumber);
navigator.push(
MaterialPageRoute(
builder: (context) => EventPicker(
eventNames: eventNames,
eventCodes: eventCodes,
eventNames: result.eventNames,
eventCodes: result.eventCodes,
),
),
);
});
} catch (e) {
scaffoldMessenger.showSnackBar(
SnackBar(content: Text('Error: ${e.toString()}')),
);
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
},
child: const Text('Login'),
child: _isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2.0,
color: Colors.white,
),
)
: const Text('Login'),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _isLoading
? null
: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SettingsPage(),
));
},
child: const Text('Settings'),
),
],
),
),
);
}
}
}

View file

@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'login.dart';
import 'package:laserscouter/core/theme.dart';
import 'package:laserscouter/login.dart';
void main() {
runApp(MyApp());
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@ -12,11 +13,8 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Laser Scouter',
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Ocraextended',
),
theme: laserTheme,
home: LoginPage(),
);
}
}
}

180
lib/notespage.dart Normal file
View file

@ -0,0 +1,180 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class NotesPage extends StatefulWidget {
final String teamCode;
final String eventCode;
final String teamName;
const NotesPage({
super.key,
required this.teamCode,
required this.teamName,
required this.eventCode,
});
@override
State<NotesPage> createState() => _NotesPageState();
}
class _NotesPageState extends State<NotesPage> {
final TextEditingController _checkboxes = TextEditingController();
final TextEditingController _controller2 = TextEditingController();
final TextEditingController _switchvalue = TextEditingController();
double _slidervalue = 0.0;
@override
void initState() {
super.initState();
_loadNotes();
}
@override
void dispose() {
_saveNotes();
_checkboxes.dispose();
_controller2.dispose();
_switchvalue.dispose();
super.dispose();
}
Future<void> _loadNotes() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (mounted) {
setState(() {
_checkboxes.text =
prefs.getString('${widget.teamCode}_${widget.eventCode}_note1') ?? '';
_controller2.text =
prefs.getString('${widget.teamCode}_${widget.eventCode}_note2') ?? '';
_switchvalue.text =
prefs.getString('${widget.teamCode}_${widget.eventCode}_note3') ?? '';
_slidervalue = double.tryParse(prefs
.getString('${widget.teamCode}_${widget.eventCode}_note4') ??
'0.0') ?? 0.0;
});
}
}
Future<void> _saveNotes() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString(
'${widget.teamCode}_${widget.eventCode}_note1', _checkboxes.text);
await prefs.setString(
'${widget.teamCode}_${widget.eventCode}_note2', _controller2.text);
await prefs.setString(
'${widget.teamCode}_${widget.eventCode}_note3', _switchvalue.text);
await prefs.setString(
'${widget.teamCode}_${widget.eventCode}_note4', _slidervalue.toString());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Notes'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView(
children: [
Text(widget.teamName, style: Theme.of(context).textTheme.titleLarge, textAlign: TextAlign.center),
Text('Bot Starting Position',
style: Theme.of(context).textTheme.titleMedium),
CheckboxListTile(
title: const Text('Left'),
value: _checkboxes.text.contains('Left'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Left ';
} else {
_checkboxes.text =
_checkboxes.text.replaceAll('Left ', '');
}
_saveNotes();
});
},
),
CheckboxListTile(
title: const Text('Mid'),
value: _checkboxes.text.contains('Mid'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Mid ';
} else {
_checkboxes.text = _checkboxes.text.replaceAll('Mid ', '');
}
_saveNotes();
});
},
),
CheckboxListTile(
title: const Text('Right'),
value: _checkboxes.text.contains('Right'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Right ';
} else {
_checkboxes.text =
_checkboxes.text.replaceAll('Right ', '');
}
_saveNotes();
});
},
),
const Divider(),
TextField(
controller: _controller2,
decoration: const InputDecoration(labelText: 'Auton Rundown'),
maxLines: null,
keyboardType: TextInputType.multiline,
onChanged: (text) => _saveNotes(),
),
const Divider(),
CheckboxListTile(
title: const Text('Can Score Algae'),
value: _switchvalue.text.contains('Can Score Algae'),
onChanged: (bool? value) {
setState(() {
_switchvalue.text =
value == true ? 'Can Score Algae' : '';
_saveNotes();
});
},
),
CheckboxListTile(
title: const Text('Cannot Score Algae'),
value: _switchvalue.text.contains('Cannot Score Algae'),
onChanged: (bool? value) {
setState(() {
_switchvalue.text =
value == true ? 'Cannot Score Algae' : '';
_saveNotes();
});
},
),
const Divider(),
Text('Coral Level', style: Theme.of(context).textTheme.titleMedium),
Slider(
value: _slidervalue,
onChanged: (double value) {
setState(() {
_slidervalue = value;
});
},
onChangeEnd: (double value) {
_saveNotes();
},
min: 0,
max: 3,
divisions: 3,
label: _slidervalue.round().toString(),
),
],
),
),
);
}
}

79
lib/settings.dart Normal file
View file

@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'core/api.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@override
State<SettingsPage> createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
final TextEditingController _urlController = TextEditingController();
@override
void dispose() {
_saveData();
_urlController.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
_loadData();
}
Future<void> _saveData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('url', _urlController.text);
}
Future<void> _loadData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_urlController.text = prefs.getString('url') ?? '';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Settings'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
children: <Widget>[
Text('LaserProxy URL', style: Theme.of(context).textTheme.titleLarge),
Text(
'Set the URL of the LaserProxy instance. Leave it blank to use the default.',
style: Theme.of(context).textTheme.bodyMedium
),
const SizedBox(height: 16),
TextField(
controller: _urlController,
decoration: const InputDecoration(
labelText: 'URL',
hintText: 'https://laserscouter.halfheart.net/',
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color.fromARGB(255, 19, 81, 179)),
),
),
onChanged: (value) {
if (value.isEmpty) {
proxyURL = "https://laserscouter.halfheart.net/";
}
else {
proxyURL = value;
}
}
),
const Divider(height: 32),
],
),
);
}
}

View file

@ -1,272 +1,143 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:laserscouter/core/api.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:to_csv/to_csv.dart' as exportCSV;
void getData(String eventCode, Function(List<String>, List<String>) callback) async {
final response = await http.get(
Uri.parse('https://laserscouter.halfheart.net/eventsearch/$eventCode'),
);
if (response.statusCode == 200) {
String data = response.body;
var decodedData = jsonDecode(data);
List<String> teamNames = [];
List<String> teamCodes = [];
for (var event in decodedData) {
teamNames.add(event['nickname']);
teamCodes.add(event['team_number'].toString());
}
callback(teamNames, teamCodes);
} else {
print(response.statusCode);
}
}
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;
TeamPicker({required this.eventCode});
const TeamPicker({super.key, required this.eventCode});
@override
_TeamPickerState createState() => _TeamPickerState();
}
class NotesPage extends StatefulWidget {
final String teamCode;
final String eventCode;
final String teamName;
NotesPage({required this.teamCode, required this.teamName, required this.eventCode});
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Notes for $teamName'),
),
body: Center(
child: Text('Notes for team $teamCode - $teamName'),
),
);
}
@override
_NotesPageState createState() => _NotesPageState();
}
class _NotesPageState extends State<NotesPage> {
final TextEditingController _checkboxes = TextEditingController();
final TextEditingController _controller2 = TextEditingController();
final TextEditingController _switchvalue = TextEditingController();
double _slidervalue = 0.0;
@override
void initState() {
super.initState();
_loadNotes();
}
_loadNotes() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_checkboxes.text = prefs.getString('${widget.teamCode}_${widget.eventCode}_note1') ?? '';
_controller2.text = prefs.getString('${widget.teamCode}_${widget.eventCode}_note2') ?? '';
_switchvalue.text = prefs.getString('${widget.teamCode}_${widget.eventCode}_note3') ?? '';
_slidervalue = double.tryParse(prefs.getString('${widget.teamCode}_${widget.eventCode}_note4') ?? '0.0') ?? 0.0;
});
}
_saveNotes() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('${widget.teamCode}_${widget.eventCode}_note1', _checkboxes.text);
await prefs.setString('${widget.teamCode}_${widget.eventCode}_note2', _controller2.text);
await prefs.setString('${widget.teamCode}_${widget.eventCode}_note3', _switchvalue.text);
await prefs.setString('${widget.teamCode}_${widget.eventCode}_note4', _slidervalue.toString());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Notes for ${widget.teamName}'),
actions: [
IconButton(
icon: Icon(Icons.save),
onPressed: _saveNotes,
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text('Bot Starting Position', style: TextStyle(fontSize: 20)),
CheckboxListTile(
title: Text('Left'),
value: _checkboxes.text.contains('Left'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Left ';
} else {
_checkboxes.text = _checkboxes.text.replaceAll('Left ', '');
}
});
},
),
CheckboxListTile(
title: Text('Mid'),
value: _checkboxes.text.contains('Mid'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Mid ';
} else {
_checkboxes.text = _checkboxes.text.replaceAll('Mid ', '');
}
});
},
),
CheckboxListTile(
title: Text('Right'),
value: _checkboxes.text.contains('Right'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_checkboxes.text += 'Right ';
} else {
_checkboxes.text = _checkboxes.text.replaceAll('Right ', '');
}
});
},
),
TextField(
controller: _controller2,
decoration: InputDecoration(labelText: 'Auton Rundown'),
maxLines: null,
keyboardType: TextInputType.multiline,
),
CheckboxListTile(
title: Text('Can Score Algae'),
value: _switchvalue.text.contains('Can Score Algae'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_switchvalue.text = 'Can Score Algae ';
} else {
_switchvalue.text = '';
}
});
},
),
CheckboxListTile(
title: Text('Cannot Score Algae'),
value: _switchvalue.text.contains('Cannot Score Algae'),
onChanged: (bool? value) {
setState(() {
if (value == true) {
_switchvalue.text = 'Cannot Score Algae ';
} else {
_switchvalue.text = '';
}
});
},
),
Text('Coral Level', style: TextStyle(fontSize: 20)),
Slider(
value: _slidervalue,
onChanged: (double value) {
setState(() {
_slidervalue = value;
});
},
min: 0,
max: 3,
divisions: 3,
label: _slidervalue.round().toString(),
),
],
),
),
);
}
State<TeamPicker> createState() => _TeamPickerState();
}
class _TeamPickerState extends State<TeamPicker> {
List<String> teamNames = [];
List<String> teamCodes = [];
bool isLoading = true;
String? errorMessage;
@override
void initState() {
super.initState();
getData(widget.eventCode, (names, codes) {
setState(() {
teamNames = names;
teamCodes = codes;
});
});
// Call the new async method to fetch teams
_fetchTeams();
}
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;
teamCodes = result.teamCodes;
isLoading = false;
});
}
} 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.";
isLoading = false;
});
}
}
}
Future<void> makeCSV() async {
List<String> header = [];
header.add('Team Number');
header.add('Bot Position');
header.add('Auton Rundown');
header.add('Can Score Algae');
header.add('Coral Level');
List<List<String>> dataLists = [];
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]);
SharedPreferences prefs = await SharedPreferences.getInstance();
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);
data.add(botPosition.trim());
data.add(autonRundown);
data.add(canScoreAlgae);
data.add(coralLevel);
dataLists.add(data);
}
exportCSV.myCSV(header, dataLists, setHeadersInFirstRow: true, emptyRowsConfig: {1: 1}, fileName: '${widget.eventCode}-');
exportcsv.myCSV(header, dataLists, fileName: '${widget.eventCode}-scouting-data');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Event', style: TextStyle(color: Colors.white)),
backgroundColor: const Color.fromARGB(255, 19, 81, 179),
iconTheme: const IconThemeData(color: Colors.white),
title: const Text('Teams'),
actions: [
IconButton(
icon: Icon(Icons.share),
onPressed: makeCSV,
icon: const Icon(Icons.share),
onPressed: isLoading || teamCodes.isEmpty ? null : makeCSV,
),
],
),
body: ListView.builder(
itemCount: teamCodes.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('${teamCodes[index]} - ${teamNames[index]}'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NotesPage(
teamName: teamNames[index],
eventCode: widget.eventCode,
teamCode: teamCodes[index],
),
),
);
},
);
},
),
body: _buildBody(),
);
}
}
Widget _buildBody() {
if (isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (errorMessage != null) {
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
errorMessage!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Colors.red,
),
),
),
);
}
if (teamCodes.isEmpty) {
return const Center(
child: Text('No teams found for this event.'),
);
}
return ListView.builder(
itemCount: teamCodes.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('${teamCodes[index]} - ${teamNames[index]}'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NotesPage(
teamName: teamNames[index],
eventCode: widget.eventCode,
teamCode: teamCodes[index],
),
),
);
},
);
},
);
}
}