From 84de541ea0c3c0b3fe980a9b1ce5f0e394f7bbdb Mon Sep 17 00:00:00 2001 From: jwt2706 Date: Thu, 7 Mar 2024 21:23:56 -0500 Subject: [PATCH] various fixes and patches before comp --- assets/games/2024.json | 4 +-- lib/screens/send_data.dart | 51 +++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/assets/games/2024.json b/assets/games/2024.json index 3b96531..5e64dd8 100644 --- a/assets/games/2024.json +++ b/assets/games/2024.json @@ -7,9 +7,9 @@ }, { "name": "Event", - "defaultValue": "insert code for north bay", + "choices": ["Newmarket", "North Bay"], "required": true, - "type": "text" + "type": "radio" }, { "name": "Match #", diff --git a/lib/screens/send_data.dart b/lib/screens/send_data.dart index ac6855b..7f23fd7 100644 --- a/lib/screens/send_data.dart +++ b/lib/screens/send_data.dart @@ -47,8 +47,50 @@ class _SendDataState extends State { await prefs.setStringList('savedGames', savedGames); } - Future sendDataToGoogleSheets() async { + Future validate() async { await loadEnv(); + SharedPreferences prefs = await SharedPreferences.getInstance(); + bool isAuthenticated = prefs.getBool('isAuthenticated') ?? false; + + if (!isAuthenticated) { + String? passcode; + await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Enter passcode'), + content: TextField( + obscureText: true, + onChanged: (value) { + passcode = value; // Update passcode + }, + ), + actions: [ + 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 sendDataToGoogleSheets() async { String message = ''; try { @@ -78,9 +120,6 @@ class _SendDataState extends State { } // 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 @@ -124,7 +163,7 @@ class _SendDataState extends State { 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: [ @@ -275,7 +314,7 @@ class _SendDataState extends State { ); }, ); - sendDataToGoogleSheets().then((_) { + validate().then((_) { //send to google sheets, but authenticate first if (!isCancelled) { Navigator.of(context).pop(); }