muccy / flutter-navigation-2.0-article-example

11 stars 6 forks source link

Unable to compile this code #1

Open pryshrm opened 3 years ago

pryshrm commented 3 years ago

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 commented 3 years ago

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

muccy commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

muccy commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

pryshrm commented 3 years ago

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 commented 3 years ago

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