Skip to content

Commit

Permalink
Add iconBuilder field for SidebarXItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Frezyx committed Apr 8, 2024
1 parent c7e4938 commit e250b7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lib/src/models/sidebarx_item.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'package:flutter/cupertino.dart';

typedef SidebarXItemBuilder = Widget Function(
bool selected,
bool hidden,
);

class SidebarXItem {
const SidebarXItem({
this.label,
Expand All @@ -9,6 +14,7 @@ class SidebarXItem {
this.onLongPress,
this.onSecondaryTap,
this.selectable = true,
this.iconBuilder,
}) : assert(
(icon != null || iconWidget != null) &&
(icon == null || iconWidget == null),
Expand All @@ -17,9 +23,13 @@ class SidebarXItem {

final String? label;
final IconData? icon;
@Deprecated('Use iconBuilder instead')
final Widget? iconWidget;
final bool selectable;
final Function()? onTap;
final Function()? onLongPress;
final Function()? onSecondaryTap;

/// The `itemBuilder` callback used for setup custom icon for [SidebarXItem]
final SidebarXItemBuilder? iconBuilder;
}
4 changes: 2 additions & 2 deletions lib/src/sidebarx_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ class SidebarX extends StatefulWidget {
/// Togglin animation duration
final Duration animationDuration;

///Collapse Icon
/// Collapse Icon
final IconData collapseIcon;

///Extend Icon
/// Extend Icon
final IconData extendIcon;

@override
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/sidebarx_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ class _SidebarXCellState extends State<SidebarXCell> {
return Spacer(flex: value);
},
),
if (widget.item.icon != null)
if (widget.item.iconBuilder != null)
widget.item.iconBuilder!.call(widget.selected, _hovered)
else if (widget.item.icon != null)
_Icon(item: widget.item, iconTheme: iconTheme)
// ignore: deprecated_member_use_from_same_package
else if (widget.item.iconWidget != null)
// ignore: deprecated_member_use_from_same_package
widget.item.iconWidget!,
Flexible(
flex: 6,
Expand Down

0 comments on commit e250b7d

Please sign in to comment.