Skip to content

Commit

Permalink
add factcheck result screen
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsasse committed May 23, 2022
1 parent 7049d7d commit cc707c9
Show file tree
Hide file tree
Showing 36 changed files with 484 additions and 405 deletions.
Binary file modified android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/appLogo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,4 @@
/* End XCConfigurationList section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
}
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 24 additions & 24 deletions lib/models/enemy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,30 @@ class Enemy {
// if an open game exists, safe it.
if (map?[DbFields.friendshipOpenGame] != null) {
openGame = Game(
//object Id
map?[DbFields.friendshipOpenGame]["objectId"],
// enemyAnswers
map?[DbFields.friendshipOpenGame][playerIndex == 0
? DbFields.gameAnswersPlayer2
: DbFields.gameAnswersPlayer1]
.map((x) => x["value"])
.toList()
.cast<bool>(),
// player answers
map?[DbFields.friendshipOpenGame][playerIndex == 0
? DbFields.gameAnswersPlayer1
: DbFields.gameAnswersPlayer2]
.map((x) => x["value"])
.toList()
.cast<bool>(),
playerIndex,
map?[DbFields.friendshipOpenGame][DbFields.gameStatementIds]
.map((x) => x["value"])
.toList()
.cast<String>(),
map?[DbFields.friendshipOpenGame][DbFields.gameWithTimer],
map?[DbFields.friendshipOpenGame][DbFields.gameRequestingPlayerIndex],
);
//object Id
map?[DbFields.friendshipOpenGame]["objectId"],
// enemyAnswers
map?[DbFields.friendshipOpenGame][playerIndex == 0
? DbFields.gameAnswersPlayer2
: DbFields.gameAnswersPlayer1]
.map((x) => x["value"])
.toList()
.cast<bool>(),
// player answers
map?[DbFields.friendshipOpenGame][playerIndex == 0
? DbFields.gameAnswersPlayer1
: DbFields.gameAnswersPlayer2]
.map((x) => x["value"])
.toList()
.cast<bool>(),
playerIndex,
map?[DbFields.friendshipOpenGame][DbFields.gameStatementIds]
.map((x) => x["value"])
.toList()
.cast<String>(),
map?[DbFields.friendshipOpenGame][DbFields.gameWithTimer],
map?[DbFields.friendshipOpenGame][DbFields.gameRequestingPlayerIndex],
null);
} else {
openGame = null;
}
Expand Down
12 changes: 9 additions & 3 deletions lib/models/game.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:quellenreiter_app/constants/constants.dart';
import 'package:quellenreiter_app/models/statement.dart';


class Game {
String? id;
int round = 0;
Expand All @@ -17,8 +16,15 @@ class Game {
// Game.fromMap(Map<String, dynamic>? map) {

// }
Game(this.id, this.enemyAnswers, this.playerAnswers, this.playerIndex,
this.statementIds, this.withTimer, this.requestingPlayerIndex);
Game(
this.id,
this.enemyAnswers,
this.playerAnswers,
this.playerIndex,
this.statementIds,
this.withTimer,
this.requestingPlayerIndex,
this.statements);

Game.empty(bool timer, int pIndex) {
// where to get statement ids? download all possible and pickRandom on device.
Expand Down
17 changes: 17 additions & 0 deletions lib/models/quellenreiter_app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class QuellenreiterAppState extends ChangeNotifier {
Routes _route = Routes.login;
Routes get route => _route;
set route(value) {
//refetch friends everytime we go to friends/startGame/openGames.
if (value == Routes.friends ||
value == Routes.startGame ||
value == Routes.openGames) {
getFriends();
}
// // refetch user everytime we got to homescreen.
// if (route == Routes.home) {
// db.checkToken(_checkTokenCallback);
// }
_route = value;
notifyListeners();
}
Expand Down Expand Up @@ -344,6 +349,18 @@ class QuellenreiterAppState extends ChangeNotifier {
return;
}

void getCurrentStatements() async {
currentEnemy!.openGame!.statements =
await db.getStatements(currentEnemy!.openGame!.statementIds!);
if (currentEnemy!.openGame!.statements == null) {
route = Routes.gameReadyToStart;
error = "Statements konnten nicht geladen werden.";
return;
}
route = Routes.gameResults;
return;
}

void playGame() async {
route = Routes.loading;
if (currentEnemy!.openGame != null &&
Expand Down
16 changes: 10 additions & 6 deletions lib/navigation/quellenreiter_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ class QuellenreiterRouterDelegate extends RouterDelegate<QuellenreiterRoutePath>
if (appState.currentEnemy != null &&
appState.currentEnemy!.openGame!.gameFinished()) {
return [
const MaterialPage(
key: ValueKey('GameResultsScreen'),
child: GameResultsScreen(),
MaterialPage(
key: const ValueKey('GameResultsScreen'),
child: GameResultsScreen(
appState: appState,
),
),
];
}
Expand All @@ -152,9 +154,11 @@ class QuellenreiterRouterDelegate extends RouterDelegate<QuellenreiterRoutePath>
];
case Routes.gameResults:
return [
const MaterialPage(
key: ValueKey('GameResultsScreen'),
child: GameResultsScreen(),
MaterialPage(
key: const ValueKey('GameResultsScreen'),
child: GameResultsScreen(
appState: appState,
),
),
];

Expand Down
60 changes: 30 additions & 30 deletions lib/provider/database_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -488,36 +488,36 @@ class DatabaseUtils {
return null;
} else {
return Game(
//object Id
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
["objectId"],
// enemyAnswers
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame][
enemy.playerIndex == 0
? DbFields.gameAnswersPlayer2
: DbFields.gameAnswersPlayer1]
.map((x) => x["value"])
.toList()
.cast<bool>(),
// player answers
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame][
enemy.playerIndex == 0
? DbFields.gameAnswersPlayer1
: DbFields.gameAnswersPlayer2]
.map((x) => x["value"])
.toList()
.cast<bool>(),
enemy.playerIndex,
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameStatementIds]
.map((x) => x["value"])
.toList()
.cast<String>(),
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameWithTimer],
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameRequestingPlayerIndex],
);
//object Id
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
["objectId"],
// enemyAnswers
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame][
enemy.playerIndex == 0
? DbFields.gameAnswersPlayer2
: DbFields.gameAnswersPlayer1]
.map((x) => x["value"])
.toList()
.cast<bool>(),
// player answers
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame][
enemy.playerIndex == 0
? DbFields.gameAnswersPlayer1
: DbFields.gameAnswersPlayer2]
.map((x) => x["value"])
.toList()
.cast<bool>(),
enemy.playerIndex,
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameStatementIds]
.map((x) => x["value"])
.toList()
.cast<String>(),
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameWithTimer],
mutationResult.data?["createOpenGame"][DbFields.friendshipOpenGame]
[DbFields.gameRequestingPlayerIndex],
null);
}
}

Expand Down
45 changes: 42 additions & 3 deletions lib/screens/game/game_results_screen.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
import 'package:flutter/material.dart';
import 'package:quellenreiter_app/models/quellenreiter_app_state.dart';

import '../../constants/constants.dart';
import '../../widgets/statement_card.dart';

class GameResultsScreen extends StatefulWidget {
const GameResultsScreen({Key? key}) : super(key: key);
const GameResultsScreen({Key? key, required this.appState}) : super(key: key);

final QuellenreiterAppState appState;
@override
State<GameResultsScreen> createState() => _GameResultsScreenState();
}

class _GameResultsScreenState extends State<GameResultsScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: const Center(child: Text("results not implemented.")),
if (widget.appState.currentEnemy!.openGame!.statements == null) {
widget.appState.getCurrentStatements();
}
return Scaffold(
appBar: AppBar(
title: const Text("Faktenchecks"),
),
body: widget.appState.currentEnemy!.openGame!.statements == null
? Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.only(bottom: 50),
child: ListView.builder(
itemCount: widget
.appState.currentEnemy!.openGame!.playerAnswers.length,
itemBuilder: (BuildContext context, int index) {
return StatementCard(
statement: widget.appState.currentEnemy!.openGame!
.statements!.statements[index],
);
},
),
),
bottomSheet: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding:
const EdgeInsets.only(bottom: 30, top: 10, left: 20, right: 20),
child: TextButton(
child: const Text("weiter"),
onPressed: () => widget.appState.route = Routes.gameReadyToStart,
),
),
],
),
);
}
}
14 changes: 8 additions & 6 deletions lib/screens/game/quest_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class _QuestScreenState extends State<QuestScreen>
// But only if withTimer. Else doing research and closing the app is welcome.
if (widget.appState.currentEnemy!.openGame!.withTimer) {
widget.appState.currentEnemy!.openGame!.playerAnswers.add(false);
// Start timer when build is finished.
WidgetsBinding.instance
.addPostFrameCallback((_) => timerController.start());
}
// show error if statements not downloaded.
if (widget.appState.currentEnemy!.openGame!.statements == null) {
return const Scaffold(
body: Text("Fehler"),
);
}
// Start timer when build is finished.
WidgetsBinding.instance
.addPostFrameCallback((_) => timerController.start());

return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -278,15 +278,17 @@ class _QuestScreenState extends State<QuestScreen>
// if its the end of the round (after 3 statements)
if (!widget.appState.currentEnemy!.openGame!.isPlayersTurn()) {
//return to readyToStartGameScreen
widget.appState.route = Routes.gameReadyToStart;
widget.appState.route = Routes.gameResults;
} else if (widget.appState.currentEnemy!.openGame!.gameFinished()) {
widget.appState.route = Routes.gameReadyToStart;
widget.appState.route = Routes.gameResults;
} else {
widget.appState.route = Routes.quest;
// show some inbetween screen
await Future.delayed(const Duration(seconds: 3), () {});
Navigator.of(context).pop();
timerController.restart();
if (widget.appState.currentEnemy!.openGame!.withTimer) {
timerController.restart();
}
}
HapticFeedback.mediumImpact();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/screens/game/ready_to_start_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ class _ReadyToStartScreenState extends State<ReadyToStartScreen> {
],
),
),
ElevatedButton.icon(
onPressed: () => widget.appState.route = Routes.gameResults,
icon: const Icon(Icons.fact_check),
label: const Text("zu den Faktenchecks"),
),
const Text("Punktestand:"),
Flexible(
child: Row(
Expand Down
Loading

0 comments on commit cc707c9

Please sign in to comment.