Skip to content

Instantly share code, notes, and snippets.

@andrea689
Created December 13, 2019 12:49
Show Gist options
  • Save andrea689/c48b74910c7ee282427dc85eef5da7cb to your computer and use it in GitHub Desktop.
Save andrea689/c48b74910c7ee282427dc85eef5da7cb to your computer and use it in GitHub Desktop.
Flutter - Container with hole
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