Protect details screen from bad tabIndex params
This commit is contained in:
parent
59af5d9e3e
commit
5fea5fc017
@ -21,7 +21,7 @@ class _WonderDetailsScreenState extends State<WonderDetailsScreen>
|
||||
late final _tabController = TabController(
|
||||
length: 4,
|
||||
vsync: this,
|
||||
initialIndex: widget.tabIndex,
|
||||
initialIndex: _clampIndex(widget.tabIndex),
|
||||
)..addListener(_handleTabChanged);
|
||||
AnimationController? _fade;
|
||||
|
||||
@ -31,7 +31,7 @@ class _WonderDetailsScreenState extends State<WonderDetailsScreen>
|
||||
@override
|
||||
void didUpdateWidget(covariant WonderDetailsScreen oldWidget) {
|
||||
if (oldWidget.tabIndex != widget.tabIndex) {
|
||||
_tabController.index = widget.tabIndex;
|
||||
_tabController.index = _clampIndex(widget.tabIndex);
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
@ -42,6 +42,8 @@ class _WonderDetailsScreenState extends State<WonderDetailsScreen>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
int _clampIndex(int index) => index.clamp(0, 3);
|
||||
|
||||
void _handleTabChanged() {
|
||||
_fade?.forward(from: 0);
|
||||
setState(() {});
|
||||
|
Loading…
x
Reference in New Issue
Block a user