Created
October 9, 2020 22:15
-
-
Save imaNNeo/53139d029e65bb3fed4c26f983e37d16 to your computer and use it in GitHub Desktop.
BottomNav1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
main() => runApp(MaterialApp(home: MyHomePage())); | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter4Fun.com'), | |
), | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(18.0), | |
child: MyBottomSheet(), | |
), | |
), | |
); | |
} | |
} | |
class MyBottomSheet extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CustomPaint( | |
painter: _MyBottomSheetCustomPainter(), | |
size: Size( | |
double.infinity, | |
74, | |
), | |
); | |
} | |
} | |
class _MyBottomSheetCustomPainter extends CustomPainter { | |
static final double holeWidth = 80; | |
static final double holeWidthHalf = holeWidth / 2; | |
static final double holeHeight = 30; | |
final double targetXPercent; | |
_MyBottomSheetCustomPainter({this.targetXPercent = 0.5}); | |
@override | |
void paint(Canvas canvas, Size size) { | |
Path p = new Path(); | |
final targetX = size.width * targetXPercent; | |
final point0 = Offset(0, 0); | |
p.moveTo(point0.dx, point0.dy); | |
final point1 = Offset(targetX - holeWidthHalf, 0); | |
p.lineTo(point1.dx, point1.dy); | |
final point2 = Offset(targetX, holeHeight); | |
final controlPoint1 = Offset(point1.dx + 24, 0); | |
final controlPoint2 = Offset(point1.dx + 15, 28); | |
p.cubicTo( | |
controlPoint1.dx, | |
controlPoint1.dy, | |
controlPoint2.dx, | |
controlPoint2.dy, | |
point2.dx, | |
point2.dy, | |
); | |
canvas.drawPath( | |
p, | |
Paint() | |
..color = Colors.black | |
..style = PaintingStyle.stroke | |
..strokeWidth = 2); | |
drawPoint(canvas, point0, offset: Offset(-14, 8)); | |
drawPoint(canvas, point1, offset: Offset(-24, -20)); | |
drawPoint(canvas, controlPoint1, color: Colors.green, offset: Offset(8, -7),); | |
drawPoint(canvas, controlPoint2, color: Colors.red, offset: Offset(-40, 8),); | |
} | |
void drawPoint( | |
Canvas canvas, | |
Offset point, { | |
String title = '', | |
Color color = Colors.black, | |
Offset offset = Offset.zero, | |
double pointSize = 4, | |
}) { | |
canvas.drawCircle(point, pointSize, Paint()..color = color); | |
final textPainter = TextPainter( | |
text: TextSpan( | |
text: '$title(${point.dx.toInt()}, ${point.dy.toInt()})', | |
style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 12)), | |
textDirection: TextDirection.ltr, | |
textAlign: TextAlign.left, | |
); | |
textPainter.layout(); | |
textPainter.paint(canvas, point + offset); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment