Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created July 6, 2018 17:18
Show Gist options
  • Save jonahwilliams/4817c76b6fca618863704becd0f42964 to your computer and use it in GitHub Desktop.
Save jonahwilliams/4817c76b6fca618863704becd0f42964 to your computer and use it in GitHub Desktop.
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