Skip to content

fix: Move Hunger Games to a real view instead of overlay (#4681) #6555

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

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

LorenzoMascia
Copy link

Committer: Lorenzo Mascia [email protected]

Changes :
modified: packages/smooth_app/lib/pages/hunger_games/question_card.dart
modified: packages/smooth_app/lib/pages/hunger_games/question_page.dart
modified: packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart
modified: packages/smooth_app/lib/pages/product/product_questions_widget.dart

What

  • Moved the Hunger Games screen from an overlay to a real view using a standard Scaffold, as described in the issue.
  • This improves navigation consistency and aligns the UI with the rest of the app.

fix: Move Hunger Games to real view instead of overlay

Screenshot

Screenshot 2025-04-15 211841
Screenshot 2025-04-15 212004

Fixes bug(s)

@monsieurtanuki
Copy link
Contributor

Hi @LorenzoMascia!
First thing, have your code formatted (cf. flutter format . and CTRL-S).

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LorenzoMascia!
Of course the first thing is to fix the formatting, but please read my other comments.

builder: (context) => QuestionsPage( ),
),
).then((questionsAnswered) {
// Gestisci il risultato se necessario
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per favore, niente in italiano.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, no more Italian

@@ -77,20 +77,24 @@ class _ProductQuestionsWidgetState extends State<ProductQuestionsWidget>
Future<void> _openQuestions() async {
_trackEvent(AnalyticsEvent.questionClicked);

final int? answeredQuestions = await openQuestionPage(
Navigator.push(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No await? Then please make it explicit and use unawait(.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_QuestionPageState._numberQuestionsNext,
? AppLocalizations.of(context).robotoff_next_n_questions(10

// QuestionPageState._numberQuestionsNext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No useless comments, please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the comment and replaced the 10 with the variable numberQuestionsNext

@@ -367,7 +281,7 @@ class _LoadingQuestionsView extends StatelessWidget {
child: Center(
child: DefaultTextStyle(
textAlign: TextAlign.center,
style: const TextStyle(),
style: TextStyle(color: colorScheme.onBackground),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what makes you use explicit colors.
Anyway, if you select onBackground as a background color, shouldn't you use background as a front color?
Shouldn't you rather use primary and onPrimary?
Or no color at all, just using the app and the device's default values?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used primary, and I had to specify the color because with the light theme the lettering was not visible


void _incrementQuestionsAnswered() {
setState(() {
_questionsAnswered++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how setState works but ++_questionsAnswered would be more appropriate.

@@ -62,7 +62,7 @@ class QuestionCard extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: screenSize.height / 6,
height: screenSize.height / 4,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an Expanded give us more flexibility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Expanded
Screenshot 2025-04-16 182409
Screenshot 2025-04-16 182611

);
_currentQuestionIndex = 0;
} catch (e) {
debugPrint('Error loading next questions: $e');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No debugPrint, please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debugPrint removed

);
_currentQuestionIndex = 0;
try {
setState(() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, you're supposed to test if(mounted) before calling setState.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

}
}

void _incrementQuestionsAnswered() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot see the added value of moving the code here.
It was more relevant to put that in _saveAnswer, wasn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function removed

.toList(growable: false),
),
),
).then((questionsAnswered) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use that much the then syntax. Harder to read.
Please stick to the int? value = await myMethod(); if (value ... syntax.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the construct

@codecov-commenter
Copy link

codecov-commenter commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 1.20482% with 82 lines in your changes missing coverage. Please review.

Project coverage is 5.84%. Comparing base (4d9c7fc) to head (53dc1de).
Report is 838 commits behind head on develop.

Files with missing lines Patch % Lines
...ooth_app/lib/pages/hunger_games/question_page.dart 1.63% 60 Missing ⚠️
...b/pages/hunger_games/question_image_thumbnail.dart 0.00% 9 Missing ⚠️
...pp/lib/pages/product/product_questions_widget.dart 0.00% 8 Missing ⚠️
...pages/preferences/user_preferences_contribute.dart 0.00% 4 Missing ⚠️
...ooth_app/lib/pages/hunger_games/question_card.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #6555      +/-   ##
==========================================
- Coverage     9.54%   5.84%   -3.70%     
==========================================
  Files          325     499     +174     
  Lines        16411   29817   +13406     
==========================================
+ Hits          1567    1744     +177     
- Misses       14844   28073   +13229     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LorenzoMascia, and thank you for your changes!
I like the Expanded version, though the image size isn't correctly computed (the bottom of the big image isn't visible). That needs to be fixed (maybe removing the SizedBox and letting the system compute by itself, I don't know).
Please read my other comments.

@@ -77,16 +77,20 @@ class _ProductQuestionsWidgetState extends State<ProductQuestionsWidget>
Future<void> _openQuestions() async {
_trackEvent(AnalyticsEvent.questionClicked);

final int? answeredQuestions = await openQuestionPage(
final int? questionsAnswered = await Navigator.push<int>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, don't change the naming of the variables unless the change is very relevant.
It was probably not the case here, and the reviewer still has to check every change...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@@ -308,7 +308,13 @@ class UserPreferencesContribute extends AbstractUserPreferences {
AnalyticsHelper.trackEvent(
AnalyticsEvent.hungerGameOpened,
);
await openQuestionPage(context);

Navigator.push(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the simpler await syntax.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

],
return Expanded(
child: Column(
mainAxisSize: MainAxisSize.max, // <--- CAMBIATO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per favore...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted, sorry

Comment on lines 34 to 47
BuildContext context,
Widget child,
ImageChunkEvent? loadingProgress,
) {
if (loadingProgress == null) {
// TODO(monsieurtanuki): remove this when the image is not null anymore
return child;
}
return const Center(
child: CircularProgressIndicator.adaptive());
},
),
);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, what's the point of changing the parameter names and the coding style, except annoying the reviewer?
You literally changed nothing here, except adding an unexpected TODO with my name...
Please revert that part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

Comment on lines 13 to 14
Widget build(BuildContext context) {
return Container(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of changing the coding style? Please revert that part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

Comment on lines 27 to 28
width: constraints.maxWidth,
height: constraints.maxHeight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please try with double.infinity for width and height?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

const _QuestionPage({
class QuestionsPage extends StatefulWidget {
const QuestionsPage({
super.key,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need key, do we?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't. Deleted.

);
_currentQuestionIndex = 0;
try {
setState(() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

setState(() {
_state = const _RobotoffQuestionLoadingState();
});
_loadQuestions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unawaited(.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@@ -367,7 +274,7 @@ class _LoadingQuestionsView extends StatelessWidget {
child: Center(
child: DefaultTextStyle(
textAlign: TextAlign.center,
style: const TextStyle(),
style: TextStyle(color: colorScheme.onSurface),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please

  • make a screenshot
  • remove all your color and style changes, and then make a screenshot

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the screenshots are exactly the same.

@LorenzoMascia
Copy link
Author

The final result using BoxFit.contain instead of cover for the ìmage:

Screenshot 2025-04-21 202721

Lorenzo Mascia added 3 commits April 22, 2025 09:23
…verlay

Committer: Lorenzo Mascia <[email protected]>

Changes :
	modified:   packages/smooth_app/lib/pages/hunger_games/question_card.dart
	modified:   packages/smooth_app/lib/pages/hunger_games/question_page.dart
	modified:   packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart
	modified:   packages/smooth_app/lib/pages/product/product_questions_widget.dart
Committer: Lorenzo Mascia <[email protected]>

Changes:
	modified:   packages/smooth_app/lib/pages/hunger_games/question_card.dart
	modified:   packages/smooth_app/lib/pages/hunger_games/question_image_thumbnail.dart
	modified:   packages/smooth_app/lib/pages/hunger_games/question_page.dart
	modified:   packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart
	modified:   packages/smooth_app/lib/pages/product/product_questions_widget.dart
Committer: Lorenzo Mascia <[email protected]>

Changes:
	modified:   packages/smooth_app/lib/pages/hunger_games/question_image_thumbnail.dart
	modified:   packages/smooth_app/lib/pages/hunger_games/question_page.dart
	modified:   packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart
	modified:   packages/smooth_app/lib/pages/product/product_questions_widget.dart
@LorenzoMascia LorenzoMascia force-pushed the fix/hunger-games-view branch from 81ca678 to 3992c5c Compare April 22, 2025 07:23
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @LorenzoMascia!

If you have 10 minutes, please have a look at my comments. If you already know that you won't have time for that in a near future, please tell me.

I'm still surprised that you had to change the styles and colors, but that's another story.

progress == null
? child
: const CircularProgressIndicator.adaptive(),
child: LayoutBuilder(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we don't need a LayoutBuilder anymore, do we?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's no longer needed. I had used the builder to get the BoxConstraints during some trials, but in the end I didn’t use them.

onAnswer: onAnswer,
),
],
return Expanded(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that Expanded is relevant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it works in the same way returning directly the Column without the Expanded

@github-project-automation github-project-automation bot moved this from 💬 To discuss and validate to 🎊 Done in 🤳🥫 The Open Food Facts mobile app (Android & iOS) Apr 22, 2025
@monsieurtanuki
Copy link
Contributor

@LorenzoMascia And congratulations for your first PR here!

LorenzoMascia and others added 3 commits April 22, 2025 19:39
Committer: Lorenzo Mascia <[email protected]>

Changes:
	modified:   lib/pages/hunger_games/question_image_thumbnail.dart
	modified:   lib/pages/hunger_games/question_page.dart
@monsieurtanuki
Copy link
Contributor

Hi @LorenzoMascia!
Before I merge your code, would you please attach a screenshot?
I'm a bit worried about your choice of adding extra styles and extra colors. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Move Hunger Games to a real view, as opposed to an overlay
3 participants