From d90e3ce66e3cf1966cc1d60cb84318f474b389e6 Mon Sep 17 00:00:00 2001 From: stephenrichter Date: Thu, 13 Apr 2023 14:11:21 -0700 Subject: [PATCH 1/2] [#1] Add optional border radius to button --- example/lib/main.dart | 2 ++ lib/pushable_button.dart | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index a4dbfee..f393fe5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -50,6 +50,7 @@ class _MyHomePageState extends State { elevation: 8, hslColor: HSLColor.fromAHSL(1.0, 356, 1.0, 0.43), shadow: shadow, + borderRadius: 4, onPressed: () => setState(() => _selection = '1'), ), SizedBox(height: 32), @@ -59,6 +60,7 @@ class _MyHomePageState extends State { elevation: 8, hslColor: HSLColor.fromAHSL(1.0, 120, 1.0, 0.37), shadow: shadow, + borderRadius: 16, onPressed: () => setState(() => _selection = '2'), ), SizedBox(height: 32), diff --git a/lib/pushable_button.dart b/lib/pushable_button.dart index 09dd8c6..4c0f9b6 100644 --- a/lib/pushable_button.dart +++ b/lib/pushable_button.dart @@ -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); @@ -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; @@ -137,8 +142,9 @@ class _PushableButtonState extends AnimationControllerState { 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), ), ), ), @@ -149,10 +155,16 @@ class _PushableButtonState extends AnimationControllerState { 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), ), ), From 1e300afb4f788e2c3cfc046f3e235bfffb5a4a39 Mon Sep 17 00:00:00 2001 From: stephenrichter Date: Thu, 13 Apr 2023 14:17:21 -0700 Subject: [PATCH 2/2] [#1] Update README to document border radius property --- CHANGELOG.md | 6 ++++++ README.md | 2 ++ pubspec.yaml | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e78eac..ab4789e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 3bac80b..c8cb964 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ PushableButton( blurRadius: 7, offset: Offset(0, 2), ), + borderRadius: 16, onPressed: () => print('Button Pressed!'), ) ``` @@ -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) \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 6cbfeb6..d509e6b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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