If you do not want to add manual drawable resources to your Android project, you can use iconBytes or imageBytes to pass PNG data directly. This is useful for using Flutter's Icons library.
Note: When both a name and bytes are provided for the same icon, the bytes take precedence. For the small icon, Android expects a white silhouette on a transparent background to allow for system tinting.
Future<Uint8List> iconDataToPngBytes(IconData icon, {double size = 24, Color color = Colors.white}) async {
final recorder = PictureRecorder();
final canvas = Canvas(recorder);
final painter = TextPainter(textDirection: TextDirection.ltr)
..text = TextSpan(
text: String.fromCharCode(icon.codePoint),
style: TextStyle(
fontSize: size,
fontFamily: icon.fontFamily,
package: icon.fontPackage,
color: color,
),
)
..layout();
painter.paint(canvas, Offset.zero);
final image = await recorder.endRecording().toImage(size.ceil(), size.ceil());
final bytes = await image.toByteData(format: ImageByteFormat.png);
return bytes!.buffer.asUint8List();
}
await location.changeNotificationOptions(
iconBytes: await iconDataToPngBytes(Icons.location_on),
);