Open popeyelau opened 4 years ago
class MeasureSizeRenderObject extends RenderProxyBox {
MeasureSizeRenderObject(this.onChange);
void Function(Size size) onChange;
Size _prevSize;
@override
void performLayout() {
super.performLayout();
Size newSize = child.size;
if (_prevSize == newSize) return;
_prevSize = newSize;
WidgetsBinding.instance.addPostFrameCallback((_) => onChange(newSize));
}
}
class MeasurableWidget extends SingleChildRenderObjectWidget {
const MeasurableWidget({Key key, @required this.onChange, @required Widget child}) : super(key: key, child: child);
final void Function(Size size) onChange;
@override
RenderObject createRenderObject(BuildContext context) => MeasureSizeRenderObject(onChange);
}
Flutter Tricks: Widget Size & Position