Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added showSelectionShape and cursor, as options to set the Bottom Navy Bar #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class _MyHomePageState extends State<MyHomePage> {
itemCornerRadius: 24,
curve: Curves.easeIn,
onItemSelected: (index) => setState(() => _currentIndex = index),
// showSelectionShape: true,
// cursor: MaterialStateMouseCursor.clickable,
items: <BottomNavyBarItem>[
BottomNavyBarItem(
icon: Icon(Icons.apps),
Expand Down
48 changes: 33 additions & 15 deletions lib/bottom_navy_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/widgets.dart';
/// Update [selectedIndex] to change the selected item.
/// [selectedIndex] is required and must not be null.
class BottomNavyBar extends StatelessWidget {

BottomNavyBar({
Key? key,
this.selectedIndex = 0,
Expand All @@ -22,8 +23,10 @@ class BottomNavyBar extends StatelessWidget {
required this.items,
required this.onItemSelected,
this.curve = Curves.linear,
}) : assert(items.length >= 2 && items.length <= 5),
super(key: key);
this.showSelectionShape = true,
this.cursor = MaterialStateMouseCursor.clickable,
}) : assert(items.length >= 2 && items.length <= 5),
super(key: key);

/// The selected item is index. Changing this property will change and animate
/// the item being selected. Defaults to zero.
Expand Down Expand Up @@ -62,6 +65,14 @@ class BottomNavyBar extends StatelessWidget {
/// Used to configure the animation curve. Defaults to [Curves.linear].
final Curve curve;

/// Define if [selected item] has a color shape.
/// Defaults to [true].
final bool showSelectionShape;

/// Define the cursor for the hover items.
/// Defaults to [MaterialStateMouseCursor.clickable]
final MaterialStateMouseCursor cursor;

@override
Widget build(BuildContext context) {
final bgColor = backgroundColor ?? Theme.of(context).bottomAppBarColor;
Expand All @@ -86,16 +97,20 @@ class BottomNavyBar extends StatelessWidget {
mainAxisAlignment: mainAxisAlignment,
children: items.map((item) {
var index = items.indexOf(item);
return GestureDetector(
onTap: () => onItemSelected(index),
child: _ItemWidget(
item: item,
iconSize: iconSize,
isSelected: index == selectedIndex,
backgroundColor: bgColor,
itemCornerRadius: itemCornerRadius,
animationDuration: animationDuration,
curve: curve,
return MouseRegion(
cursor: cursor,
child: GestureDetector(
onTap: () => onItemSelected(index),
child: _ItemWidget(
item: item,
iconSize: iconSize,
isSelected: index == selectedIndex,
backgroundColor: bgColor,
itemCornerRadius: itemCornerRadius,
animationDuration: animationDuration,
showSelectionShape: showSelectionShape,
curve: curve,
),
),
);
}).toList(),
Expand All @@ -114,6 +129,7 @@ class _ItemWidget extends StatelessWidget {
final double itemCornerRadius;
final Duration animationDuration;
final Curve curve;
final bool showSelectionShape;

const _ItemWidget({
Key? key,
Expand All @@ -124,7 +140,8 @@ class _ItemWidget extends StatelessWidget {
required this.itemCornerRadius,
required this.iconSize,
this.curve = Curves.linear,
}) : super(key: key);
this.showSelectionShape = true
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -138,7 +155,8 @@ class _ItemWidget extends StatelessWidget {
curve: curve,
decoration: BoxDecoration(
color:
isSelected ? item.activeColor.withOpacity(0.2) : backgroundColor,
isSelected && showSelectionShape?
item.activeColor.withOpacity(0.2) : backgroundColor,
borderRadius: BorderRadius.circular(itemCornerRadius),
),
child: SingleChildScrollView(
Expand Down Expand Up @@ -214,4 +232,4 @@ class BottomNavyBarItem {
///
/// This will take effect only if [title] it a [Text] widget.
final TextAlign? textAlign;
}
}