I am trying to use the freezed package inside a plain dart package - NO flutter!
I am following the instructions at https://pub.dev/packages/freezed#run-the-generator .
My pubspec.yaml:
...
version: 1.0.0
# homepage: https://www.example.com
environment:
sdk: '>=2.17.5 <3.0.0'
dependencies:
bloc: ^8.0.3
freezed_annotation: ^2.1.0
dev_dependencies:
build_runner: ^2.2.0
freezed: ^2.1.0+1
lints: ^2.0.0
mockito: ^5.3.0
test: ^1.16.0
My example class:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'person.freezed.dart';
@freezed
class Person with _$Person {
const factory Person({
required String firstName,
required String lastName,
}) = _Person;
}
But when I call
dart run build_runner build
I get the following error:
Unhandled exception:
Could not load "file:///{my_project_path}/run": FileSystemException: Cannot open file, path = '{my_project_path}//run' (OS Error: No such file or directory, errno = 2)
null
The same result when I use the run build command from the freezed vs code extension:
Running `dart run build_runner build --delete-conflicting-outputs`
Current working folder: `{my_project_path}`
Unhandled exception:
Could not load "file:///{my_project_path}/run": FileSystemException: Cannot open file, path = '{my_project_path}/run' (OS Error: No such file or directory, errno = 2)
null
So I created a flutter package instead with the same dependencies and class and when I now call
flutter pub run build_runner build
it works!
My dart version:
% dart --version
Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"
OS: macOS Big Sur Version 11.6.7
And yes, I googled the problem extensively, but did not find anything related!
Any suggestions? Anyone? Please!
Edit:
Seems that my standalone dart installation is seriously broken. I can call dart my_dart_program.dart
and it works. But if I try to call any dart commands like create, run, ... it looks for a file with this name in the current directory.
I changed my path settings to always use the dart version shipped with flutter and everything works just fine.
So I don't use the latest stable of dart for my dart only code, but I always know that everything is compatible with the current flutter version.