Created
April 24, 2020 13:24
-
-
Save orestesgaolin/3549b954e820ba9e9098697814f7ea32 to your computer and use it in GitHub Desktop.
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
color: Colors.grey, | |
child: Stack( | |
children: [ | |
Center( | |
child: FlutterLogo( | |
size: 800, | |
), | |
), | |
Container( | |
child: Center( | |
child: CustomPaint( | |
painter: BorderPainter(), | |
child: Container( | |
width: BarReaderSize.width, | |
height: BarReaderSize.height, | |
), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class BorderPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final width = 3.0; | |
final radius = 20.0; | |
final tRadius = 2 * radius; | |
final rect = Rect.fromLTWH( | |
width, | |
width, | |
size.width - 2 * width, | |
size.height - 2 * width, | |
); | |
final rrect = RRect.fromRectAndRadius(rect, Radius.circular(radius)); | |
final clippingRect0 = Rect.fromLTWH( | |
0, | |
0, | |
tRadius, | |
tRadius, | |
); | |
final clippingRect1 = Rect.fromLTWH( | |
size.width - tRadius, | |
0, | |
tRadius, | |
tRadius, | |
); | |
final clippingRect2 = Rect.fromLTWH( | |
0, | |
size.height - tRadius, | |
tRadius, | |
tRadius, | |
); | |
final clippingRect3 = Rect.fromLTWH( | |
size.width - tRadius, | |
size.height - tRadius, | |
tRadius, | |
tRadius, | |
); | |
final path = Path() | |
..addRect(clippingRect0) | |
..addRect(clippingRect1) | |
..addRect(clippingRect2) | |
..addRect(clippingRect3); | |
canvas.clipPath(path); | |
canvas.drawRRect( | |
rrect, | |
Paint() | |
..color = Colors.white | |
..style = PaintingStyle.stroke | |
..strokeWidth = width, | |
); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) { | |
return false; | |
} | |
} | |
class BarReaderSize { | |
static double width = 200; | |
static double height = 200; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment