Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

refactor(capture_page): cubit usage adjustments #52

Merged
merged 2 commits into from
Feb 18, 2022

Conversation

felangel
Copy link
Contributor

Description

  • refactor(capture_page): cubit usage adjustments

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@felangel felangel requested a review from Jan-Stepien February 17, 2022 16:32
),
const SizedBox(height: 55),
// TODO(Jan-Stepien): implement Need Help button
TextButton(
onPressed: context.read<CaptureCubit>().callNeedHelp,
onPressed: () => context.read<CaptureCubit>().callNeedHelp(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the tear-off because context.read will get call on each build unnecessarily.

),
),
),
BlocSelector<CaptureCubit, CaptureCubitState, bool>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using BlocSelector here to scope rebuilds

Copy link
Contributor

Choose a reason for hiding this comment

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

i get it, all fine

@felangel felangel mentioned this pull request Feb 17, 2022
7 tasks
Comment on lines +262 to +265
extension on CaptureCubitState {
bool get isScoreSelected => score != -1;
bool get canSubmit => score != -1 && chipIndexes.isNotEmpty;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hows this better than getters on cubit? i dont really get it

Copy link
Contributor Author

@felangel felangel Feb 17, 2022

Choose a reason for hiding this comment

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

Extension in the UI indicates that this is purely presentation logic that is "syntactic sugar". I recommend avoiding exposing public methods to query state information from the cubit directly because ideally the cubit should only be accessed in order notify of changes in the UI. Getters on the cubit are error prone because they don't trigger rebuilds when the computed value changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, it wont trigger changes and we want to keep the state as a complete definition, i see that, thanks

? NpsColors.colorWhite
: NpsColors.colorPrimary1,
(index) {
final isSelected = context.select(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is to reduce of 'watch rebuilds' ? from 2 to 1?

Copy link
Contributor Author

@felangel felangel Feb 17, 2022

Choose a reason for hiding this comment

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

Yeah I apologize if I was unclear when I said scope the watches as low as possible. I meant scope them to the lowest BuildContext. Having multiple watches on the same context is less efficient than a single top level watch.

Copy link
Contributor

Choose a reason for hiding this comment

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

It makes sense,
Im super greatfull for a review, all your comments are very helpful

Copy link
Contributor

@Jan-Stepien Jan-Stepien left a comment

Choose a reason for hiding this comment

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

I rly dont get the advantage of Extension over in cubit implementation, but rest is nice optimization

@Jan-Stepien Jan-Stepien merged commit 7b4d2c2 into capture_view Feb 18, 2022
@Jan-Stepien Jan-Stepien deleted the refactor/capture_page-bloc-updates branch February 18, 2022 09:46
Jan-Stepien pushed a commit that referenced this pull request Feb 18, 2022
* Add animations to capture view

* button styling changes

* fix unit tests

* split apptheme to seperate file

* implicit scaffold's background theme

* use project barrel file

* barrel coverage fix

* code review fixes

* implement PR's comments

* theme fix

* top level theme

* max score in cubit state

* move business logic to cubit

* add i18n

* refactor(capture_page): cubit usage adjustments (#52)

* fix tests

* localize chip names

* fix cubit tests

* change row trick into align

* medium typo fix

* removed

* supportedLocales fix

* missing trailing coma

Co-authored-by: Felix Angelov <[email protected]>
Jan-Stepien pushed a commit that referenced this pull request Feb 18, 2022
* Add animations to capture view

* button styling changes

* fix unit tests

* split apptheme to seperate file

* implicit scaffold's background theme

* use project barrel file

* barrel coverage fix

* feat: responsive capture page

* responsiveness test

* code review fixes

* implement PR's comments

* theme fix

* top level theme

* max score in cubit state

* move business logic to cubit

* add i18n

* refactor(capture_page): cubit usage adjustments (#52)

* fix tests

* localize chip names

* fix cubit tests

* change row trick into align

* fix tests

* medium typo fix

* removed

* supportedLocales fix

* missing trailing coma

* empty line

* supress gen files

Co-authored-by: Felix Angelov <[email protected]>
Jan-Stepien pushed a commit that referenced this pull request Feb 21, 2022
* Add animations to capture view

* button styling changes

* fix unit tests

* split apptheme to seperate file

* implicit scaffold's background theme

* use project barrel file

* barrel coverage fix

* feat: responsive capture page

* responsiveness test

* feat: implement thank you screen

* code review fixes

* use FlutterGen for accessing assets

* pull request review fixes

* implement PR's comments

* theme fix

* top level theme

* max score in cubit state

* move business logic to cubit

* add i18n

* refactor(capture_page): cubit usage adjustments (#52)

* fix tests

* localize chip names

* fix cubit tests

* change row trick into align

* fix tests

* organize imports

* medium typo fix

* removed

* supportedLocales fix

* missing trailing coma

* capture end page test

* exclude assets from flutter gen

* ignore gen file

* full path

Co-authored-by: Felix Angelov <[email protected]>
Jan-Stepien pushed a commit that referenced this pull request Mar 14, 2022
* Add animations to capture view

* button styling changes

* fix unit tests

* split apptheme to seperate file

* implicit scaffold's background theme

* use project barrel file

* barrel coverage fix

* feat: responsive capture page

* responsiveness test

* feat: implement thank you screen

* feat: capture navigation with transition animation

* code review fixes

* use FlutterGen for accessing assets

* pull request review fixes

* capture navigation fix

* implement PR's comments

* theme fix

* top level theme

* max score in cubit state

* move business logic to cubit

* add i18n

* refactor(capture_page): cubit usage adjustments (#52)

* fix tests

* localize chip names

* fix cubit tests

* change row trick into align

* fix tests

* organize imports

* medium typo fix

* removed

* supportedLocales fix

* missing trailing coma

* unused import

* capture end page test

* exclude assets from flutter gen

* ignore gen file

* full path

* cleanup

* PR comments resolving

Co-authored-by: Felix Angelov <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants