-
Notifications
You must be signed in to change notification settings - Fork 18
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
Refactor/exams page #818
Conversation
uni/lib/view/exams/exams.dart
Outdated
} | ||
return Column(children: examCards); | ||
} | ||
} | ||
|
||
class ExamContext extends StatelessWidget { |
There was a problem hiding this comment.
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.
Codecov Report
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/controller/local_storage/app_refresh_times_database.dart
Outdated
Show resolved
Hide resolved
949f65a
to
95b4549
Compare
af74a92
to
0bdd78c
Compare
43e6780
to
d2ed63a
Compare
onChanged: (value) { | ||
setState(() { | ||
filteredExams[key] = value!; | ||
widget.filteredExams[key] = value!; |
There was a problem hiding this comment.
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
f35d21b
to
8df6a73
Compare
4807ce3
to
d3e75bb
Compare
60c0b08
to
d010780
Compare
There was a problem hiding this 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}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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
6d10ab4
to
7f304dc
Compare
widget.filteredExamsTypes[key] = value!; | ||
Provider.of<ExamProvider>(context, listen: false) | ||
.setFilteredExams(widget.filteredExamsTypes); | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
6b95e22
to
49e8ee8
Compare
Co-authored-by: Rubem-Viscard <[email protected]>
49e8ee8
to
89192c6
Compare
22ed352
to
8358ebc
Compare
8358ebc
to
9a8e989
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since #1057, this won't be needed. |
Closes #740
Replacing helper functions with Class Widgets in the exam's page, for more information see #737.
Review checklist
whatsnew/whatsnew-pt-PT
changelog.md
with the change