Skip to content

Instantly share code, notes, and snippets.

@marcoleonardini
Created January 25, 2022 15:03
Show Gist options
  • Save marcoleonardini/1de72e05bad7f869e9cc91206cd63ead to your computer and use it in GitHub Desktop.
Save marcoleonardini/1de72e05bad7f869e9cc91206cd63ead to your computer and use it in GitHub Desktop.
MeasureSize.dart
class MeasureSizeRenderObject extends RenderProxyBox {
Size? oldSize;
final ValueChanged<Size> onChange;
MeasureSizeRenderObject(this.onChange);
@override
void performLayout() {
super.performLayout();
Size newSize = child!.size;
if (oldSize == newSize) return;
oldSize = newSize;
WidgetsBinding.instance!.addPostFrameCallback((_) {
onChange(newSize);
});
}
}
class MeasureSize extends SingleChildRenderObjectWidget {
final ValueChanged<Size> onChange;
const MeasureSize({
required this.onChange,
required Widget child,
Key? key,
}) : super(key: key, child: child);
@override
RenderObject createRenderObject(BuildContext context) {
return MeasureSizeRenderObject(onChange);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment