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

Unable to compile this code #1

Open
pryshrm opened this issue Oct 26, 2021 · 12 comments
Open

Unable to compile this code #1

pryshrm opened this issue Oct 26, 2021 · 12 comments

Comments

@pryshrm
Copy link

pryshrm commented Oct 26, 2021

Getting errors like this:
The method 'when' isn't defined for the type 'AppSection'. (Documentation)
Any idea how to fix?

Seems like a great sample to learn flutter navigation. Is it possible to make this example without any references to addition libraries and features such as @freezed? It is just complicating the matter. Just a request.

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

Many compilations errors such as:
The name 'NavigationStackItemNotFound' isn't a type and can't be used in a redirected constructor.

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

Hi,
in the linked article I explain why using freezed is a great simplification, instead.
You are getting the errors because you didn't generate the code, I suspect. Please refer to Freezed docs

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

Yes, I am very new with flutter/dart and just trying to get the hang of the navigator stuff. No idea how to generate code or execute the build runner after opening this project in Android Studio. Freezed doc says, "To use Freezed, you will need your typical build_runner/code-generator setup."!

May be a parallel article that just keeps everything pure (no freezed/riverpod package) will be very helpful in understanding why freezed and riverpod are great. Again, just a humble suggestion.

But anyway, thanks for responding.

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

C:\temp\fluttertest\Muccy-flutter-navigation-2.0-article-example-master>flutter pub run build_runner build
Failed to build build_runner:build_runner:
/C:/flutter223/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:258:50: Error: The property 'displayString' is defined in multiple extensions for 'TargetKind' and neither is more specific.

  • 'TargetKind' is from 'package:meta/meta_meta.dart' ('/C:/flutter223/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart').
    Try using an explicit extension application of the wanted extension or hiding unwanted extensions from scope.
    var kindNames = kinds.map((kind) => kind.displayString).toList()
    ^^^^^^^^^^^^^
    /C:/flutter223/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:1950:14: Context: This is one of the extension members.
    String get displayString {
    ^^^^^^^^^^^^^
    /C:/flutter223/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/meta_meta.dart:91:14: Context: This is one of the extension members.
    String get displayString {
    ^^^^^^^^^^^^^
    /C:/flutter223/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/src/error/best_practices_verifier.dart:260:36: Error: The getter 'commaSeparatedWithOr' isn't defined for the class 'List'.
  • 'List' is from 'dart:core'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'commaSeparatedWithOr'.
    var validKinds = kindNames.commaSeparatedWithOr;
    ^^^^^^^^^^^^^^^^^^^^
    pub finished with exit code 1

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

I really would like to help you I don't use Windows nor Android Studio.

I only know that I execute dthose two commands on terminal and I was good to go on my machine:

flutter pub get
flutter pub run build_runner build

Maybe there as some incompatibilities, because Dart has upgraded a lot in the last months. Sadly I have no free time to check and correct those.

If you are interested on my take on freezed and immutability in general, you could read this

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

Yes, I understand. No problem. I am just posting it here, in case someone else comes along looking for the same stuff.

Finally, got the build runner to work after running: flutter pub upgrade

But it is now generating these errors in the code :

[WARNING] freezed:freezed on lib/ingredients/model.dart:
The class Ingredient was declared as abstract, but it is not need anymore.
Read here: https://github.com/rrousselGit/freezed/tree/master/packages/freezed#the-abstract-keyword

[SEVERE] freezed:freezed on lib/ingredients/model.dart:

The parameter id of Ingredient is non-nullable but is neither required nor marked with @default
package:new_navigation/ingredients/model.dart:8:22

8 │ @required String id,
│ ^^

[WARNING] freezed:freezed on lib/recipes/model.dart:
The class Recipe was declared as abstract, but it is not need anymore.
Read here: https://github.com/rrousselGit/freezed/tree/master/packages/freezed#the-abstract-keyword

[SEVERE] freezed:freezed on lib/recipes/model.dart:

The parameter id of Recipe is non-nullable but is neither required nor marked with @default
package:new_navigation/recipes/model.dart:8:22

8 │ @required String id,
│ ^^

[WARNING] freezed:freezed on lib/app_sections/model.dart:
The class AppSection was declared as abstract, but it is not need anymore.
Read here: https://github.com/rrousselGit/freezed/tree/master/packages/freezed#the-abstract-keyword

[WARNING] freezed:freezed on lib/routing/stack.dart:
The class NavigationStackItem was declared as abstract, but it is not need anymore.
Read here: https://github.com/rrousselGit/freezed/tree/master/packages/freezed#the-abstract-keyword

[SEVERE] freezed:freezed on lib/routing/stack.dart:

The parameter id of NavigationStackItem.appSection is non-nullable but is neither required nor marked with @default
package:new_navigation/routing/stack.dart:35:66

35 │ const factory NavigationStackItem.appSection({@required String id}) = NavigationStackItemAppSection;
│ ^^

[INFO] Running build completed, took 10.7s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 24ms

[SEVERE] Failed after 10.7s
pub finished with exit code 1

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

This codebase isn't null safe, but it seems it uses a freezed with null safety enabled. I'll take a quick look and I'll come back if fix is not too long to make

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

I managed to get the command "flutter pub run build_runner build" to run to completion after replacing @required with required in several files.

But now getting errors in several files because of null safety. For example, in routing/stack.dart says at line 27:
A value of type 'Null' can't be returned from the method 'pop' because it has a return type of 'NavigationStackItem'. (Documentation)

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

Yes. Same for me. It must be ported to null safety. Even downgrading dependencies didn't make the trick. (And sadly I have no time to make a migration now)

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

I strongly suggest you to read the article and to use pragmatic_navigation in a new project if you are learning Flutter

@pryshrm
Copy link
Author

pryshrm commented Oct 26, 2021

I managed to get rid of all compilation errors in the code. Mostly by replacing Key key with Key? key and other such similar null checks. (I know it will probably crash at runtime.)

However, when I try to run it, I am now getting errors like these from riverpod stuff:

C:/flutter223/.pub-cache/hosted/pub.dartlang.org/riverpod-0.12.4/lib/src/common.freezed.dart:121:4: Error: This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @nullable

I guess that the end of this rabbit hole for me!

@muccy
Copy link
Owner

muccy commented Oct 26, 2021

You cannot take shortcuts: you have to perform a migration — which is not complicated nor simple

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

2 participants