canvas_test 0.2.0
canvas_test: ^0.2.0 copied to clipboard
A package with classes to help testing applications using the canvas
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
// Outer white container with padding
body: Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 80),
// Inner yellow container
child: Container(
// pass double.infinity to prevent shrinking of the painter area to 0.
width: double.infinity,
height: double.infinity,
color: Colors.black,
child: CustomPaint(painter: RectanglePainter()),
),
),
),
);
}
}
class RectanglePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 4.0
..color = Colors.indigo;
canvas.drawRect(
const Rect.fromLTWH(100, 100, 100, 100),
paint,
);
}
@override
bool shouldRepaint(RectanglePainter oldDelegate) => false;
}
copied to clipboard