Created
March 31, 2017 22:53
-
-
Save abarth/dc9281fb43648bb13cd21ce01daf1a33 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'; | |
import 'package:flutter/widgets.dart'; | |
class OffscreenRenderView extends RenderView { | |
OffscreenRenderView() : super(configuration: const ViewConfiguration(size: const Size(800.0, 600.0))); | |
@override | |
void compositeFrame() { | |
// Don't draw to ui.window | |
} | |
} | |
class OffscreenWidgetTree { | |
OffscreenWidgetTree() { | |
renderView.attach(pipelineOwner); | |
renderView.scheduleInitialFrame(); | |
} | |
final RenderView renderView = new OffscreenRenderView(); | |
final BuildOwner buildOwner = new BuildOwner(); | |
final PipelineOwner pipelineOwner = new PipelineOwner(); | |
RenderObjectToWidgetElement<RenderBox> root; | |
void pumpWidget(Widget app) { | |
root = new RenderObjectToWidgetAdapter<RenderBox>( | |
container: renderView, | |
debugShortDescription: '[root]', | |
child: app | |
).attachToRenderTree(buildOwner, root); | |
pumpFrame(); | |
} | |
void pumpFrame() { | |
buildOwner.buildScope(root); | |
pipelineOwner.flushLayout(); | |
buildOwner.finalizeTree(); | |
} | |
} | |
void main() { | |
runApp(new Center(child: new Text('Hello, world!'))); | |
BuildContext savedContext; | |
final Widget container = new Container(width: 400.0, height: 300.0); | |
final Widget builder = new Builder( | |
builder: (BuildContext context) { | |
savedContext = context; | |
return container; | |
}, | |
); | |
new OffscreenWidgetTree().pumpWidget(new Center(child: builder)); | |
final double height = savedContext.size.height; | |
runApp(new Center(child: new Text('height: $height'))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment