Flutter Reflection with Reflectable: working example needed
Maybe the only missing bit is to do
flutter packages pub run build_runner build entry_point/main.dart
or add a build.yaml
file along the lines of
targets:
test_reflectable:
builders:
reflectable:
generate_for:
- entry_point/main.dart
Edit: Here's an example repo which may serve as a very simplistic starting point for reflectable in Flutter.
Edit 2: There is a whitelist of locations where pub
supports entry points ("Dart programs"), and entry_point
is not on that list. Try using a directory which is present in the whitelist.
First, make sure you have these both packages added in pubspec.yaml
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: any
built_value_generator: any
if only build_runner is added. it won't be going to generate anything and end up with success.
also, check your main.dart
//reflectable impoort statement should be like this
import 'main.reflectable.dart' show initializeReflectable;
void main(){
// initialize Reflectable in main
initializeReflectable();
runApp(MyApp());
}
Now try to build with the command
flutter packages pub run build_runner build DIR
if it's working then you are damn lucky.
Now let's add a build.yaml file manually (same directory of pubspec.yaml)
targets:
$default:
builders:
reflectable:
generate_for:
- lib/main.dart
Now try command
flutter packages pub run build_runner build DIR