Skip to content

Replace private helper methods with private widgets#120

Closed
edgarfroes wants to merge 1 commit intoyako-dev:masterfrom
edgarfroes:master
Closed

Replace private helper methods with private widgets#120
edgarfroes wants to merge 1 commit intoyako-dev:masterfrom
edgarfroes:master

Conversation

@edgarfroes
Copy link
Copy Markdown

Connection with issue(s)

This PR will resolve a performance problem that has no open issue.

There are private methods that return Widgets instead of Widgets themselves, which makes it impossible for Flutter to identify their address in the build context, thus rebuilding all the widgets inside those methods instead of pointing to the already built widget in the memory and Widget tree.

This PR will FIX this by moving this code to private widgets, while also creating a parent-building structure that will rebuild children widgets only when necessary.

Testing and Review Notes

No tests other than normal smoke tests are required, as this PR changes only issues related to performance.

Sources:
Writing Better Flutter Widgets: How to Choose Between Classes and Functions
Widgets versus helper methods | Decoding Flutter

Screenshots or Videos

Simulator.Screen.Recording.-.iPhone.1.-.2023-09-19.at.17.33.24.mp4

To Do

  • double check the original issue to confirm it is fully satisfied
  • add testing notes and screenshots in PR description to help guide reviewers
  • request the "UX" team perform a design review (if/when applicable)

@edgarfroes
Copy link
Copy Markdown
Author

@yako-dev any feedback?

@yadaniyil yadaniyil added the enhancement New feature or request label Dec 1, 2023
yadaniyil added a commit that referenced this pull request Apr 10, 2026
Bug fixes:
- #114: showBadge ignored when loop animation active (didUpdateWidget restructured)
- #130: showBadge slow to hide with animation (stop() before reverse())
- #98: border anti-aliasing artifact (border moved into BoxDecoration strokeAlignInside)
- #115: animation not re-triggered for custom content (key-based detection)

New API:
- BadgeStyle.copyWith() covering all 8 fields
- BadgePosition.centerStart() and .centerEnd() named constructors
- BadgeState.animationController and .appearanceController public getters

Code quality:
- _BadgeVisual extracted as StatelessWidget (PR #120, reduces rebuilds)
- ConstrainedBox + IntrinsicWidth for proportional small badges (PR #111)
- BadgeGradient.gradient() asserts document constructor invariants
- Example app: 16 lint warnings resolved, pedantic replaced with flutter_lints
- README: corrected GIF height, added hide Badge import option

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
yadaniyil added a commit that referenced this pull request Apr 10, 2026
* test: rewrite and expand test suite

- Rewrite content_change tests: replace illegal state.didUpdateWidget()
  calls with proper TestWidgetScreen+setState so the framework drives
  the lifecycle naturally
- Fix duplicate test name in show_hide tests (shadowed the second case)
- Remove unnecessary async from all synchronous unit tests
- Add 15 new test cases: standalone badge rendering/onTap/ignorePointer,
  showBadge:false initial state, BadgePosition factory defaults, Icon
  content change animation, non-Text/Icon limitation documentation, and
  issue #114 regression (skip:true — confirms early-return bug in
  didUpdateWidget loop branch)
- Note in PLAN.md: always use GestureDetector (not ElevatedButton) when
  triggering setState in animation tests to avoid ripple pollution

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: upgrade flutter_lints to ^6.0.0, fix resulting lint warnings

- Bump flutter_lints ^2.0.1 → ^6.0.0 in main package
- Update flutter SDK lower bound from ">=0.2.5" → ">=3.10.0" to match
  the Dart >=3.0.0 constraint (Dart 3.0 shipped with Flutter 3.10)
- Example app: replace discontinued pedantic ^1.11.1 with flutter_lints
  ^6.0.0, remove unused integration_test dep, bump cupertino_icons to
  ^1.0.8, add flutter SDK lower bound
- Fix 3 use_super_parameters lint warnings in Badge, BadgePositioned,
  and TestWidgetScreen constructors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs: mark Phase 1 complete in PLAN.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: v3.2.0 — bug fixes, new API, and code quality improvements

Bug fixes:
- #114: showBadge ignored when loop animation active (didUpdateWidget restructured)
- #130: showBadge slow to hide with animation (stop() before reverse())
- #98: border anti-aliasing artifact (border moved into BoxDecoration strokeAlignInside)
- #115: animation not re-triggered for custom content (key-based detection)

New API:
- BadgeStyle.copyWith() covering all 8 fields
- BadgePosition.centerStart() and .centerEnd() named constructors
- BadgeState.animationController and .appearanceController public getters

Code quality:
- _BadgeVisual extracted as StatelessWidget (PR #120, reduces rebuilds)
- ConstrainedBox + IntrinsicWidth for proportional small badges (PR #111)
- BadgeGradient.gradient() asserts document constructor invariants
- Example app: 16 lint warnings resolved, pedantic replaced with flutter_lints
- README: corrected GIF height, added hide Badge import option

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ci: add GitHub Actions for CI and pub.dev publishing

- ci.yml: runs on every PR and push to master (analyze, format check, tests)
- publish.yml: publishes to pub.dev on v* tag push using OIDC (no stored secrets)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@yadaniyil
Copy link
Copy Markdown
Collaborator

Great idea — implemented in v3.2.0. The badgeView() closure has been replaced with a proper _BadgeVisual StatelessWidget, allowing Flutter's element tree to cache it across _appearanceController ticks.

@yadaniyil yadaniyil closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants