[go: up one dir, main page]

Skip to content

Commit

Permalink
Implement hoverColor
Browse files Browse the repository at this point in the history
  • Loading branch information
Frezyx committed Aug 3, 2022
1 parent c1591b0 commit ee715cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ExampleSidebarX extends StatelessWidget {
color: canvasColor,
borderRadius: BorderRadius.circular(20),
),
hoverColor: Colors.white.withOpacity(0.5),
textStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
selectedTextStyle: const TextStyle(color: Colors.white),
itemTextPadding: const EdgeInsets.only(left: 30),
Expand Down
9 changes: 9 additions & 0 deletions lib/src/theme/sidebarx_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SidebarXTheme {
this.selectedItemPadding,
this.itemTextPadding,
this.selectedItemTextPadding,
this.hoverColor,
});

/// [SidebarX] width
Expand Down Expand Up @@ -72,6 +73,10 @@ class SidebarXTheme {
/// Selected item [SidebarXItem] text padding
final EdgeInsets? selectedItemTextPadding;

/// Background color of [SidebarXItem] when the mouse
/// cursor hover over an item
final Color? hoverColor;

/// Method to get default flutter theme settings
SidebarXTheme mergeFlutterTheme(BuildContext context) {
final theme = Theme.of(context);
Expand All @@ -95,6 +100,7 @@ class SidebarXTheme {
selectedItemPadding: selectedItemPadding,
itemTextPadding: itemTextPadding,
selectedItemTextPadding: selectedItemTextPadding,
hoverColor: theme.hoverColor,
);
return mergedTheme;
}
Expand Down Expand Up @@ -123,6 +129,7 @@ class SidebarXTheme {
itemDecoration: itemDecoration ?? theme.itemDecoration,
selectedItemDecoration:
selectedItemDecoration ?? theme.selectedItemDecoration,
hoverColor: hoverColor ?? theme.hoverColor,
);
}

Expand All @@ -145,6 +152,7 @@ class SidebarXTheme {
EdgeInsets? selectedItemPadding,
EdgeInsets? itemTextPadding,
EdgeInsets? selectedItemTextPadding,
Color? hoverColor,
}) {
return SidebarXTheme(
width: width ?? this.width,
Expand All @@ -166,6 +174,7 @@ class SidebarXTheme {
itemTextPadding: itemTextPadding ?? this.itemTextPadding,
selectedItemTextPadding:
selectedItemTextPadding ?? this.selectedItemTextPadding,
hoverColor: hoverColor ?? this.hoverColor,
);
}
}
17 changes: 14 additions & 3 deletions lib/src/widgets/sidebarx_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SidebarXCell extends StatefulWidget {

class _SidebarXCellState extends State<SidebarXCell> {
late Animation<double> _animation;
var _hovered = false;

@override
void initState() {
Expand Down Expand Up @@ -52,12 +53,14 @@ class _SidebarXCellState extends State<SidebarXCell> {
widget.selected ? theme.selectedItemTextPadding : theme.itemTextPadding;

return MouseRegion(
onEnter: (e) => debugPrint(e.toString()),
onExit: (e) => debugPrint(e.toString()),
onEnter: (_) => _onEnteredCellZone(),
onExit: (_) => _onExitCellZone(),
child: GestureDetector(
onTap: widget.onTap,
child: Container(
decoration: decoration,
decoration: decoration?.copyWith(
color: _hovered ? theme.hoverColor : null,
),
padding: padding ?? const EdgeInsets.all(8),
margin: margin ?? const EdgeInsets.all(4),
child: Row(
Expand Down Expand Up @@ -100,6 +103,14 @@ class _SidebarXCellState extends State<SidebarXCell> {
),
);
}

void _onEnteredCellZone() {
setState(() => _hovered = true);
}

void _onExitCellZone() {
setState(() => _hovered = false);
}
}

class _Icon extends StatelessWidget {
Expand Down

0 comments on commit ee715cc

Please sign in to comment.