Skip to content

Instantly share code, notes, and snippets.

@nobuh
Created June 13, 2024 06:59
Show Gist options
  • Save nobuh/298451842bcbb6cfa8b6da497f9cb6bf to your computer and use it in GitHub Desktop.
Save nobuh/298451842bcbb6cfa8b6da497f9cb6bf to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('CustomPaint Example')),
body: Center(
child: CustomPaint(
painter: MyCustomPainter(),
child: Container(
width: 400,
height: 400,
),
),
),
),
);
}
}
class MyCustomPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.black
..strokeWidth = 1.0;
canvas.drawRect(Rect.fromPoints(Offset(0, 0), Offset(4, 4)), paint);
//canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment