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

refactor(weather_example): use named extension #4305

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

gcugnet
Copy link
Contributor

@gcugnet gcugnet commented Dec 28, 2024

Name the double extension to make it available through imports in other files (i.e. in weather_cubit_test.dart).

Status

READY

Breaking Changes

NO

Description

I’m following the flutter_weather example, and I encountered an error in the weather_cubit_test.dart file:

The method 'toFahrenheit' isn't defined for the type 'double'.
Try correcting the name to the name of an existing method, or defining a method named 'toFahrenheit'.dart[undefined_method](https://dart.dev/diagnostics/undefined_method)
Type: InvalidType

However exports and imports are correct (I double-checked them).

Just naming the extension fixes this error.

EDIT: I realized a bit later that the extension was added again in the test file. So the current code is fully functional and my PR is less necessary.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • [] 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@gcugnet gcugnet requested a review from felangel as a code owner December 28, 2024 14:08
@gcugnet
Copy link
Contributor Author

gcugnet commented Dec 28, 2024

Sorry, I haven’t seen the extension declaration on test file.

extension on double {
  double toFahrenheit() => (this * 9 / 5) + 32;
  double toCelsius() => (this - 32) * 5 / 9;
}

I’ll remove it in a new commit, to make it cleaner.
Don’t know if my PR really enhance the example code, and it’s not a fix anymore but a refactor.

Name the extension on `double` to make it available  through imports in
other files without the need to redefine it (i.e. in weather_cubit_test.dart).
@gcugnet gcugnet changed the title fix: use named extension refactor(weather_example): use named extension Dec 28, 2024
Copy link
Owner

@felangel felangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for the cleanup! 💙

@felangel felangel added example Example application refactor Refactor an existing implementation labels Jan 1, 2025
@felangel felangel merged commit 117d2ec into felangel:master Jan 1, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Example application refactor Refactor an existing implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants