flutter_svg
flutter_svg copied to clipboard
Proposal to add `ColorMapper.fromCallback` constructor
Personally I find it a bit excessive having to write a new class extending ColorMapper just to override one method which is ColorMapper.substitute. This method is usually quite simple an can be expressed in few lines of code without any complex logic.
For cases like that I propose to add the new ColorMapper.fromCallback named constructor that would take the substitute method as a callback. Somewhat precise implementation would be something like this.
abstract class ColorMapper {
const ColorMapper();
const factory ColorMapper.fromCallback(
SubstituteCallback substitute,
) = _ColorMapperCallback;
Color substitute(
String? id,
String elementName,
String attributeName,
Color color,
);
}
class _ColorMapperCallback implements ColorMapper {
const _ColorMapperCallback(this._substitute);
final Color Function(
String? id,
String elementName,
String attributeName,
Color color,
) _substitute;
@override
Color substitute(
String? id,
String elementName,
String attributeName,
Color color,
) =>
_substitute(
id,
elementName,
attributeName,
color,
);
}
I don't see why not. It could make evolving the ColorMapper interface harder but I'm not sure how much evolution it really would/will need.