Comments (1)
Here is an example of such a listener if FlutterVectorGraphicsListener
would have a raw
public constructor instead of _
.
class OverridesFlutterVectorGraphicsListener
extends FlutterVectorGraphicsListener {
factory OverridesFlutterVectorGraphicsListener({
required Map<int, int> colorOverrides,
int id = 0,
Locale? locale,
TextDirection? textDirection,
bool clipViewbox = true,
@visibleForTesting
DefaultPictureFactory pictureFactory = const DefaultPictureFactory(),
}) {
final PictureRecorder recorder = pictureFactory.createPictureRecorder();
return OverridesFlutterVectorGraphicsListener.raw(
id,
pictureFactory,
recorder,
pictureFactory.createCanvas(recorder),
locale,
textDirection,
clipViewbox,
colorOverrides,
);
}
OverridesFlutterVectorGraphicsListener.raw(
int id,
DefaultPictureFactory pictureFactory,
PictureRecorder recorder,
Canvas canvas,
Locale? locale,
TextDirection? textDirection,
bool clipViewbox,
this.colorOverrides,
) : super.raw(
id,
pictureFactory,
recorder,
canvas,
locale,
textDirection,
clipViewbox,
);
final Map<int, int> colorOverrides;
@override
void onLinearGradient(
double fromX,
double fromY,
double toX,
double toY,
Int32List colors,
Float32List? offsets,
int tileMode,
int id,
) {
final colorValues = <int>[];
for (var color in colors) {
final replacedColor = colorOverrides[_colorValue(color)];
colorValues.add(replacedColor ?? color);
}
super.onLinearGradient(
fromX,
fromY,
toX,
toY,
Int32List.fromList(colorValues),
offsets,
tileMode,
id,
);
}
@override
void onPaintObject({
required int color,
required int? strokeCap,
required int? strokeJoin,
required int blendMode,
required double? strokeMiterLimit,
required double? strokeWidth,
required int paintStyle,
required int id,
required int? shaderId,
}) {
/// If we add an override we add it to the paints instead
final int? override = colorOverrides[_colorValue(color)];
if (override != null) {
return super.onPaintObject(
id: id,
color: override,
strokeCap: strokeCap,
strokeJoin: strokeJoin,
blendMode: blendMode,
strokeMiterLimit: strokeMiterLimit,
strokeWidth: strokeWidth,
paintStyle: paintStyle,
shaderId: shaderId,
);
}
return super.onPaintObject(
id: id,
color: color,
strokeCap: strokeCap,
strokeJoin: strokeJoin,
blendMode: blendMode,
strokeMiterLimit: strokeMiterLimit,
strokeWidth: strokeWidth,
paintStyle: paintStyle,
shaderId: shaderId,
);
}
final _colorData = ByteData(4);
int _colorValue(int value) {
_colorData.setInt32(0, value);
return _colorData.getUint32(0);
}
}
from vector_graphics.
Related Issues (20)
- Ignore hits on transparent parts of the image HOT 2
- adjust vector_graphics errorBuilder (to trigger on BytesLoader errors) HOT 1
- Question: Points of Path are Accessible using this package? HOT 1
- Differences between 1.1.9 and 1.1.7 HOT 5
- Invalid double -1.07502e HOT 3
- A few packages can be updated
- Wrong coloring on iOS with Impeller HOT 4
- optimize-clips incorrect with clipPath
- Migrate away from `elementAt` for Dart 3.3 HOT 5
- vector_graphics 1.1.10 breaks widgets inside an opacity HOT 7
- Export PDF/SVG/AI/EPS with Layers HOT 2
- Pub publisher HOT 1
- Support libpathops on Linux arm.
- isn't run for flutter web HOT 3
- [BUG] Caching is not working correctly. HOT 1
- ffi imported when compiling for web wasm HOT 13
- 6.6K fatal crashes on Crashlytics
- IMPROVEMENT: add an arg to skip non svg files HOT 1
- build: Occasionaly fails to rename vector file after transforming during build
- Reverse the compile of svg back to svg files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vector_graphics.