diff --git a/lib/ui/helpers/widget_size.dart b/lib/ui/helpers/widget_size.dart index 2b9eb962..bbd1529f 100644 --- a/lib/ui/helpers/widget_size.dart +++ b/lib/ui/helpers/widget_size.dart @@ -1,14 +1,26 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; +/// A helper widget that calls a callback when its size changes. +/// +/// This is useful when you want to know the size of a widget, and use it in +/// another leaf of the tree. +/// +/// The [onChange] callback is called after the widget is rendered, and the +/// size of the widget is different from the previous render. class WidgetSize extends StatefulWidget { + /// Creates a helper widget that calls a callback when its size changes. const WidgetSize({ required this.onChange, required this.child, super.key, }); + + /// The child widget, the size of which is to be measured. final Widget child; - final Function onChange; + + /// The callback to be called when the size of the widget changes. + final Function(Size) onChange; @override State createState() => _WidgetSizeState(); @@ -34,6 +46,11 @@ class _WidgetSizeState extends State { } final newSize = context.size; + + if (newSize == null) { + return; + } + if (oldSize == newSize) { return; }