I want to achieve reflection in a cross-platform (iOS, Android) project using Flutter and the Reflectable package. To keep the binaries short, this package uses code generation.
However, following the tutorial/readme of this package, I am not able to generate the needed code, in this case the file main.reflectable.dart. While I have reached the point where things work without error, code generation concludes with the statement:
[INFO] Succeeded after 88ms with 0 outputs
In the following I try to show a reproducible path of what I did. For that I moved flutter to a different path and reinstalled it, but didn't reinstall the flutter plugin in IntelliJ IDEA.
How to reproduce / What I did?
I) Install Flutter as usual for Mac. On the command line:
cd ~/development
git clone -b beta https://github.com/flutter/flutter.git
export PATH=/Users/yourname/development/flutter/bin:$PATH
flutter doctor
II) Create a new Flutter project in IntelliJ IDEA
- Choose SDK path: /Users/yourname/development/flutter
- Choose project location: ~/gitroot/PlayGround/reflectable_test_2
- Add directory entry_point parallel to lib directory
- Add dart file main.dart inside directory entry_point
- Get the content for main.dart from the main.dart in https://github.com/dart-lang/reflectable (a lot will be shown red)
- Delete main.dart from lib directory (unchecked "safe delete" and "search in comments")
- Delete widet_test.dart in test directory
- Add "reflectable: any" to pubspec.yaml under dependencies
- In main.dart, click run and in the upcoming dialog set the entry point to /Users/yourname/gitroot/PlayGround/reflectable_test_2/entry_point/main.dart
When the dependencies are loaded, some of the red wiggles will go away, but not the one in "import 'main.reflectable.dart';", since this file does not exist yet.
III) Try to generate main.reflectable.dart with the builder on the command line:
cd /Users/yourname/gitroot/PlayGround/reflectable_test_2/
flutter packages pub run build_runner build entry_point
Note that instead of the last line, the tutorial only says
pub run build_runner build DIR
but the used line is indeed correct when used in a Flutter project. Following the readme/tutorial so far, I got the result:
Package "build_runner" is not an immediate dependency.
Cannot run executables in transitive dependencies.
pub finished with exit code 65
IV) In IntelliJ, add "build_runner: any" to dev_dependencies in pubspec.yaml. Run again on the command line (flutter packages pub run build_runner build entry_point). This results in the output:
[INFO] Generating build script...
[INFO] Generating build script completed, took 506ms
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 776ms
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 3ms
[INFO] Running build...
[INFO] Running build completed, took 7ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 69ms
[INFO] Succeeded after 88ms with 0 outputs
To summarise, no errors, but it didn't create the file main.reflectable.dart either (0 outputs). What can I do to fix this?