Last active
November 20, 2023 14:16
-
-
Save m-kikuchi777/96af9d4a98480f9654ccab26a9ded4bf to your computer and use it in GitHub Desktop.
ClipSamplePainter
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 '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