We need to start this recipe by first creating a shell that that will hold the CustomPainter subclass:
- Update the Star class to use a CustomPaint widget:
import 'package:flutter/material.dart';
class Star extends StatelessWidget {
final Color color;
final double size;
const Star({
Key key,
this.color,
this.size,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SizedBox(
width: size,
height: size,
child: CustomPaint(
painter: _StarPainter(color),
),
);
}
}
- This code will throw an error because the _StarPainter class doesn't exist yet. Create it now and make sure to override the required methods of CustomPainter:
class _StarPainter extends CustomPainter {
final Color color;
_StarPainter(this.color);
@override
void paint(Canvas canvas, Size size) {
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
- Update the...