@@ -4,6 +4,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
4
4
_DropdownRoute ({
5
5
required this .items,
6
6
required this .buttonRect,
7
+ required this .buttonBorderRadius,
7
8
required this .selectedIndex,
8
9
required this .isNoSelectedItem,
9
10
required this .onChanged,
@@ -25,6 +26,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
25
26
26
27
final List <DropdownItem <T >> items;
27
28
final ValueNotifier <Rect ?> buttonRect;
29
+ final BorderRadius ? buttonBorderRadius;
28
30
final int selectedIndex;
29
31
final bool isNoSelectedItem;
30
32
final ValueChanged <T ?>? onChanged;
@@ -89,10 +91,11 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
89
91
return barrierCoversButton
90
92
? routePage
91
93
: _CustomModalBarrier (
92
- animation: animation,
93
94
barrierColor: _altBarrierColor,
95
+ animation: animation,
94
96
barrierCurve: barrierCurve,
95
97
buttonRect: rect,
98
+ buttonBorderRadius: buttonBorderRadius ?? BorderRadius .zero,
96
99
child: routePage,
97
100
);
98
101
},
@@ -458,18 +461,20 @@ class _DropdownRouteResult<T> {
458
461
/// It's used instead of the route barrier when `barrierCoversButton` is set to false.
459
462
class _CustomModalBarrier extends StatefulWidget {
460
463
const _CustomModalBarrier ({
461
- this .animation ,
462
- this .barrierColor ,
464
+ required this .barrierColor ,
465
+ required this .animation ,
463
466
required this .barrierCurve,
467
+ required this .buttonRect,
468
+ required this .buttonBorderRadius,
464
469
required this .child,
465
- this .buttonRect,
466
470
});
467
471
468
- final Animation <double >? animation;
469
472
final Color ? barrierColor;
473
+ final Animation <double >? animation;
470
474
final Curve barrierCurve;
475
+ final Rect buttonRect;
476
+ final BorderRadius buttonBorderRadius;
471
477
final Widget child;
472
- final Rect ? buttonRect;
473
478
474
479
@override
475
480
State <_CustomModalBarrier > createState () => _CustomModalBarrierState ();
@@ -503,8 +508,9 @@ class _CustomModalBarrierState extends State<_CustomModalBarrier> {
503
508
builder: (BuildContext context, Color ? value, Widget ? child) {
504
509
return CustomPaint (
505
510
painter: _DropdownBarrierPainter (
506
- buttonRect: widget.buttonRect,
507
511
barrierColor: value,
512
+ buttonRect: widget.buttonRect,
513
+ buttonBorderRadius: widget.buttonBorderRadius,
508
514
pageSize: size,
509
515
),
510
516
);
@@ -518,29 +524,47 @@ class _CustomModalBarrierState extends State<_CustomModalBarrier> {
518
524
519
525
class _DropdownBarrierPainter extends CustomPainter {
520
526
const _DropdownBarrierPainter ({
521
- this .buttonRect,
522
- this .barrierColor,
527
+ required this .barrierColor,
528
+ required this .buttonRect,
529
+ required this .buttonBorderRadius,
523
530
required this .pageSize,
524
531
});
525
532
526
- final Rect ? buttonRect;
527
533
final Color ? barrierColor;
534
+ final Rect buttonRect;
535
+ final BorderRadius buttonBorderRadius;
528
536
final Size pageSize;
529
537
530
538
@override
531
539
void paint (Canvas canvas, Size size) {
532
- if (barrierColor != null && buttonRect != null ) {
533
- final Rect rect =
534
- Rect .fromLTRB (- buttonRect! .left, - buttonRect! .top, pageSize.width, pageSize.height);
540
+ if (barrierColor != null ) {
541
+ final Rect rect = Rect .fromLTRB (
542
+ - buttonRect.left,
543
+ - buttonRect.top,
544
+ pageSize.width,
545
+ pageSize.height,
546
+ );
547
+
535
548
canvas.saveLayer (rect, Paint ());
536
549
canvas.drawRect (rect, Paint ()..color = barrierColor! );
537
- canvas.drawRect (buttonRect! , Paint ()..blendMode = BlendMode .clear);
550
+
551
+ final RRect buttonRRect = RRect .fromRectAndCorners (
552
+ buttonRect,
553
+ topLeft: buttonBorderRadius.topLeft,
554
+ topRight: buttonBorderRadius.topRight,
555
+ bottomLeft: buttonBorderRadius.bottomLeft,
556
+ bottomRight: buttonBorderRadius.bottomRight,
557
+ );
558
+
559
+ canvas.drawRRect (buttonRRect, Paint ()..blendMode = BlendMode .clear);
538
560
canvas.restore ();
539
561
}
540
562
}
541
563
542
564
@override
543
565
bool shouldRepaint (_DropdownBarrierPainter oldPainter) {
544
- return oldPainter.buttonRect != buttonRect || oldPainter.barrierColor != barrierColor;
566
+ return oldPainter.buttonRect != buttonRect ||
567
+ oldPainter.barrierColor != barrierColor ||
568
+ oldPainter.buttonBorderRadius != buttonBorderRadius;
545
569
}
546
570
}
0 commit comments