Skip to content
Snippets Groups Projects
Commit 1f651d73 authored by Sunny Singh's avatar Sunny Singh
Browse files

add bonus question with accelerometer

parent 123eb5e9
No related branches found
No related tags found
No related merge requests found
Pipeline #376722 passed
......@@ -8,11 +8,13 @@
import 'package:cloud_firestore_web/cloud_firestore_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:sensors_plus/src/sensors_plus_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
void registerPlugins([final Registrar? pluginRegistrar]) {
final Registrar registrar = pluginRegistrar ?? webPluginRegistrar;
FirebaseFirestoreWeb.registerWith(registrar);
FirebaseCoreWeb.registerWith(registrar);
WebSensorsPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
......@@ -91,6 +91,12 @@
"packageUri": "lib/",
"languageVersion": "3.3"
},
{
"name": "flutter_compass",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_compass-0.8.1",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "flutter_lints",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_lints-3.0.2",
......@@ -133,6 +139,12 @@
"packageUri": "lib/",
"languageVersion": "3.0"
},
{
"name": "logging",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/logging-1.3.0",
"packageUri": "lib/",
"languageVersion": "3.4"
},
{
"name": "matcher",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/matcher-0.12.16+1",
......@@ -163,6 +175,18 @@
"packageUri": "lib/",
"languageVersion": "3.0"
},
{
"name": "sensors_plus",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus-6.1.1",
"packageUri": "lib/",
"languageVersion": "3.3"
},
{
"name": "sensors_plus_platform_interface",
"rootUri": "file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus_platform_interface-2.0.1",
"packageUri": "lib/",
"languageVersion": "2.18"
},
{
"name": "sky_engine",
"rootUri": "file:///C:/Users/Sunny/Dev/flutter/flutter/flutter/bin/cache/pkg/sky_engine",
......@@ -230,7 +254,7 @@
"languageVersion": "3.2"
}
],
"generated": "2024-12-11T23:42:08.754845Z",
"generated": "2025-01-10T14:32:53.536941Z",
"generator": "pub",
"generatorVersion": "3.5.4",
"flutterRoot": "file:///C:/Users/Sunny/Dev/flutter/flutter/flutter",
......
......@@ -54,6 +54,10 @@ firebase_core_web
3.4
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.18.2/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.18.2/lib/
flutter_compass
2.12
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_compass-0.8.1/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_compass-0.8.1/lib/
flutter_lints
3.1
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_lints-3.0.2/
......@@ -74,6 +78,10 @@ lints
3.0
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/lints-3.0.0/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/lints-3.0.0/lib/
logging
3.4
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/logging-1.3.0/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/logging-1.3.0/lib/
matcher
3.0
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/matcher-0.12.16+1/
......@@ -94,6 +102,14 @@ plugin_platform_interface
3.0
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/plugin_platform_interface-2.1.8/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/plugin_platform_interface-2.1.8/lib/
sensors_plus
3.3
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus-6.1.1/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus-6.1.1/lib/
sensors_plus_platform_interface
2.18
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus_platform_interface-2.0.1/
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/sensors_plus_platform_interface-2.0.1/lib/
source_span
2.18
file:///C:/Users/Sunny/AppData/Local/Pub/Cache/hosted/pub.dev/source_span-1.10.0/
......
......@@ -3,3 +3,5 @@ cloud_firestore=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\c
cloud_firestore_web=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\cloud_firestore_web-3.12.5\\
firebase_core=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_core-2.32.0\\
firebase_core_web=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_core_web-2.18.2\\
flutter_compass=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_compass-0.8.1\\
sensors_plus=C:\\Users\\Sunny\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\sensors_plus-6.1.1\\
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"cloud_firestore_web","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore_web-3.12.5\\\\","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core_web-2.18.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"cloud_firestore","dependencies":["cloud_firestore_web","firebase_core"]},{"name":"cloud_firestore_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]}],"date_created":"2024-12-12 00:42:08.997193","version":"3.24.5","swift_package_manager_enabled":false}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]},{"name":"flutter_compass","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_compass-0.8.1\\\\","native_build":true,"dependencies":[]},{"name":"sensors_plus","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sensors_plus-6.1.1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]},{"name":"flutter_compass","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_compass-0.8.1\\\\","native_build":true,"dependencies":[]},{"name":"sensors_plus","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sensors_plus-6.1.1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"linux":[],"windows":[{"name":"cloud_firestore","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore-4.17.5\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-2.32.0\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"cloud_firestore_web","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\cloud_firestore_web-3.12.5\\\\","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core_web-2.18.2\\\\","dependencies":[]},{"name":"sensors_plus","path":"C:\\\\Users\\\\Sunny\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sensors_plus-6.1.1\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"cloud_firestore","dependencies":["cloud_firestore_web","firebase_core"]},{"name":"cloud_firestore_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"flutter_compass","dependencies":[]},{"name":"sensors_plus","dependencies":[]}],"date_created":"2025-01-10 15:32:53.728377","version":"3.24.5","swift_package_manager_enabled":false}
\ No newline at end of file
......@@ -4,4 +4,6 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
......@@ -45,5 +45,7 @@
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to show compass data.</string>
</dict>
</plist>
......@@ -254,93 +254,60 @@ class _QuestionScreenState extends State<QuestionScreen> {
});
}
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('games')
.doc(widget.gameCode)
.collection('questions')
.orderBy('createdAt')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
return const Center(child: CircularProgressIndicator());
}
questions = snapshot.data!.docs;
// Check if we've reached the end of questions
if (_currentQuestionIndex >= questions.length) {
return const Center(
child: Text(
'Game Complete!',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
);
}
final questionDoc = questions[_currentQuestionIndex];
final question = questionDoc.data() as Map<String, dynamic>?; // Cast to Map<String, dynamic>
if (question == null) {
return const Center(child: Text('Error: Question data is null'));
}
return Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Question ${_currentQuestionIndex + 1} of ${questions.length}',
style: Theme.of(context).textTheme.titleLarge,
return Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Question ${_currentQuestionIndex + 1} of ${questions.length}',
style: Theme.of(context).textTheme.titleLarge,
),
),
Text(
gameData['questions'][_currentQuestionIndex]['text'] as String,
style: Theme.of(context).textTheme.headlineMedium,
),
if (_wasCorrect != null)
Column(
children: [
Text(
'Correct Answer: $_correctAnswer',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
Text(
question['text'] as String,
style: Theme.of(context).textTheme.headlineMedium,
),
if (_wasCorrect != null)
Column(
children: [
Text(
'Correct Answer: $_correctAnswer',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
'Your Answer: $_userAnswer',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
Text(
'Points Gained: $_pointsGained',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
],
Text(
'Your Answer: $_userAnswer',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
controller: _answerController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Enter your answer',
border: OutlineInputBorder(),
),
Text(
'Points Gained: $_pointsGained',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
],
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
controller: _answerController,
decoration: const InputDecoration(
labelText: 'Your Answer',
),
if (!_hasAnswered)
ElevatedButton(
onPressed: _submitAnswer,
child: const Text('Submit Answer'),
),
if (_hasAnswered)
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: _nextQuestion,
child: const Text('Next Question'),
),
),
],
);
},
keyboardType: TextInputType.number,
),
),
if (!_hasAnswered)
ElevatedButton(
onPressed: _submitAnswer,
child: const Text('Submit Answer'),
),
if (_hasAnswered)
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: _nextQuestion,
child: const Text('Next Question'),
),
),
],
);
},
),
......
......@@ -4,8 +4,9 @@ import 'main.dart'; // Ensure this imports the HomeScreen
class ResultsScreen extends StatelessWidget {
final String gameCode;
final String playerName; // Add playerName to identify the current user
const ResultsScreen({super.key, required this.gameCode});
const ResultsScreen({super.key, required this.gameCode, required this.playerName});
@override
Widget build(BuildContext context) {
......@@ -38,6 +39,9 @@ class ResultsScreen extends StatelessWidget {
itemCount: players.length,
itemBuilder: (context, index) {
final player = players[index].data() as Map<String, dynamic>;
final isCurrentUser = player['name'] == playerName;
final displayName = isCurrentUser ? '${player['name']} (You)' : player['name'];
return Card(
elevation: 2.0,
margin: const EdgeInsets.symmetric(vertical: 8.0),
......@@ -50,7 +54,7 @@ class ResultsScreen extends StatelessWidget {
),
),
title: Text(
player['name'] as String,
displayName,
style: const TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
),
trailing: Text(
......@@ -89,6 +93,28 @@ class ResultsScreen extends StatelessWidget {
),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
width: double.infinity, // Make the button full-width
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const HomeScreen()),
);
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16.0),
backgroundColor: Colors.deepPurple,
),
child: const Text(
'Start/Join a New Game',
style: TextStyle(fontSize: 18.0),
),
),
),
),
],
),
),
......
......@@ -118,6 +118,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_compass:
dependency: "direct main"
description:
name: flutter_compass
sha256: "1b4d7e6c95a675ec8482b5c9c9ccf1ebf0ced3dbec59dce28ad609da953de850"
url: "https://pub.dev"
source: hosted
version: "0.8.1"
flutter_lints:
dependency: "direct dev"
description:
......@@ -168,6 +176,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
url: "https://pub.dev"
source: hosted
version: "1.3.0"
matcher:
dependency: transitive
description:
......@@ -208,6 +224,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
sensors_plus:
dependency: "direct main"
description:
name: sensors_plus
sha256: "905282c917c6bb731c242f928665c2ea15445aa491249dea9d98d7c79dc8fd39"
url: "https://pub.dev"
source: hosted
version: "6.1.1"
sensors_plus_platform_interface:
dependency: transitive
description:
name: sensors_plus_platform_interface
sha256: "58815d2f5e46c0c41c40fb39375d3f127306f7742efe3b891c0b1c87e2b5cd5d"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
......
......@@ -13,6 +13,8 @@ dependencies:
firebase_core: ^2.24.2
cloud_firestore: ^4.13.6
cupertino_icons: ^1.0.8
flutter_compass: ^0.8.1
sensors_plus: ^6.1.1
dev_dependencies:
flutter_test:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment