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

Error in super class #12

Open
vbhsnh opened this issue Oct 3, 2021 · 7 comments
Open

Error in super class #12

vbhsnh opened this issue Oct 3, 2021 · 7 comments

Comments

@vbhsnh
Copy link

vbhsnh commented Oct 3, 2021

is:issue is:open S1E4 video time 1:33...getting error when applying super class.how to remove that error

@romanejaquez
Copy link
Owner

hi vbhsnh did you migrate your app to Null Safety? Please use the migration tool. I started the project without null safety, and then I migrated to it - apologies if that caused you an issue, but the benefits are greater by being on Null Safety.
Here's the link
https://dart.dev/null-safety/migration-guide#migration-tool

Since Subcategory extends Category and Category is null safe, then both your Category and Subcategory must be null-safe.

Let me know if you are encountering other issues after migrating to Null Safety, so I can help you unblock. Thanks for your feedback and your support - i'm here to help!!!

@vbhsnh
Copy link
Author

vbhsnh commented Oct 3, 2021

Hi romanejaquez really appreciate your work, loved your project. I am sending my sample code with you of "Catagory" and "SubCategory" file. Request you to kindly help me fixing the same with some sample code.
category
subcategory

Error in the console :
The named parameter 'subCategories' is required, but there's no corresponding argument.
Try adding the required argument.

@romanejaquez
Copy link
Owner

Your issue is that you're setting the values of the Category class as required and you're not passing the subCategories (it is required). If you still want to keep it this way, then pass some default value to the subcategories constructor parameter, such as (subCategories: []) like the code below:

class SubCategory extends Category { SubCategory({ required String name, required String imgName }): super(imgName: imgName, name: name, subCategories: []); }
I still recommend you switching to null safety whenever possible. Let me know if that works - thank you!

@vbhsnh
Copy link
Author

vbhsnh commented Oct 4, 2021

Thanks romanejaquez for your help. "Super" issue got fixed thanks allot for that. Now I have issue in "SelectedCategoryPage" when trying pass item name below error is showing in code. If i mention required modifier i get error in CategoryListPage from where navigation is happening. As suggested by you i will definitely go through null safety.

image

Console screenshot:
image

I am new to flutter so troubling you more.

@ddiawara
Copy link

ddiawara commented Oct 20, 2021

Hello , thanks for this course its very very useful. i have the same error

Performing hot reload...
Syncing files to device iPhone 11 Pro...
lib/pages/selectedcategorypage.dart:50:65: Error: The argument type 'Category' can't be assigned to the parameter type 'SubCategory'.
 - 'Category' is from 'package:orilla_fresca/models/category.dart' ('lib/models/category.dart').
 - 'SubCategory' is from 'package:orilla_fresca/models/subcategory.dart' ('lib/models/subcategory.dart').
                                  selectedCategory.subCategories[index],
                                                                ^

image

@romanejaquez
Copy link
Owner

Make sure you're casting the selectedCategory.subCategories[index] into a SubCategory object, as in:
selectedCategory.subCategories[index] as SubCategory.
Did you also upgrade the project to null safety?

@ddiawara
Copy link

Yeah its probably works
image

this news configuration

image

its works . thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants