Created
March 20, 2020 01:50
-
-
Save Rahiche/4f73c6d8c22d628419a84b3b4a44b9bb 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'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: CropRect( | |
child: Image.network( | |
"https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg", | |
fit: BoxFit.fill, | |
), | |
clipper: TriangleClipper(), | |
size: const Size(200, 200), | |
), | |
), | |
), | |
); | |
} | |
} | |
class CropRect extends StatelessWidget { | |
final CustomClipper<Path> clipper; | |
final Size size; | |
final Widget child; | |
const CropRect({Key key, this.clipper, this.size, this.child}) | |
: super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
width: clipper.getClip(size).getBounds().width, | |
height: clipper.getClip(size).getBounds().height, | |
child: Stack( | |
children: <Widget>[ | |
Positioned( | |
height: size.height, | |
width: size.width, | |
child: ClipPath( | |
clipper: clipper, | |
child: Image.network( | |
"https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg", | |
fit: BoxFit.fill, | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
class TriangleClipper extends CustomClipper<Path> { | |
@override | |
Path getClip(Size size) { | |
final path = Path(); | |
path.moveTo(10, 10); | |
path.lineTo(100, 10); | |
path.lineTo(100, 110); | |
path.lineTo(10, 110); | |
path.close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(TriangleClipper oldClipper) => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment