Skip to content

Commit

Permalink
Merge pull request #107 from JaseElder/master
Browse files Browse the repository at this point in the history
Added configurable border width and disable flag for the shadow on tapping (helpful if you want a flat button and the elevation is 0)
  • Loading branch information
Frezyx authored Sep 19, 2024
2 parents fcb68fa + e0aa35b commit 06a5741
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 2 additions & 0 deletions lib/src/group_button_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ class GroupButton<T> extends StatelessWidget {
selectedBorderColor: options.selectedBorderColor,
unselectedBorderColor: options.unselectedBorderColor,
borderRadius: options.borderRadius,
borderWidth: options.borderWidth,
selectedShadow: options.selectedShadow,
unselectedShadow: options.unselectedShadow,
tappingShadowColor: options.tappingShadowColor,
buttonWidth: options.buttonWidth,
buttonHeight: options.buttonHeight,
mainGroupAlignment: options.mainGroupAlignment,
Expand Down
6 changes: 6 additions & 0 deletions lib/src/group_button_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class GroupButtonBody<T> extends StatefulWidget {
this.selectedColor,
this.unselectedColor,
this.borderRadius = BorderRadius.zero,
this.borderWidth,
this.selectedShadow = const [],
this.unselectedShadow = const [],
this.tappingShadowColor,
this.buttonWidth,
this.buttonHeight,
this.mainGroupAlignment = MainGroupAlignment.center,
Expand Down Expand Up @@ -59,8 +61,10 @@ class GroupButtonBody<T> extends StatefulWidget {
final Color? selectedBorderColor;
final Color? unselectedBorderColor;
final BorderRadius? borderRadius;
final double? borderWidth;
final List<BoxShadow> selectedShadow;
final List<BoxShadow> unselectedShadow;
final Color? tappingShadowColor;
final double? buttonWidth;
final double? buttonHeight;
final GroupingType? groupingType;
Expand Down Expand Up @@ -186,8 +190,10 @@ class _GroupButtonBodyState<T> extends State<GroupButtonBody<T>> {
selectedBorderColor: widget.selectedBorderColor,
unselectedBorderColor: widget.unselectedBorderColor,
borderRadius: widget.borderRadius,
borderWidth: widget.borderWidth,
selectedShadow: widget.selectedShadow,
unselectedShadow: widget.unselectedShadow,
tappingShadowColor: widget.tappingShadowColor,
height: widget.buttonHeight,
width: widget.buttonWidth,
textAlign: widget.textAlign,
Expand Down
9 changes: 8 additions & 1 deletion lib/src/group_button_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class GroupButtonItem extends StatelessWidget {
this.selectedColor,
this.unselectedColor,
this.borderRadius,
this.borderWidth,
this.selectedShadow,
this.unselectedShadow,
this.tappingShadowColor,
this.height,
this.width,
this.textAlign,
Expand All @@ -35,8 +37,10 @@ class GroupButtonItem extends StatelessWidget {
final Color? selectedBorderColor;
final Color? unselectedBorderColor;
final BorderRadius? borderRadius;
final double? borderWidth;
final List<BoxShadow>? selectedShadow;
final List<BoxShadow>? unselectedShadow;
final Color? tappingShadowColor;
final double? height;
final double? width;
final TextAlign? textAlign;
Expand Down Expand Up @@ -64,6 +68,8 @@ class GroupButtonItem extends StatelessWidget {
? unselectedBorderColor
: null;

double get _borderWidth => borderWidth ?? 1.0;

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -87,6 +93,7 @@ class GroupButtonItem extends StatelessWidget {
return ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
shadowColor: tappingShadowColor ?? _getBackgroundColor(theme),
elevation: elevation ?? 0.0,
backgroundColor: _getBackgroundColor(theme),
shape: _buildShape(),
Expand Down Expand Up @@ -136,7 +143,7 @@ class GroupButtonItem extends StatelessWidget {

BorderSide buildBorderSide(Color? color) {
if (color != null) {
return BorderSide(color: color);
return BorderSide(color: color, width: _borderWidth);
}
return BorderSide.none;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/src/options/group_button_options.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

import 'package:group_button/group_button.dart';
import 'package:group_button/src/options/defaults.dart';

Expand All @@ -17,8 +16,10 @@ class GroupButtonOptions {
this.selectedBorderColor,
this.unselectedBorderColor,
this.borderRadius,
this.borderWidth,
this.selectedShadow = defaultShadow,
this.unselectedShadow = defaultShadow,
this.tappingShadowColor,
this.buttonHeight,
this.buttonWidth,
this.mainGroupAlignment = MainGroupAlignment.center,
Expand Down Expand Up @@ -74,12 +75,18 @@ class GroupButtonOptions {
/// How much the button will be rounded
final BorderRadius? borderRadius;

/// The width of the button's border
final double? borderWidth;

/// list of selected button(s) [BoxShadow]
final List<BoxShadow> selectedShadow;

/// list of unselected buttons [BoxShadow]
final List<BoxShadow> unselectedShadow;

/// shadow [Color] shown when performing an onTap()
final Color? tappingShadowColor;

/// Height of Group button
final double? buttonHeight;

Expand Down

0 comments on commit 06a5741

Please sign in to comment.