mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
docs: Document WidgetSize widget
This commit is contained in:
parent
f0f1e8cacc
commit
805f12b9e9
|
@ -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<WidgetSize> createState() => _WidgetSizeState();
|
||||
|
@ -34,6 +46,11 @@ class _WidgetSizeState extends State<WidgetSize> {
|
|||
}
|
||||
|
||||
final newSize = context.size;
|
||||
|
||||
if (newSize == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldSize == newSize) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue