Conversation
WalkthroughIntroduces a new Badge widget component to the duit UI framework. This includes the BadgeAttributes configuration struct with variant types, color theming, sizing, spacing, and count properties; a Badge element type constant; wrapper methods for theming and reference tracking; and a Badge widget constructor function that creates composite elements with child and label content. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
cmd/gen/embedded_sturct_delegate_gen.gois excluded by!**/gen/**
📒 Files selected for processing (4)
pkg/duit_attributes/badge_attributes.go(1 hunks)pkg/duit_attributes/zz_embedded_structs_delegates.go(1 hunks)pkg/duit_core/element_type.go(1 hunks)pkg/duit_widget/badge.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/duit_widget/badge.go (3)
pkg/duit_core/element_type.go (1)
Badge(93-93)pkg/duit_attributes/badge_attributes.go (1)
BadgeAttributes(17-31)pkg/duit_core/element.go (1)
DuitElementModel(12-39)
pkg/duit_attributes/badge_attributes.go (3)
pkg/duit_attributes/value_reference_holder.go (1)
ValueReferenceHolder(15-17)pkg/duit_attributes/theme.go (1)
ThemeConsumer(12-16)pkg/duit_utils/tristate.go (6)
Tristate(30-30)TBool(32-32)TristateFrom(54-68)Float32Value(118-120)BoolValue(74-76)UintValue(98-100)
pkg/duit_attributes/zz_embedded_structs_delegates.go (3)
pkg/duit_attributes/badge_attributes.go (1)
BadgeAttributes(17-31)pkg/duit_attributes/theme.go (2)
ThemeConsumer(12-16)ThemeOverrideRule(5-5)pkg/duit_attributes/value_reference_holder.go (2)
ValueRef(5-9)ValueReferenceHolder(15-17)
🔇 Additional comments (5)
pkg/duit_core/element_type.go (1)
93-93: LGTM - Badge element type added correctly.The new Badge element type follows the established pattern and naming conventions.
pkg/duit_attributes/zz_embedded_structs_delegates.go (1)
4403-4443: LGTM - Generated wrapper methods are consistent.The wrapper methods for BadgeAttributes follow the established lazy-initialization and delegation pattern used throughout this generated file.
pkg/duit_attributes/badge_attributes.go (2)
10-15: LGTM - Badge variant constants defined correctly.The BadgeVariant type alias and constants (BadgeCommon, BadgeCount) follow Go conventions.
63-125: LGTM - Constructor and setter methods are well-implemented.The fluent API methods follow the established pattern and correctly use utility functions from duit_utils for type conversions.
pkg/duit_widget/badge.go (1)
8-11: No nil checks needed—nil children are expected behavior in this framework.The Badge function correctly follows the established pattern across all multi-child widgets in the codebase. Similar widgets (SliverAppBar, AppBar, FlexibleSpaceBar, SliverVisibility) all pass nullable parameters directly to the children array without filtering. As documented in the codebase's design, the client/renderer is responsible for handling nil values appropriately, so defensive nil checks would be inconsistent with framework conventions.
| func (r *BadgeAttributes) Validate() error { | ||
| if err := r.ThemeConsumer.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := r.ValueReferenceHolder.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := r.AnimatedPropertyOwner.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if r.Padding != nil { | ||
| if err := r.Padding.Validate(); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if r.Variant != nil { | ||
| if *r.Variant == BadgeCount && r.Count == nil { | ||
| return errors.New("count property can`t be ") | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } |
There was a problem hiding this comment.
Fix incomplete error message and add nil checks.
Two issues identified:
-
Line 55: The error message is incomplete:
"count property cant be "` - missing the rest of the message. Also uses a backtick instead of an apostrophe in "can't". -
Lines 35-45: Potential nil pointer dereference. The embedded pointers (ThemeConsumer, ValueReferenceHolder, AnimatedPropertyOwner) may be nil, and calling
Validate()on them will panic. Add nil checks before validation.
Apply this diff to fix both issues:
func (r *BadgeAttributes) Validate() error {
- if err := r.ThemeConsumer.Validate(); err != nil {
- return err
+ if r.ThemeConsumer != nil {
+ if err := r.ThemeConsumer.Validate(); err != nil {
+ return err
+ }
}
- if err := r.ValueReferenceHolder.Validate(); err != nil {
- return err
+ if r.ValueReferenceHolder != nil {
+ if err := r.ValueReferenceHolder.Validate(); err != nil {
+ return err
+ }
}
- if err := r.AnimatedPropertyOwner.Validate(); err != nil {
- return err
+ if r.AnimatedPropertyOwner != nil {
+ if err := r.AnimatedPropertyOwner.Validate(); err != nil {
+ return err
+ }
}
if r.Padding != nil {
@@ -52,7 +58,7 @@
if r.Variant != nil {
if *r.Variant == BadgeCount && r.Count == nil {
- return errors.New("count property can`t be ")
+ return errors.New("count property cannot be nil when variant is BadgeCount")
}
}🤖 Prompt for AI Agents
In pkg/duit_attributes/badge_attributes.go around lines 34 to 60, the Validate
method currently calls Validate() on embedded fields without nil checks and
returns an incomplete error string for the count check; add nil checks before
calling ThemeConsumer.Validate(), ValueReferenceHolder.Validate(), and
AnimatedPropertyOwner.Validate() (only call Validate if the receiver pointer is
non-nil) and update the count error to a complete, clear message using an
apostrophe (e.g. "count property can't be nil when variant is BadgeCount").
Summary by CodeRabbit
Release Notes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.