Created
December 13, 2019 12:49
-
-
Save andrea689/c48b74910c7ee282427dc85eef5da7cb to your computer and use it in GitHub Desktop.
Flutter - Container with hole
This file contains hidden or 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( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
backgroundColor: Colors.blue, | |
appBar: AppBar( | |
title: Text('Container with hole'), | |
), | |
body: Center( | |
child: Container( | |
child: Stack( | |
children: [ | |
Image.network( | |
'https://picsum.photos/250?image=9', | |
), | |
Container( | |
width: 250, | |
height: 250, | |
color: Colors.transparent, | |
child: CustomPaint( | |
painter: Hole(), | |
), | |
) | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class Hole extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
canvas.drawCircle( | |
Offset(size.width / 2, size.height / 2), | |
size.width / 4, | |
Paint() | |
..blendMode = BlendMode.xor | |
..color = Colors.yellow, | |
); | |
} | |
@override | |
bool shouldRepaint(Hole oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment