Skip to content

Commit

Permalink
Merge 018968c into f615c3d
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Dec 16, 2019
2 parents f615c3d + 018968c commit fccd2b1
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 65 deletions.
3 changes: 2 additions & 1 deletion analysis_options.yaml
Expand Up @@ -20,6 +20,7 @@

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
# treat missing required parameters as a warning (not a hint)
Expand All @@ -43,7 +44,7 @@ linter:
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as
# - avoid_as # conflicts with implicit-casts: false
# - avoid_bool_literals_in_conditional_expressions # not yet tested
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
Expand Down
6 changes: 3 additions & 3 deletions lib/avd.dart
Expand Up @@ -21,7 +21,7 @@ final Avd avd = Avd._();
class Avd {
Avd._();

FutureOr<PictureInfo> avdPictureDecoder(
Future<PictureInfo> avdPictureDecoder(
Uint8List raw,
bool allowDrawingOutsideOfViewBox,
ColorFilter colorFilter,
Expand All @@ -33,7 +33,7 @@ class Avd {
return PictureInfo(picture: pic, viewport: avdRoot.viewport.viewBoxRect);
}

FutureOr<PictureInfo> avdPictureStringDecoder(
Future<PictureInfo> avdPictureStringDecoder(
String raw,
bool allowDrawingOutsideOfViewBox,
ColorFilter colorFilter,
Expand All @@ -49,7 +49,7 @@ class Avd {
);
}

FutureOr<DrawableRoot> fromAvdBytes(Uint8List raw, String key) async {
Future<DrawableRoot> fromAvdBytes(Uint8List raw, String key) async {
// TODO(dnfield): do utf decoding in another thread?
// Might just have to live with potentially slow(ish) decoding, this is causing errors.
// See: https://github.com/dart-lang/sdk/issues/31954
Expand Down
53 changes: 28 additions & 25 deletions lib/src/picture_provider.dart
Expand Up @@ -87,7 +87,7 @@ class PictureConfiguration {
Locale locale,
TextDirection textDirection,
Rect viewBox,
String platform,
TargetPlatform platform,
ColorFilter colorFilter,
}) {
return PictureConfiguration(
Expand Down Expand Up @@ -132,13 +132,13 @@ class PictureConfiguration {
if (other.runtimeType != runtimeType) {
return false;
}
final PictureConfiguration typedOther = other;
return typedOther.bundle == bundle &&
typedOther.locale == locale &&
typedOther.textDirection == textDirection &&
typedOther.viewBox == viewBox &&
typedOther.platform == platform &&
typedOther.colorFilter == colorFilter;
return other is PictureConfiguration &&
other.bundle == bundle &&
other.locale == locale &&
other.textDirection == textDirection &&
other.viewBox == viewBox &&
other.platform == platform &&
other.colorFilter == colorFilter;
}

@override
Expand Down Expand Up @@ -399,10 +399,10 @@ class AssetBundlePictureKey {
if (other.runtimeType != runtimeType) {
return false;
}
final AssetBundlePictureKey typedOther = other;
return bundle == typedOther.bundle &&
name == typedOther.name &&
colorFilter == typedOther.colorFilter;
return other is AssetBundlePictureKey &&
bundle == other.bundle &&
name == other.name &&
colorFilter == other.colorFilter;
}

@override
Expand Down Expand Up @@ -516,8 +516,9 @@ class NetworkPicture extends PictureProvider<NetworkPicture> {
if (other.runtimeType != runtimeType) {
return false;
}
final NetworkPicture typedOther = other;
return url == typedOther.url && colorFilter == typedOther.colorFilter;
return other is NetworkPicture &&
url == other.url &&
colorFilter == other.colorFilter;
}

@override
Expand Down Expand Up @@ -583,9 +584,9 @@ class FilePicture extends PictureProvider<FilePicture> {
if (other.runtimeType != runtimeType) {
return false;
}
final FilePicture typedOther = other;
return file?.path == typedOther.file?.path &&
typedOther.colorFilter == colorFilter;
return other is FilePicture &&
file?.path == other.file?.path &&
other.colorFilter == colorFilter;
}

@override
Expand Down Expand Up @@ -649,8 +650,9 @@ class MemoryPicture extends PictureProvider<MemoryPicture> {
if (other.runtimeType != runtimeType) {
return false;
}
final MemoryPicture typedOther = other;
return bytes == typedOther.bytes && colorFilter == typedOther.colorFilter;
return other is MemoryPicture &&
bytes == other.bytes &&
colorFilter == other.colorFilter;
}

@override
Expand Down Expand Up @@ -715,8 +717,9 @@ class StringPicture extends PictureProvider<StringPicture> {
if (other.runtimeType != runtimeType) {
return false;
}
final StringPicture typedOther = other;
return string == typedOther.string && colorFilter == typedOther.colorFilter;
return other is StringPicture &&
string == other.string &&
colorFilter == other.colorFilter;
}

@override
Expand Down Expand Up @@ -858,10 +861,10 @@ class ExactAssetPicture extends AssetBundlePictureProvider {
if (other.runtimeType != runtimeType) {
return false;
}
final ExactAssetPicture typedOther = other;
return keyName == typedOther.keyName &&
bundle == typedOther.bundle &&
colorFilter == typedOther.colorFilter;
return other is ExactAssetPicture &&
keyName == other.keyName &&
bundle == other.bundle &&
colorFilter == other.colorFilter;
}

@override
Expand Down
10 changes: 5 additions & 5 deletions lib/src/picture_stream.dart
Expand Up @@ -50,10 +50,10 @@ class PictureInfo {
if (other.runtimeType != runtimeType) {
return false;
}
final PictureInfo typedOther = other;
return typedOther.picture == picture &&
typedOther.viewport == viewport &&
typedOther.size == size;
return other is PictureInfo &&
other.picture == picture &&
other.viewport == viewport &&
other.size == size;
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ abstract class PictureStreamCompleter extends Diagnosticable {
DiagnosticsNode context, dynamic exception, dynamic stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
stack: stack as StackTrace,
library: 'SVG',
context: context,
));
Expand Down
7 changes: 6 additions & 1 deletion lib/src/render_picture.dart
Expand Up @@ -208,7 +208,12 @@ void scaleCanvasToViewBox(
desiredSize.width / viewBox.width,
desiredSize.height / viewBox.height,
);
final Offset shift = desiredSize / 2.0 - viewBox.size * scale / 2.0;
final Size scaledHalfViewBoxSize = viewBox.size * scale / 2.0;
final Size halfDesiredSize = desiredSize / 2.0;
final Offset shift = Offset(
halfDesiredSize.width - scaledHalfViewBoxSize.width,
halfDesiredSize.height - scaledHalfViewBoxSize.height,
);
canvas.translate(shift.dx, shift.dy);
canvas.scale(scale, scale);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/svg/parsers.dart
Expand Up @@ -200,7 +200,8 @@ Future<Image> resolveImage(String href) async {
return null;
}

final Function decodeImage = (Uint8List bytes) async {
final Future<Image> Function(Uint8List) decodeImage =
(Uint8List bytes) async {
final Codec codec = await instantiateImageCodec(bytes);
final FrameInfo frame = await codec.getNextFrame();
return frame.image;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/svg/xml_parsers.dart
Expand Up @@ -147,7 +147,7 @@ DashOffset parseDashOffset(List<XmlElementAttribute> attributes) {
double parseOpacity(List<XmlElementAttribute> attributes) {
final String rawOpacity = getAttribute(attributes, 'opacity', def: null);
if (rawOpacity != null) {
return parseDouble(rawOpacity).clamp(0.0, 1.0);
return parseDouble(rawOpacity).clamp(0.0, 1.0).toDouble();
}
return null;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ DrawablePaint parseStroke(
def: '1.0',
);
final String rawOpacity = getAttribute(attributes, 'opacity');
double opacity = parseDouble(rawStrokeOpacity).clamp(0.0, 1.0);
double opacity = parseDouble(rawStrokeOpacity).clamp(0.0, 1.0).toDouble();
if (rawOpacity != '') {
opacity *= parseDouble(rawOpacity).clamp(0.0, 1.0);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ DrawablePaint parseFill(
final String rawFill = getAttribute(el, 'fill');
final String rawFillOpacity = getAttribute(el, 'fill-opacity', def: '1.0');
final String rawOpacity = getAttribute(el, 'opacity');
double opacity = parseDouble(rawFillOpacity).clamp(0.0, 1.0);
double opacity = parseDouble(rawFillOpacity).clamp(0.0, 1.0).toDouble();
if (rawOpacity != '') {
opacity *= parseDouble(rawOpacity).clamp(0.0, 1.0);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/src/vector_drawable.dart
Expand Up @@ -604,7 +604,7 @@ class DrawableDefinitionServer {
/// Retreive a gradient from the pre-defined [DrawableGradient] collection.
T getGradient<T extends DrawableGradient>(String id) {
assert(id != null);
return _gradients[id];
return _gradients[id] as T;
}

/// Add a [DrawableGradient] to the pre-defined collection by [id].
Expand Down Expand Up @@ -1108,7 +1108,12 @@ class DrawableRasterImage implements Drawable {
);
}
if (scale != 1.0 || offset != Offset.zero || transform != null) {
final Offset shift = desiredSize / 2.0 - imageSize * scale / 2.0;
final Size halfDesiredSize = desiredSize / 2.0;
final Size scaledHalfImageSize = imageSize * scale / 2.0;
final Offset shift = Offset(
halfDesiredSize.width - scaledHalfImageSize.width,
halfDesiredSize.height - scaledHalfImageSize.height,
);
canvas.save();
canvas.translate(offset.dx + shift.dx, offset.dy + shift.dy);
canvas.scale(scale, scale);
Expand Down
6 changes: 3 additions & 3 deletions lib/svg.dart
Expand Up @@ -36,7 +36,7 @@ class Svg {
/// The `colorFilter` property will be applied to any [Paint] objects used during drawing.
///
/// The [key] will be used for debugging purposes.
FutureOr<PictureInfo> svgPictureDecoder(
Future<PictureInfo> svgPictureDecoder(
Uint8List raw,
bool allowDrawingOutsideOfViewBox,
ColorFilter colorFilter,
Expand Down Expand Up @@ -64,7 +64,7 @@ class Svg {
/// The `colorFilter` property will be applied to any [Paint] objects used during drawing.
///
/// The [key] will be used for debugging purposes.
FutureOr<PictureInfo> svgPictureStringDecoder(
Future<PictureInfo> svgPictureStringDecoder(
String raw,
bool allowDrawingOutsideOfViewBox,
ColorFilter colorFilter,
Expand All @@ -84,7 +84,7 @@ class Svg {
/// Produces a [Drawableroot] from a [Uint8List] of SVG byte data (assumes UTF8 encoding).
///
/// The [key] will be used for debugging purposes.
FutureOr<DrawableRoot> fromSvgBytes(Uint8List raw, String key) async {
Future<DrawableRoot> fromSvgBytes(Uint8List raw, String key) async {
// TODO(dnfield): do utf decoding in another thread?
// Might just have to live with potentially slow(ish) decoding, this is causing errors.
// See: https://github.com/dart-lang/sdk/issues/31954
Expand Down
14 changes: 9 additions & 5 deletions test/widget_svg_test.dart
Expand Up @@ -61,7 +61,7 @@ void main() {
</g>
</svg>''';

final Uint8List svg = utf8.encode(svgStr);
final Uint8List svg = utf8.encode(svgStr) as Uint8List;

testWidgets('SvgPicture can work with a FittedBox',
(WidgetTester tester) async {
Expand Down Expand Up @@ -258,10 +258,14 @@ void main() {
onError: anyNamed('onError'),
cancelOnError: anyNamed('cancelOnError')))
.thenAnswer((Invocation invocation) {
final void Function(Uint8List) onData = invocation.positionalArguments[0];
final void Function(Object) onError = invocation.namedArguments[#onError];
final void Function() onDone = invocation.namedArguments[#onDone];
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
final void Function(Uint8List) onData =
invocation.positionalArguments[0] as void Function(Uint8List);
final void Function(Object) onError =
invocation.namedArguments[#onError] as void Function(Object);
final VoidCallback onDone =
invocation.namedArguments[#onDone] as VoidCallback;
final bool cancelOnError =
invocation.namedArguments[#cancelOnError] as bool;

return Stream<Uint8List>.fromIterable(<Uint8List>[svg]).listen(
onData,
Expand Down

0 comments on commit fccd2b1

Please sign in to comment.