Added ability to add custom teams and events.
This commit is contained in:
parent
84aaf9c527
commit
9327b6120f
8 changed files with 687 additions and 189 deletions
|
|
@ -1,30 +1,107 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:laserscouter/eventadder.dart';
|
||||
import 'teampicker.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
class EventPicker extends StatefulWidget {
|
||||
const EventPicker({super.key, required this.eventNames, required this.eventCodes});
|
||||
|
||||
class EventPicker extends StatelessWidget {
|
||||
final List<String> eventNames;
|
||||
final List<String> eventCodes;
|
||||
|
||||
const EventPicker({super.key, required this.eventNames, required this.eventCodes});
|
||||
@override
|
||||
State<EventPicker> createState() => _EventPickerState();
|
||||
}
|
||||
|
||||
class _EventPickerState extends State<EventPicker> {
|
||||
List<String> eventNames = [];
|
||||
List<String> eventCodes = [];
|
||||
List<bool> isCustom = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
eventNames = List<String>.from(widget.eventNames);
|
||||
eventCodes = List<String>.from(widget.eventCodes);
|
||||
isCustom = List<bool>.filled(widget.eventCodes.length, false);
|
||||
_refreshEvents();
|
||||
}
|
||||
|
||||
Future<void> _refreshEvents() async {
|
||||
eventNames = widget.eventNames.toList();
|
||||
eventCodes = widget.eventCodes.toList();
|
||||
isCustom = List<bool>.filled(widget.eventCodes.length, false).toList();
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final storedNames = prefs.getStringList('custom_event_names') ?? [];
|
||||
final storedCodes = prefs.getStringList('custom_event_codes') ?? [];
|
||||
|
||||
for (int i = 0; i < storedNames.length; i++) {
|
||||
if (!eventCodes.contains(storedCodes[i])) {
|
||||
eventNames.add(storedNames[i]);
|
||||
eventCodes.add(storedCodes[i]);
|
||||
isCustom.add(true);
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Event')),
|
||||
appBar: AppBar(
|
||||
title: const Text('Event'),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const EventAdder(),
|
||||
),
|
||||
);
|
||||
_refreshEvents();
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
)
|
||||
]
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: eventNames.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(eventNames[index]),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TeamPicker(
|
||||
eventCode: eventCodes[index],
|
||||
bool isEventCustom = isCustom[index];
|
||||
String eventCode = eventCodes[index];
|
||||
String eventName = eventCodes[index];
|
||||
|
||||
if (isEventCustom) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TeamPicker(
|
||||
eventCode: eventCode,
|
||||
eventName: eventName,
|
||||
isCustomOnly: isEventCustom,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TeamPicker(
|
||||
isCustomOnly: isEventCustom,
|
||||
eventName: eventName,
|
||||
eventCode: eventCode,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue