Last active
June 23, 2018 04:26
-
-
Save hnvn/a23d7294d5a795217b2f4008d2c56e72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/rendering.dart'; | |
class _Shimmer extends SingleChildRenderObjectWidget { | |
final Gradient gradient; | |
_Shimmer({Widget child, this.gradient}) | |
: super(child: child); | |
@override | |
_ShimmerFilter createRenderObject(BuildContext context) { | |
return _ShimmerFilter(gradient); | |
} | |
} | |
class _ShimmerFilter extends RenderProxyBox { | |
final _clearPaint = Paint(); | |
final Paint _gradientPaint; | |
final Gradient _gradient; | |
_ShimmerFilter(this._gradient) | |
: _gradientPaint = Paint()..blendMode = BlendMode.srcIn; | |
@override | |
bool get alwaysNeedsCompositing => child != null; | |
@override | |
void paint(PaintingContext context, Offset offset) { | |
if (child != null) { | |
assert(needsCompositing); | |
final rect = offset & child.size; | |
_gradientPaint.shader = _gradient.createShader(rect); | |
context.canvas.saveLayer(rect, _clearPaint); | |
context.paintChild(child, offset); | |
context.canvas.drawRect(rect, _gradientPaint); | |
context.canvas.restore(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment