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(
|
late final _tabController = TabController(
|
||||||
length: 4,
|
length: 4,
|
||||||
vsync: this,
|
vsync: this,
|
||||||
initialIndex: widget.tabIndex,
|
initialIndex: _clampIndex(widget.tabIndex),
|
||||||
)..addListener(_handleTabChanged);
|
)..addListener(_handleTabChanged);
|
||||||
AnimationController? _fade;
|
AnimationController? _fade;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ class _WonderDetailsScreenState extends State<WonderDetailsScreen>
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant WonderDetailsScreen oldWidget) {
|
void didUpdateWidget(covariant WonderDetailsScreen oldWidget) {
|
||||||
if (oldWidget.tabIndex != widget.tabIndex) {
|
if (oldWidget.tabIndex != widget.tabIndex) {
|
||||||
_tabController.index = widget.tabIndex;
|
_tabController.index = _clampIndex(widget.tabIndex);
|
||||||
}
|
}
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
@ -42,6 +42,8 @@ class _WonderDetailsScreenState extends State<WonderDetailsScreen>
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _clampIndex(int index) => index.clamp(0, 3);
|
||||||
|
|
||||||
void _handleTabChanged() {
|
void _handleTabChanged() {
|
||||||
_fade?.forward(from: 0);
|
_fade?.forward(from: 0);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user