mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-09 18:33:11 +00:00
45 lines
926 B
Dart
45 lines
926 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
|
|
class WidgetSize extends StatefulWidget {
|
|
const WidgetSize({
|
|
required this.onChange,
|
|
required this.child,
|
|
super.key,
|
|
});
|
|
final Widget child;
|
|
final Function onChange;
|
|
|
|
@override
|
|
State<WidgetSize> createState() => _WidgetSizeState();
|
|
}
|
|
|
|
class _WidgetSizeState extends State<WidgetSize> {
|
|
@override
|
|
Widget build(final BuildContext context) {
|
|
SchedulerBinding.instance.addPostFrameCallback(postFrameCallback);
|
|
return Container(
|
|
key: widgetKey,
|
|
child: widget.child,
|
|
);
|
|
}
|
|
|
|
var widgetKey = GlobalKey();
|
|
Size? oldSize;
|
|
|
|
void postFrameCallback(final _) {
|
|
final context = widgetKey.currentContext;
|
|
if (context == null) {
|
|
return;
|
|
}
|
|
|
|
final newSize = context.size;
|
|
if (oldSize == newSize) {
|
|
return;
|
|
}
|
|
|
|
oldSize = newSize;
|
|
widget.onChange(newSize);
|
|
}
|
|
}
|