|
1 | 1 | import 'package:flutter/material.dart';
|
2 |
| -import 'package:libadwaita/src/internal/triangle_painter.dart'; |
| 2 | +import 'package:flutter/widgets.dart'; |
| 3 | + |
| 4 | +class BorderPainter extends CustomPainter { |
| 5 | + @override |
| 6 | + void paint(Canvas canvas, Size size) { |
| 7 | + Paint paint = Paint() |
| 8 | + ..style = PaintingStyle.stroke |
| 9 | + ..strokeWidth = 1 |
| 10 | + ..color = Colors.black12; |
| 11 | + var half = size.width / 2; |
| 12 | + final path = Path(); |
| 13 | + path.moveTo(1, 12); |
| 14 | + path.lineTo(half - 10, 12); |
| 15 | + path.lineTo(half, 1); |
| 16 | + path.lineTo(half + 10, 12); |
| 17 | + path.lineTo(size.width - 1, 12); |
| 18 | + canvas.drawPath(path, paint); |
| 19 | + } |
| 20 | + |
| 21 | + @override |
| 22 | + bool shouldRepaint(CustomPainter oldDelegate) => true; |
| 23 | +} |
| 24 | + |
| 25 | +class PopOverClipper extends CustomClipper<Path> { |
| 26 | + PopOverClipper(); |
| 27 | + |
| 28 | + @override |
| 29 | + Path getClip(Size size) { |
| 30 | + var half = size.width / 2; |
| 31 | + final path = Path(); |
| 32 | + path.moveTo(0, 15); |
| 33 | + path.lineTo(half - 10, 15); |
| 34 | + path.lineTo(half, 5); |
| 35 | + path.lineTo(half + 10, 15); |
| 36 | + path.lineTo(size.width, 15); |
| 37 | + path.lineTo(size.width, size.height); |
| 38 | + path.lineTo(0.0, size.height); |
| 39 | + path.close(); |
| 40 | + return path; |
| 41 | + } |
| 42 | + |
| 43 | + @override |
| 44 | + bool shouldReclip(CustomClipper<Path> oldClipper) { |
| 45 | + return true; |
| 46 | + } |
| 47 | +} |
3 | 48 |
|
4 | 49 | class _PopoverRoute extends PopupRoute {
|
5 | 50 | final Widget body;
|
@@ -31,42 +76,30 @@ class _PopoverRoute extends PopupRoute {
|
31 | 76 | Widget buildPage(BuildContext context, Animation<double> animation,
|
32 | 77 | Animation<double> secondaryAnimation) {
|
33 | 78 | return Align(
|
34 |
| - alignment: Alignment.topLeft, |
35 |
| - child: Transform.translate( |
36 |
| - offset: Offset( |
37 |
| - position.dx + contentOffset.dx, position.dy + contentOffset.dy), |
38 |
| - child: Column( |
39 |
| - mainAxisSize: MainAxisSize.min, |
40 |
| - children: [ |
41 |
| - Stack( |
42 |
| - children: [ |
43 |
| - CustomPaint( |
44 |
| - painter: TriangleShadowPainter(color: backgroundColor), |
45 |
| - size: const Size(36, 20), |
46 |
| - ), |
47 |
| - CustomPaint( |
48 |
| - painter: TrianglePainter(color: backgroundColor), |
49 |
| - size: const Size(34, 18), |
50 |
| - ), |
51 |
| - ], |
52 |
| - ), |
53 |
| - Transform.translate( |
54 |
| - offset: const Offset(0, -5), |
55 |
| - child: SizedBox( |
56 |
| - width: width, |
57 |
| - height: height, |
58 |
| - child: Material( |
59 |
| - type: MaterialType.card, |
60 |
| - borderRadius: BorderRadius.circular(8), |
61 |
| - color: backgroundColor, |
62 |
| - child: body, |
63 |
| - ), |
64 |
| - ), |
65 |
| - ), |
66 |
| - ], |
67 |
| - ), |
68 |
| - ), |
69 |
| - ); |
| 79 | + alignment: Alignment.topLeft, |
| 80 | + child: Transform.translate( |
| 81 | + offset: Offset( |
| 82 | + position.dx + contentOffset.dx, position.dy + contentOffset.dy), |
| 83 | + child: ConstrainedBox( |
| 84 | + constraints: |
| 85 | + BoxConstraints(maxWidth: width, maxHeight: height ?? 200), |
| 86 | + child: ClipPath( |
| 87 | + clipper: PopOverClipper(), |
| 88 | + child: Card( |
| 89 | + shape: RoundedRectangleBorder( |
| 90 | + side: |
| 91 | + const BorderSide(color: Colors.black12, width: 1), |
| 92 | + borderRadius: BorderRadius.circular(8.0)), |
| 93 | + child: CustomPaint( |
| 94 | + painter: BorderPainter(), |
| 95 | + child: Container( |
| 96 | + margin: const EdgeInsets.only( |
| 97 | + left: 0.0, |
| 98 | + top: 10.0, |
| 99 | + right: 0.0, |
| 100 | + bottom: 0.0), |
| 101 | + child: body)))), |
| 102 | + ))); |
70 | 103 | }
|
71 | 104 |
|
72 | 105 | @override
|
|
0 commit comments