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

Refactor/exams page #818

Closed
wants to merge 9 commits into from
Closed

Refactor/exams page #818

wants to merge 9 commits into from

Conversation

rubuy-74
Copy link
Contributor

@rubuy-74 rubuy-74 commented Jul 5, 2023

Closes #740
Replacing helper functions with Class Widgets in the exam's page, for more information see #737.

Review checklist

  • Terms and conditions reflect the current change
  • Contains enough appropriate tests
  • If aimed at production, writes a new summary in whatsnew/whatsnew-pt-PT
  • Properly adds an entry in changelog.md with the change
  • If PR includes UI updates/additions, its description has screenshots
  • Behavior is as expected
  • Clean, well-structured code

@bdmendes bdmendes self-requested a review July 5, 2023 14:01
@bdmendes bdmendes added this to the Mid-Summer 2023 Release milestone Jul 12, 2023
uni/lib/view/exams/exams.dart Outdated Show resolved Hide resolved
}
return Column(children: examCards);
}
}

class ExamContext extends StatelessWidget {
Copy link
Member

Choose a reason for hiding this comment

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

This might instead be the result of the lambda above.

@rubuy-74 rubuy-74 requested a review from bdmendes July 28, 2023 12:19
@codecov
Copy link

codecov bot commented Aug 13, 2023

Codecov Report

Merging #818 (6acbca6) into develop (6edba2d) will decrease coverage by 0%.
Report is 2 commits behind head on develop.
The diff coverage is 100%.

Additional details and impacted files
@@          Coverage Diff           @@
##           develop   #818   +/-   ##
======================================
- Coverage       16%    16%   -0%     
======================================
  Files          207    207           
  Lines         6487   6485    -2     
======================================
- Hits          1004    999    -5     
- Misses        5483   5486    +3     

uni/lib/view/exams/exams.dart Outdated Show resolved Hide resolved
onChanged: (value) {
setState(() {
filteredExams[key] = value!;
widget.filteredExams[key] = value!;
Copy link
Member

Choose a reason for hiding this comment

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

Notice that you are not changing the widget's state, but rather the widgets properties. It might be working since setState does trigger a rebuild of the entire widget, but I believe there's a better way to do this.
Ideally, the widget should not change outside values by aliasing, but through a callback. How about:

  • The widget receives the initial filtered list via an immutable list view
  • The widget mutates it via a callback

Copy link
Member

@bdmendes bdmendes left a comment

Choose a reason for hiding this comment

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

Note that we are still modifying the list by aliasing, but only encapsulating that in a function. Make sure to mutate the global state via callback, and to receive an immutable view of it to create the widget.

@@ -6,9 +6,12 @@ import 'package:uni/model/providers/lazy/exam_provider.dart';

class ExamFilterForm extends StatefulWidget {
const ExamFilterForm(this.filteredExamsTypes, {super.key});
Copy link
Member

Choose a reason for hiding this comment

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

Now make this list an immutable view and create a local version of it in the state class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't the widget.filteredExamTypes already a local version of the immutable view?

Copy link
Member

Choose a reason for hiding this comment

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

The widget is receiving a Map object that is a pointer to a collection of key-value structures probably on the heap. This means that it is mutable.
Consider using UnmodifiableMapView from the collections package. This ensures that you need to create a copy of that map as a member of the state class, which is the best way to do it in my opinion.
Tldr don't modify any widget prop in its lifecycle

@@ -6,9 +6,12 @@ import 'package:uni/model/providers/lazy/exam_provider.dart';

class ExamFilterForm extends StatefulWidget {
const ExamFilterForm(this.filteredExamsTypes, {super.key});
Copy link
Member

Choose a reason for hiding this comment

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

The widget is receiving a Map object that is a pointer to a collection of key-value structures probably on the heap. This means that it is mutable.
Consider using UnmodifiableMapView from the collections package. This ensures that you need to create a copy of that map as a member of the state class, which is the best way to do it in my opinion.
Tldr don't modify any widget prop in its lifecycle

Comment on lines 20 to 23
widget.filteredExamsTypes[key] = value!;
Provider.of<ExamProvider>(context, listen: false)
.setFilteredExams(widget.filteredExamsTypes);
});
Copy link
Member

Choose a reason for hiding this comment

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

You seem to still be modifying the widget prop. Perhaps I could be of help sometime in the next few days so that you get what I was saying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay.

@bdmendes bdmendes force-pushed the refactor/exams-page branch 4 times, most recently from 6b95e22 to 49e8ee8 Compare December 8, 2023 15:15
Co-authored-by: Rubem-Viscard <[email protected]>
bdmendes
bdmendes previously approved these changes Dec 8, 2023
@bdmendes bdmendes requested a review from a team December 16, 2023 12:53
@bdmendes bdmendes removed this from the Back to School 2023 milestone Dec 16, 2023
Copy link
Member

@bdmendes bdmendes left a comment

Choose a reason for hiding this comment

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

@rubuy-74 this might be superseded by #1057. Please merge and/or check if this is still needed.

@rubuy-74
Copy link
Contributor Author

Since #1057, this won't be needed.

@rubuy-74 rubuy-74 closed this Dec 24, 2023
@DGoiana DGoiana deleted the refactor/exams-page branch June 19, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor helper functions in the exam's page
2 participants