Created
January 25, 2022 15:03
-
-
Save marcoleonardini/1de72e05bad7f869e9cc91206cd63ead to your computer and use it in GitHub Desktop.
MeasureSize.dart
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
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