Skip to content

Commit

Permalink
Merge pull request #38 from FRC2706/dev
Browse files Browse the repository at this point in the history
v1.0.12
  • Loading branch information
jwt2706 authored Mar 8, 2024
2 parents c4e7872 + 84de541 commit 24c4908
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
4 changes: 2 additions & 2 deletions assets/games/2024.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
},
{
"name": "Event",
"defaultValue": "insert code for north bay",
"choices": ["Newmarket", "North Bay"],
"required": true,
"type": "text"
"type": "radio"
},
{
"name": "Match #",
Expand Down
51 changes: 45 additions & 6 deletions lib/screens/send_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,50 @@ class _SendDataState extends State<SendData> {
await prefs.setStringList('savedGames', savedGames);
}

Future<void> sendDataToGoogleSheets() async {
Future<void> validate() async {
await loadEnv();
SharedPreferences prefs = await SharedPreferences.getInstance();
bool isAuthenticated = prefs.getBool('isAuthenticated') ?? false;

if (!isAuthenticated) {
String? passcode;
await showDialog<String>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Enter passcode'),
content: TextField(
obscureText: true,
onChanged: (value) {
passcode = value; // Update passcode
},
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
);
},
);

if (passcode == dotenv.env['PASSCODE']) {
await prefs.setBool('isAuthenticated', true);
sendDataToGoogleSheets();
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Wrong passcode!")),
);
}
} else { // already authenticated
sendDataToGoogleSheets();
}
}

Future<void> sendDataToGoogleSheets() async {
String message = '';

try {
Expand Down Expand Up @@ -78,9 +120,6 @@ class _SendDataState extends State<SendData> {
}
// Clear the saved games after sending them
final a = await prefs.setStringList('savedGames', []);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Cleared games: $a')),
);
}

// Send current game
Expand Down Expand Up @@ -124,7 +163,7 @@ class _SendDataState extends State<SendData> {
title:
Text('Are you sure you want to return to home?'),
content: Text(
'All unsaved data will be sent to the shadow realm.',
'All unsaved data will be sent to the shadow realm. If the page behind is blank anyway, no worries.',
style:
TextStyle(fontSize: 12, color: Colors.red)),
actions: [
Expand Down Expand Up @@ -275,7 +314,7 @@ class _SendDataState extends State<SendData> {
);
},
);
sendDataToGoogleSheets().then((_) {
validate().then((_) { //send to google sheets, but authenticate first
if (!isCancelled) {
Navigator.of(context).pop();
}
Expand Down

0 comments on commit 24c4908

Please sign in to comment.