Skip to content

Instantly share code, notes, and snippets.

@coman3
Created January 27, 2019 07:41
Show Gist options
  • Save coman3/bc8ea7c16db0461acf753f6d856f2757 to your computer and use it in GitHub Desktop.
Save coman3/bc8ea7c16db0461acf753f6d856f2757 to your computer and use it in GitHub Desktop.
DropShadow on ClipRect
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class AppScaffold extends StatefulWidget {
final double offsetSize;
const AppScaffold({
@required this.offsetSize,
});
@override
State<StatefulWidget> createState() => _AppScaffoldState();
}
class _AppScaffoldState extends State<AppScaffold> {
_AppScaffoldState();
onDragStart(DragStartDetails details) {
print(details);
}
Widget buildMenuWidget(BuildContext context) {
return Align(
alignment: Alignment(1, 1),
child: Icon(
Icons.menu,
color: Colors.black,
),
);
}
Widget buildBodyWidget(BuildContext context) {
return CustomPaint(
painter: MyCustomPainter(
clipSize: 55,
blurSize: 4
),
child: ClipPath(
clipper: MyCustomClipper(clipSize: 55),
child: Scaffold(
body: Center(
child: Text("Test"),
),
),
),
);
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
),
padding: EdgeInsets.fromLTRB(0, 0, widget.offsetSize, widget.offsetSize),
child: Stack(
children: <Widget>[
buildMenuWidget(context),
buildBodyWidget(context),
],
),
);
}
}
class Paths {
static Path getMenuClipPath(Size size, double clipSize) {
var path = Path();
var bottomRight = Offset(size.width, size.height);
List<Offset> points = [
Offset(0, 0),
Offset(size.width, 0),
bottomRight - Offset(0, clipSize),
bottomRight - Offset(clipSize, 0),
Offset(0, size.height)
];
path.addPolygon(points, true);
return path;
}
}
class MyCustomClipper extends CustomClipper<Path> {
double clipSize;
MyCustomClipper({this.clipSize});
@override
Path getClip(Size size) {
return Paths.getMenuClipPath(size, clipSize);
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}
class MyCustomPainter extends CustomPainter {
double clipSize;
double blurSize;
MyCustomPainter({this.clipSize, this.blurSize});
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
..color = Colors.black
..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSize);
var path = Paths.getMenuClipPath(size, clipSize);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
// TODO: implement shouldRepaint
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment