Added team select page.
This commit is contained in:
parent
123dfbd192
commit
08f182ebc9
7 changed files with 125 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<application
|
<application
|
||||||
android:label="laserscouter"
|
android:label="Laser Scouter"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/launcher_icon">
|
android:icon="@mipmap/launcher_icon">
|
||||||
<activity
|
<activity
|
||||||
|
|
@ -42,4 +42,5 @@
|
||||||
<data android:mimeType="text/plain"/>
|
<data android:mimeType="text/plain"/>
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
</Testables>
|
</Testables>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Profile"
|
buildConfiguration = "Release"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
// login.dart
|
// eventpicker.dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'login.dart';
|
import 'teampicker.dart';
|
||||||
|
|
||||||
class EventPicker extends StatelessWidget {
|
class EventPicker extends StatelessWidget {
|
||||||
|
final List<String> eventNames;
|
||||||
|
final List<String> eventCodes;
|
||||||
|
final String apiKey;
|
||||||
|
|
||||||
|
EventPicker({required this.eventNames, required this.eventCodes, required this.apiKey});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -11,6 +17,25 @@ class EventPicker extends StatelessWidget {
|
||||||
backgroundColor: const Color.fromARGB(255, 19, 81, 179),
|
backgroundColor: const Color.fromARGB(255, 19, 81, 179),
|
||||||
iconTheme: const IconThemeData(color: Colors.white),
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
),
|
),
|
||||||
|
body: ListView.builder(
|
||||||
|
itemCount: eventNames.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(eventNames[index]),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => TeamPicker(
|
||||||
|
apiKey: apiKey,
|
||||||
|
eventCode: eventCodes[index],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} // Call the function with the apiKey
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ import 'eventpicker.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
void getData(String apiKey, teamNumber) async {
|
void getData(String apiKey, String teamNumber, Function(List<String>, List<String>) callback) async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse('https://www.thebluealliance.com/api/v3/team/frc$teamNumber/events/2025'),
|
Uri.parse('https://www.thebluealliance.com/api/v3/team/frc$teamNumber/events/2025'),
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -14,11 +14,13 @@ void getData(String apiKey, teamNumber) async {
|
||||||
String data = response.body;
|
String data = response.body;
|
||||||
var decodedData = jsonDecode(data);
|
var decodedData = jsonDecode(data);
|
||||||
List<String> eventNames = [];
|
List<String> eventNames = [];
|
||||||
|
List<String> eventCodes = [];
|
||||||
|
|
||||||
for (var event in decodedData) {
|
for (var event in decodedData) {
|
||||||
eventNames.add(event['name']);
|
eventNames.add(event['name']);
|
||||||
|
eventCodes.add(event['key']);
|
||||||
}
|
}
|
||||||
print(eventNames);
|
callback(eventNames, eventCodes);
|
||||||
} else {
|
} else {
|
||||||
print(response.statusCode);
|
print(response.statusCode);
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +66,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -99,11 +100,18 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
String teamNumber = _teamNumberController.text;
|
String teamNumber = _teamNumberController.text;
|
||||||
String apiKey = _apiKeyController.text;
|
String apiKey = _apiKeyController.text;
|
||||||
getData(apiKey, teamNumber);
|
getData(apiKey, teamNumber, (eventNames, eventCodes) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => EventPicker()),
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EventPicker(
|
||||||
|
eventNames: eventNames,
|
||||||
|
eventCodes: eventCodes,
|
||||||
|
apiKey: apiKey,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: const Text('Login'),
|
child: const Text('Login'),
|
||||||
),
|
),
|
||||||
|
|
@ -113,4 +121,3 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
73
lib/teampicker.dart
Normal file
73
lib/teampicker.dart
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
void getData(String apiKey, String eventCode, Function(List<String>, List<String>) callback) async {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('https://www.thebluealliance.com/api/v3/event/$eventCode/teams'),
|
||||||
|
headers: {
|
||||||
|
'X-TBA-Auth-Key': apiKey,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TeamPicker extends StatefulWidget {
|
||||||
|
final String apiKey;
|
||||||
|
final String eventCode;
|
||||||
|
|
||||||
|
TeamPicker({required this.apiKey, required this.eventCode});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TeamPickerState createState() => _TeamPickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TeamPickerState extends State<TeamPicker> {
|
||||||
|
List<String> teamNames = [];
|
||||||
|
List<String> teamCodes = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
getData(widget.apiKey, widget.eventCode, (names, codes) {
|
||||||
|
setState(() {
|
||||||
|
teamNames = names;
|
||||||
|
teamCodes = codes;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@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),
|
||||||
|
),
|
||||||
|
body: ListView.builder(
|
||||||
|
itemCount: teamCodes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text('${teamCodes[index]} - ${teamNames[index]}'),
|
||||||
|
onTap: () {
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,5 +8,7 @@
|
||||||
<true/>
|
<true/>
|
||||||
<key>com.apple.security.network.server</key>
|
<key>com.apple.security.network.server</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>com.apple.security.network.client</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,7 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>com.apple.security.network.client</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue