Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve null safety in animated_tab_visibility.dart #1082

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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