From debfd6903e47895f008921859e52c260c2c4c149 Mon Sep 17 00:00:00 2001 From: adityamahendrap Date: Tue, 17 Sep 2024 21:48:21 +0800 Subject: [PATCH] add gradient --- lib/curved_navigation_bar.dart | 18 ++++++++++++++---- lib/src/nav_custom_painter.dart | 7 +++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/curved_navigation_bar.dart b/lib/curved_navigation_bar.dart index f9c2016..a7b923e 100644 --- a/lib/curved_navigation_bar.dart +++ b/lib/curved_navigation_bar.dart @@ -19,6 +19,7 @@ class CurvedNavigationBar extends StatefulWidget { final Duration animationDuration; final double height; final double? maxWidth; + final Gradient? gradient; CurvedNavigationBar({ Key? key, @@ -33,6 +34,7 @@ class CurvedNavigationBar extends StatefulWidget { this.animationDuration = const Duration(milliseconds: 600), this.height = 75.0, this.maxWidth, + this.gradient, }) : letIndexChange = letIndexChange ?? ((_) => true), assert(items.isNotEmpty), assert(0 <= index && index < items.length), @@ -137,9 +139,13 @@ class CurvedNavigationBarState extends State 0, -(1 - _buttonHide) * 80, ), - child: Material( - color: widget.buttonBackgroundColor ?? widget.color, - type: MaterialType.circle, + child: Container( + decoration: BoxDecoration( + color: + widget.buttonBackgroundColor ?? widget.color, + shape: BoxShape.circle, + gradient: widget.gradient, + ), child: Padding( padding: const EdgeInsets.all(8.0), child: _icon, @@ -154,7 +160,11 @@ class CurvedNavigationBarState extends State bottom: 0 - (75.0 - widget.height), child: CustomPaint( painter: NavCustomPainter( - _pos, _length, widget.color, textDirection), + _pos, + _length, + widget.color, + textDirection, + widget.gradient), child: Container( height: 75.0, ), diff --git a/lib/src/nav_custom_painter.dart b/lib/src/nav_custom_painter.dart index bb0965d..51f3a19 100644 --- a/lib/src/nav_custom_painter.dart +++ b/lib/src/nav_custom_painter.dart @@ -5,9 +5,10 @@ class NavCustomPainter extends CustomPainter { late double s; Color color; TextDirection textDirection; + Gradient? gradient; - NavCustomPainter( - double startingLoc, int itemsLength, this.color, this.textDirection) { + NavCustomPainter(double startingLoc, int itemsLength, this.color, + this.textDirection, this.gradient) { final span = 1.0 / itemsLength; s = 0.2; double l = startingLoc + (span - s) / 2; @@ -18,6 +19,8 @@ class NavCustomPainter extends CustomPainter { void paint(Canvas canvas, Size size) { final paint = Paint() ..color = color + ..shader = + gradient?.createShader(Rect.fromLTWH(0, 0, size.width, size.height)) ..style = PaintingStyle.fill; final path = Path()