docs: Document WidgetSize widget

pull/203/head
Inex Code 2023-03-27 20:03:16 +03:00 committed by Gitea
parent f0f1e8cacc
commit 805f12b9e9
1 changed files with 18 additions and 1 deletions

View File

@ -1,14 +1,26 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.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 { class WidgetSize extends StatefulWidget {
/// Creates a helper widget that calls a callback when its size changes.
const WidgetSize({ const WidgetSize({
required this.onChange, required this.onChange,
required this.child, required this.child,
super.key, super.key,
}); });
/// The child widget, the size of which is to be measured.
final Widget child; final Widget child;
final Function onChange;
/// The callback to be called when the size of the widget changes.
final Function(Size) onChange;
@override @override
State<WidgetSize> createState() => _WidgetSizeState(); State<WidgetSize> createState() => _WidgetSizeState();
@ -34,6 +46,11 @@ class _WidgetSizeState extends State<WidgetSize> {
} }
final newSize = context.size; final newSize = context.size;
if (newSize == null) {
return;
}
if (oldSize == newSize) { if (oldSize == newSize) {
return; return;
} }