Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.3

Add additional property to the package:

- **borderRadius**: an optional border radius for the button corners

## 0.0.2

Updated GitHub media images.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ PushableButton(
blurRadius: 7,
offset: Offset(0, 2),
),
borderRadius: 16,
onPressed: () => print('Button Pressed!'),
)
```
Expand All @@ -34,6 +35,7 @@ PushableButton(
- **elevation**: elevation or "gap" between the top and bottom layer
- **hslColor**: color of the top layer. `HSLColor` is used instead of `Color` so that the bottom layer is automatically calculated by reducing the luminosity
- **shadow**: an optional shadow to make the button look better
- **borderRadius**: an optional border radius for the button corners
- **onPressed**: button callback

### [LICENSE: MIT](LICENSE)
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _MyHomePageState extends State<MyHomePage> {
elevation: 8,
hslColor: HSLColor.fromAHSL(1.0, 356, 1.0, 0.43),
shadow: shadow,
borderRadius: 4,
onPressed: () => setState(() => _selection = '1'),
),
SizedBox(height: 32),
Expand All @@ -59,6 +60,7 @@ class _MyHomePageState extends State<MyHomePage> {
elevation: 8,
hslColor: HSLColor.fromAHSL(1.0, 120, 1.0, 0.37),
shadow: shadow,
borderRadius: 16,
onPressed: () => setState(() => _selection = '2'),
),
SizedBox(height: 32),
Expand Down
24 changes: 18 additions & 6 deletions lib/pushable_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PushableButton extends StatefulWidget {
required this.height,
this.elevation = 8.0,
this.shadow,
this.borderRadius,
this.onPressed,
}) : assert(height > 0),
super(key: key);
Expand All @@ -34,6 +35,10 @@ class PushableButton extends StatefulWidget {
/// This is added to the bottom layer only
final BoxShadow? shadow;

/// An optional border radius of the button corners
/// If no border radius is provided, the button will use [StadiumBorder]
final double? borderRadius;

/// button pressed callback
final VoidCallback? onPressed;

Expand Down Expand Up @@ -137,8 +142,9 @@ class _PushableButtonState extends AnimationControllerState<PushableButton> {
color: bottomHslColor.toColor(),
boxShadow:
widget.shadow != null ? [widget.shadow!] : [],
borderRadius:
BorderRadius.circular(widget.height / 2),
borderRadius: widget.borderRadius != null
? BorderRadius.circular(widget.borderRadius!)
: BorderRadius.circular(widget.height / 2),
),
),
),
Expand All @@ -149,10 +155,16 @@ class _PushableButtonState extends AnimationControllerState<PushableButton> {
top: top,
child: Container(
height: widget.height,
decoration: ShapeDecoration(
color: hslColor.toColor(),
shape: StadiumBorder(),
),
decoration: widget.borderRadius != null
? BoxDecoration(
color: hslColor.toColor(),
borderRadius:
BorderRadius.circular(widget.borderRadius!),
)
: ShapeDecoration(
color: hslColor.toColor(),
shape: StadiumBorder(),
),
child: Center(child: widget.child),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pushable_button
description: A 3D pushable button. Ideal for important CTAs in the app.
version: 0.0.2
version: 0.0.3
homepage: https://codewithandrea.com/
repository: https://github.com/bizz84/pushable_button

Expand Down