You can try to use CustomPaint with some clipping with paths.
Please find the full example here in the DartPad.
The tricky part is to determine how to clip the rounded white rectangle borders. I just used custom Path for that. I created custom Rects and created a Path out of them:
final path = Path()
..addRect(clippingRect0)
..addRect(clippingRect1)
..addRect(clippingRect2)
..addRect(clippingRect3);
It may be not the most efficient approach, but sometimes it's faster to draw something with CustomPainter than to experiment with some already provided widgets. This way you will have always the same look no matter how the API of the material widget changes.
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;
}
Decoration
class, something likeCornerDecoration
in gist.github.com/pskink/da43c327b75eec05d903fa1b4d0c4d3e