From 805f12b9e9c5711c2b49730d632acf402ebc54f7 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Mon, 27 Mar 2023 20:03:16 +0300 Subject: [PATCH] docs: Document WidgetSize widget --- lib/ui/helpers/widget_size.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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; }