Skip to content

Instantly share code, notes, and snippets.

@m-kikuchi777
Last active November 20, 2023 14:16
Show Gist options
  • Save m-kikuchi777/96af9d4a98480f9654ccab26a9ded4bf to your computer and use it in GitHub Desktop.
Save m-kikuchi777/96af9d4a98480f9654ccab26a9ded4bf to your computer and use it in GitHub Desktop.
ClipSamplePainter
import 'dart:ui';
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(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage());
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Center(
child: CustomPaint(
painter: ClipSamplePainter(),
),
),
);
}
}
class ClipSamplePainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
canvas.clipRect(
Rect.fromLTRB(100, 100, size.width - 100, size.height - 100),
// clipOp: ClipOp.difference,
);
canvas.drawRect(Rect.largest, Paint()..color = Colors.black);
}
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment