Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.12 #38

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading