Skip to content

Commit

Permalink
Improve null safety in animated_tab_visibility.dart (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreichardt authored Sep 24, 2023
1 parent 5c6b710 commit 093f3ed
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/lib/homework/shared/animated_tab_visibility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,27 @@ class AnimatedTabVisibility extends StatefulWidget {
}

class _AnimatedTabVisibilityState extends State<AnimatedTabVisibility> {
bool? isVisible;
TabController? tabController;
late bool isVisible;
late TabController tabController;

/// [true] if the [build] function has not been run yet.
late bool isFirstBuild;

@override
void initState() {
super.initState();
isVisible = false;
isFirstBuild = true;
tabController = widget.tabController;
super.initState();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
tabController = widget.tabController ?? DefaultTabController.of(context);
}

bool _shouldChildBeVisible() {
return widget.visibleInTabIndicies.contains(tabController!.index);
return widget.visibleInTabIndicies.contains(tabController.index);
}

void _animateVisibilityIfNecessary() {
Expand All @@ -117,8 +122,7 @@ class _AnimatedTabVisibilityState extends State<AnimatedTabVisibility> {

@override
Widget build(BuildContext context) {
tabController ??= DefaultTabController.of(context);
tabController!.addListener(() {
tabController.addListener(() {
_animateVisibilityIfNecessary();
});

Expand All @@ -132,7 +136,7 @@ class _AnimatedTabVisibilityState extends State<AnimatedTabVisibility> {
}

return AnimatedVisibility(
visible: isVisible!,
visible: isVisible,
maintainState: widget.maintainState,
duration: const Duration(milliseconds: 300),
curve: widget.curve,
Expand Down

0 comments on commit 093f3ed

Please sign in to comment.