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

Null Safety issue on the given example! #11545

Open
1 task done
kishan-dhankecha opened this issue Dec 26, 2024 · 4 comments
Open
1 task done

Null Safety issue on the given example! #11545

kishan-dhankecha opened this issue Dec 26, 2024 · 4 comments
Labels
e2-days Effort: < 5 days from.page-issue Reported in a reader-filed concern p2-medium Necessary but not urgent concern. Resolve when possible.

Comments

@kishan-dhankecha
Copy link

Page URL

https://docs.flutter.dev/cookbook/effects/shimmer-loading/

Page source

https://github.com/flutter/website/tree/main/src/content/cookbook/effects/shimmer-loading.md

Describe the problem

There is an issue with the code provided in the example below. When I copied the whole code from the interactive editor in the website and pasted it into my project to use the ShimmerLoading widget, I found that I get the classic Null check operator used on a null value error. See the issue in the below snippet.

// Collect ancestor shimmer information.
final shimmer = Shimmer.of(context)!; /// Error comes from this line
if (!shimmer.isSized) {
  // The ancestor Shimmer widget isn't laid
  // out yet. Return an empty box.
  return const SizedBox();
}

Expected fix

It should be changed to this,

// Collect ancestor shimmer info.
final shimmer = Shimmer.of(context);
if (shimmer == null || !shimmer.isSized) {
  // The ancestor Shimmer widget has not laid
  // itself out yet. Return an empty box.
  return const SizedBox();
}

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@kishan-dhankecha kishan-dhankecha added the from.page-issue Reported in a reader-filed concern label Dec 26, 2024
kishan-dhankecha added a commit to kishan-dhankecha/flutter-website that referenced this issue Dec 26, 2024
@sfshaza2
Copy link
Contributor

@kishan-dhankecha, what version of Flutter/Dart are you using? shimmer is defined as never being null. So, testing for null isn't necessary. The only thing that makes sense is that you are using an older version of Dart.

@sfshaza2 sfshaza2 added the act.wait-for-customer Needs response from customer label Jan 10, 2025
@kishan-dhankecha
Copy link
Author

Note that this issue of null check only happens when a user forgets to wrap the widget with Shimmer. In that case, context will not find the Shimmer on the upper side of the tree.

@github-actions github-actions bot removed the act.wait-for-customer Needs response from customer label Jan 10, 2025
@sfshaza2
Copy link
Contributor

@domesticmouse, can you weigh in on this?

@sfshaza2 sfshaza2 added p2-medium Necessary but not urgent concern. Resolve when possible. e2-days Effort: < 5 days labels Jan 15, 2025
@domesticmouse
Copy link
Contributor

Given this is an exception that is only thrown when the developer goofs, I don't see the need to make the suggested change. I'd prefer the code to break, given it is already broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2-days Effort: < 5 days from.page-issue Reported in a reader-filed concern p2-medium Necessary but not urgent concern. Resolve when possible.
Projects
None yet
Development

No branches or pull requests

3 participants