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

Customize the selected Gbutton size, solves issue #93 #106

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ GNav(
iconSize: 24, // tab button icon size
tabBackgroundColor: Colors.purple.withOpacity(0.1), // selected tab background color
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 5), // navigation bar padding
selectedGbuttonSize: Size(500, 50), // Customize the size of the selected GButton
tabs: [
GButton(
icon: LineIcons.home,
Expand Down
75 changes: 41 additions & 34 deletions lib/src/gbutton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class GButton extends StatefulWidget {
final String? semanticLabel;
final GnavStyle? style;
final double? textSize;
final Size? size;


const GButton({
Key? key,
Expand Down Expand Up @@ -64,6 +66,7 @@ class GButton extends StatefulWidget {
this.semanticLabel,
this.style = GnavStyle.google,
this.textSize,
this.size
}) : super(key: key);

@override
Expand All @@ -75,40 +78,44 @@ class _GButtonState extends State<GButton> {
Widget build(BuildContext context) {
return Semantics(
label: widget.semanticLabel ?? widget.text,
child: Button(
textSize: widget.textSize,
style: widget.style,
borderRadius: widget.borderRadius,
border: widget.border,
activeBorder: widget.activeBorder,
shadow: widget.shadow,
debug: widget.debug,
duration: widget.duration,
iconSize: widget.iconSize,
active: widget.active,
onPressed: () {
if (widget.haptic!) HapticFeedback.selectionClick();
widget.onPressed?.call();
},
padding: widget.padding,
margin: widget.margin,
gap: widget.gap,
color: widget.backgroundColor,
rippleColor: widget.rippleColor,
hoverColor: widget.hoverColor,
gradient: widget.backgroundGradient,
curve: widget.curve,
leading: widget.leading,
iconActiveColor: widget.iconActiveColor,
iconColor: widget.iconColor,
icon: widget.icon,
text: Text(
widget.text,
style: widget.textStyle ??
TextStyle(
fontWeight: FontWeight.w600,
color: widget.textColor,
),
child: SizedBox(
width: widget.size != null ? widget.size!.width : null,
height: widget.size != null ? widget.size!.height : null,
child: Button(
textSize: widget.textSize,
style: widget.style,
borderRadius: widget.borderRadius,
border: widget.border,
activeBorder: widget.activeBorder,
shadow: widget.shadow,
debug: widget.debug,
duration: widget.duration,
iconSize: widget.iconSize,
active: widget.active,
onPressed: () {
if (widget.haptic!) HapticFeedback.selectionClick();
widget.onPressed?.call();
},
padding: widget.padding,
margin: widget.margin,
gap: widget.gap,
color: widget.backgroundColor,
rippleColor: widget.rippleColor,
hoverColor: widget.hoverColor,
gradient: widget.backgroundGradient,
curve: widget.curve,
leading: widget.leading,
iconActiveColor: widget.iconActiveColor,
iconColor: widget.iconColor,
icon: widget.icon,
text: Text(
widget.text,
style: widget.textStyle ??
TextStyle(
fontWeight: FontWeight.w600,
color: widget.textColor,
),
),
),
),
);
Expand Down
11 changes: 7 additions & 4 deletions lib/src/gnav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GNav extends StatefulWidget {
this.mainAxisAlignment = MainAxisAlignment.spaceBetween,
this.style = GnavStyle.google,
this.textSize,
this.selectedGbuttonSize
}) : super(key: key);

final List<GButton> tabs;
Expand Down Expand Up @@ -64,6 +65,7 @@ class GNav extends StatefulWidget {
final MainAxisAlignment mainAxisAlignment;
final GnavStyle? style;
final double? textSize;
final Size? selectedGbuttonSize;

@override
_GNavState createState() => _GNavState();
Expand Down Expand Up @@ -94,7 +96,7 @@ class _GNavState extends State<GNav> {
child: Row(
mainAxisAlignment: widget.mainAxisAlignment,
children: widget.tabs
.map((t) => GButton(
.map((t) => GButton(
textSize: widget.textSize,
style: widget.style,
key: t.key,
Expand Down Expand Up @@ -127,17 +129,18 @@ class _GNavState extends State<GNav> {
backgroundColor:
t.backgroundColor ?? widget.tabBackgroundColor,
duration: widget.duration,
size: selectedIndex == widget.tabs.indexOf(t) ? widget.selectedGbuttonSize : null ,
onPressed: () {
if (!clickable) return;
setState(() {
selectedIndex = widget.tabs.indexOf(t);
clickable = false;
});

t.onPressed?.call();

widget.onTabChange?.call(selectedIndex);

Future.delayed(widget.duration, () {
if (context.mounted) {
setState(() {
Expand Down