Created
July 6, 2018 17:18
-
-
Save jonahwilliams/4817c76b6fca618863704becd0f42964 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
void main() { | |
runApp(new Center(child: new Example())); | |
} | |
class Ancestor extends SingleChildRenderObjectWidget { | |
const Ancestor({Widget child, Key key}): super(child: child, key: key); | |
@override | |
RenderObject createRenderObject(BuildContext context) { | |
return new RenderAncestor(); | |
} | |
} | |
class RenderAncestor extends RenderProxyBox { | |
@override | |
bool get alwaysNeedsCompositing => true; | |
@override | |
void paint(PaintingContext context, Offset offset) { | |
context.pushLayer(new OffsetLayer(), super.paint, offset); | |
} | |
} | |
class Example extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Transform( // Transform widget | |
transform: new Matrix4.identity()..setEntry(3, 0, 0.0003), // remove perspective x and it renders correctly | |
alignment: FractionalOffset.center, | |
child: new Ancestor( | |
child: new Material( | |
child: new Container( | |
color: Colors.red, | |
width: 200.0, | |
height: 200.0, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment