Rewrote pretty much all of it. New logo/icons. Overall did alot tbh.
This commit is contained in:
parent
5858a4a231
commit
d128768478
142 changed files with 968 additions and 3875 deletions
69
lib/core/api.dart
Normal file
69
lib/core/api.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue