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

add gradient #152

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
18 changes: 14 additions & 4 deletions lib/curved_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CurvedNavigationBar extends StatefulWidget {
final Duration animationDuration;
final double height;
final double? maxWidth;
final Gradient? gradient;

CurvedNavigationBar({
Key? key,
Expand All @@ -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),
Expand Down Expand Up @@ -137,9 +139,13 @@ class CurvedNavigationBarState extends State<CurvedNavigationBar>
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,
Expand All @@ -154,7 +160,11 @@ class CurvedNavigationBarState extends State<CurvedNavigationBar>
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,
),
Expand Down
7 changes: 5 additions & 2 deletions lib/src/nav_custom_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down