Torikul Islam Topu d2534e118d
feat: Add maxCount parameter to Badge.count constructor. (#171054)
feat: Add `maxCount` parameter to `Badge.count` constructor

This enhancement provides the ability to specify a **dynamic maximum
limit** for the badge count, offering greater flexibility and
eliminating the reliance on hardcoded values within the widget. This
allows developers to, for example, display "99+" instead of "100" or
"9+" instead of "10", improving UI consistency and preventing overly
large numbers on badges.

---

## Description of Changes

This PR introduces a new optional parameter, `maxCount`, to the
`Badge.count` constructor. This provides a flexible way to define a
numerical upper bound for the badge display.

Key aspects of this change:
* **Dynamic Limits:** Developers can now set custom maximum values
(e.g., 9, 99, 999) that, when exceeded, will display the `maxCount`
value followed by a `+` symbol (e.g., "9+", "99+").
* **Improved UI/UX:** Prevents large, potentially overflowing numbers
from appearing on badges, maintaining visual integrity and a cleaner
user interface.
* **Reduced Hardcoding:** Centralizes the logic for maximum badge values
within the `Badge` widget itself, reducing the need for manual checks
and conditional rendering outside the widget.
* **Comprehensive Documentation:** Includes updated API documentation
for the `maxCount` parameter, clarifying its usage, behavior, and the
visual outcome when the maximum is reached.

This change aligns with Flutter's principles of providing highly
customizable and intuitive widgets.

---

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported. (Assuming no breaking changes)
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-07-17 20:01:22 +00:00
..