mirror of
https://github.com/mzelldev/autoscale_tabbarview.git
synced 2024-09-21 16:56:27 +00:00
Fix for non-zero initial tab index not sizing children correctly and device orientation change support
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.
This commit is contained in:
parent
adfe89918f
commit
c9d31a2b79
@ -18,14 +18,9 @@ class SizeDetectorWidget extends StatefulWidget {
|
||||
class _SizeDetectorWidgetState extends State<SizeDetectorWidget> {
|
||||
Size? _oldSize;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SchedulerBinding.instance?.addPostFrameCallback((_) => _detectSize());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SchedulerBinding.instance?.addPostFrameCallback((_) => _detectSize());
|
||||
return widget.child;
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,7 @@ class SizedPageView extends StatefulWidget {
|
||||
_SizedPageViewState createState() => _SizedPageViewState();
|
||||
}
|
||||
|
||||
class _SizedPageViewState extends State<SizedPageView>
|
||||
with TickerProviderStateMixin {
|
||||
class _SizedPageViewState extends State<SizedPageView> with TickerProviderStateMixin {
|
||||
late List<double> _heights;
|
||||
int _currentIndex = 0;
|
||||
|
||||
@ -32,14 +31,13 @@ class _SizedPageViewState extends State<SizedPageView>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_heights = List.generate(widget.children.length, (index) => 0.0);
|
||||
final int initialIndex = widget.pageController.initialPage;
|
||||
_setCurrentIndex(initialIndex);
|
||||
|
||||
widget.pageController.addListener(() {
|
||||
final _newIndex = widget.pageController.page?.round();
|
||||
if (_currentIndex != _newIndex) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
setState(() => _currentIndex = _newIndex!);
|
||||
final int? newIndex = widget.pageController.page?.round();
|
||||
if (newIndex != null) {
|
||||
_setCurrentIndex(newIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -79,4 +77,13 @@ class _SizedPageViewState extends State<SizedPageView>
|
||||
widget.pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setCurrentIndex(int newIndex) {
|
||||
if (_currentIndex != newIndex) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
setState(() => _currentIndex = newIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user