mirror of
https://github.com/mzelldev/autoscale_tabbarview.git
synced 2024-09-21 16:56:27 +00:00
This commit fixes two issues: - When the tabController.index was initial set to something > 0, the height for the children was not being calculated correctly. - When changing the device orientation (portrait/landscape) the height was not being updated.
38 lines
841 B
Dart
38 lines
841 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
|
|
class SizeDetectorWidget extends StatefulWidget {
|
|
final Widget child;
|
|
final ValueChanged<Size> onSizeDetect;
|
|
|
|
const SizeDetectorWidget({
|
|
Key? key,
|
|
required this.child,
|
|
required this.onSizeDetect,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_SizeDetectorWidgetState createState() => _SizeDetectorWidgetState();
|
|
}
|
|
|
|
class _SizeDetectorWidgetState extends State<SizeDetectorWidget> {
|
|
Size? _oldSize;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
SchedulerBinding.instance?.addPostFrameCallback((_) => _detectSize());
|
|
return widget.child;
|
|
}
|
|
|
|
void _detectSize() {
|
|
if (!mounted) {
|
|
return;
|
|
}
|
|
final size = context.size;
|
|
if (_oldSize != size) {
|
|
_oldSize = size;
|
|
widget.onSizeDetect(size!);
|
|
}
|
|
}
|
|
}
|