Skip to content

Commit

Permalink
fix: ImpaktfullUiSidebarNavigationItem now correctly handles the sele…
Browse files Browse the repository at this point in the history
…cted state
  • Loading branch information
vanlooverenkoen committed Jan 21, 2025
1 parent bdbf766 commit ac30c54
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2025-01-21 13:31:41.670557","version":"3.24.4","swift_package_manager_enabled":false}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2025-01-21 14:30:40.343622","version":"3.24.4","swift_package_manager_enabled":false}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.34.1

## Fix

- ImpaktfullUiSidebarNavigationItem now correctly handles the selected state

# 0.34.0

## Feat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export 'sidebar_navigation_item_style.dart';

part 'sidebar_navigation_item.describe.dart';

class ImpaktfullUiSidebarNavigationItem extends StatefulWidget
with ComponentDescriptorMixin {
class ImpaktfullUiSidebarNavigationItem extends StatefulWidget with ComponentDescriptorMixin {
final ImpaktfullUiAsset? leading;
final String title;
final List<Widget> items;
Expand All @@ -33,15 +32,13 @@ class ImpaktfullUiSidebarNavigationItem extends StatefulWidget
});

@override
State<ImpaktfullUiSidebarNavigationItem> createState() =>
_ImpaktfullUiSidebarNavigationItemState();
State<ImpaktfullUiSidebarNavigationItem> createState() => _ImpaktfullUiSidebarNavigationItemState();

@override
String describe(BuildContext context) => _describeInstance(context, this);
}

class _ImpaktfullUiSidebarNavigationItemState
extends State<ImpaktfullUiSidebarNavigationItem>
class _ImpaktfullUiSidebarNavigationItemState extends State<ImpaktfullUiSidebarNavigationItem>
with SingleTickerProviderStateMixin {
var _expanded = false;
late AnimationController _controller;
Expand All @@ -50,8 +47,7 @@ class _ImpaktfullUiSidebarNavigationItemState
@override
void initState() {
super.initState();
_expanded = widget.items.any(
(item) => item is ImpaktfullUiSidebarNavigationItem && item.isSelected);
_expanded = _hasSelectedSubItem(widget.items);
_controller = AnimationController(
duration: const Duration(milliseconds: 200),
vsync: this,
Expand All @@ -65,6 +61,18 @@ class _ImpaktfullUiSidebarNavigationItemState
}
}

bool _hasSelectedSubItem(List<Widget> items) => items.any(
(item) {
if (item is! ImpaktfullUiSidebarNavigationItem) {
return false;
}
if (item.items.isNotEmpty) {
return _hasSelectedSubItem(item.items);
}
return item.isSelected;
},
);

@override
void dispose() {
_controller.dispose();
Expand All @@ -73,8 +81,7 @@ class _ImpaktfullUiSidebarNavigationItemState

@override
Widget build(BuildContext context) {
return ImpaktfullUiComponentThemeBuilder<
ImpaktfullUiSidebarNavigationItemTheme>(
return ImpaktfullUiComponentThemeBuilder<ImpaktfullUiSidebarNavigationItemTheme>(
overrideComponentTheme: widget.theme,
builder: (context, componentTheme) {
return ImpaktfullUiAutoLayout.vertical(
Expand All @@ -84,13 +91,11 @@ class _ImpaktfullUiSidebarNavigationItemState
children: [
ImpaktfullUiTouchFeedback(
onTap: _onTap,
color:
widget.isSelected ? componentTheme.colors.background : null,
color: widget.isSelected ? componentTheme.colors.background : null,
borderRadius: componentTheme.dimens.borderRadius,
child: Padding(
padding: widget.items.isEmpty
? componentTheme.dimens.padding
: componentTheme.dimens.paddingWithSubItems,
padding:
widget.items.isEmpty ? componentTheme.dimens.padding : componentTheme.dimens.paddingWithSubItems,
child: ImpaktfullUiAutoLayout.horizontal(
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 12,
Expand Down

0 comments on commit ac30c54

Please sign in to comment.