Issues with build_runner after adding Hive Field - flutter

I have added addtional Hive Fields to a Hive type before as needed. I have then deleted .g.dart file and regenerated it with no problems.
This time after added a new Hive Field I have this error and I am not able to understand why
[INFO] Generating build script...
[INFO] Generating build script completed, took 424ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 73ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 968ms
[INFO] Running build...
[INFO] Running build completed, took 21ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 55ms
[SEVERE] hive_generator:hive_generator on lib/main.dart (cached):
This builder requires Dart inputs without syntax errors.
However, package:flutter_app_hive/main.dart (or an existing part) contains the following errors.
main.dart:33:3: Expected to find ';'.
main.dart:33:3: Expected an identifier.
Try fixing the errors and re-running the build.
[SEVERE] Failed after 92ms
pub finished with exit code 1
I have tried flutter clean, flutter pub outdated, pub get, etc... and I keep getting this error.
In my pubspec.yaml I have, this worked just fine until I have added the latest Hive Field.
dependencies:
flutter:
sdk: flutter
hive: ^2.0.2
hive_flutter: ^1.0.0
path_provider: ^2.0.1
curved_navigation_bar: ^0.3.7
video_player: ^1.0.1
font_awesome_flutter: ^8.5.0
badges: ^1.2.0
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.0.1
hive_generator: ^1.1.0
I found an old post about downgrading analyzer, but this then causes problems with the versions I am using.
In the main.dart there isn't an error on line 33:3. it should not have ; as suggested. Again this worked fine before, so I am not sure why it is an issue now. I also commented out the code here and I still get the same error message even with nothing at line 33:3
If I remove the field I added I still get the same error. If I restore the .g.dart file from a backup I can run the app as before.
Any input on this would be appreciated as it's very confusing
Update:
So I tried deleting the model file and completely recreating it and then generating the .g.dart. I get this:
[INFO] Generating build script...
[INFO] Generating build script completed, took 485ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 83ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 1.1s
[INFO] Running build...
[INFO] Running build completed, took 23ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 66ms
[INFO] Succeeded after 102ms with 0 outputs (0 actions)
I have tried keeping the file as it was, added a new Hive Field to a previous Hive Type and adding a Hive type and I get nothing generated.
I haven't changed the existing Hive fields, I know that causes issues. New Hive Fields and Hive Types were given the next number that hadn't been used before.

So I didn't fix the issue, but for a work around I created a new flutter project, copied my code over except any generated files. Then I was able to generate new type adapters after adding new Hive fields and hive types. Maybe something got corrupted in my previous project. Not sure why flutter clean wouldn't fix this. But maybe this will help someone stuck on the same issue.

Set source_gen: 1.0.3 in pubspec.yaml helped in my case.

Related

Error using source generator from a source generator package

I am writing a dart source generator that is using json_serializable for some of it models. Initially the source generation was working fine for some time but now when I run dart run build_runner build --delete-conflicting-outputs I am getting error:
[INFO] Generating build script completed, took 410ms [INFO]
Reading cached asset graph completed, took 62ms [INFO] Checking
for updates since last build completed, took 492ms [WARNING]
Invalidating asset graph due to build script update! [INFO]
Cleaning up outputs from previous builds. completed, took 4ms
[INFO] Generating build script completed, took 79ms [WARNING]
Invalidated precompiled build script due to missing asset graph.
[WARNING] lib/settings/config.dart:3:6: Error: Error when reading
'lib/settings/config.g.dart': No such file or directory part
'config.g.dart';
^ lib/settings/config.dart:3:6: Error: Can't use 'lib/settings/config.g.dart' as a part, because it has no 'part of'
declaration. part 'config.g.dart';
^ [INFO] Precompiling build script... completed, took 785ms [SEVERE] Failed to precompile build script
.dart_tool/build/entrypoint/build.dart. This is likely caused by a
misconfigured builder definition.
Here is the dependencies for my package:
dependencies:
path: ^1.8.1
yaml: ^3.1.0
dotenv: ^3.0.0
recase: ^4.0.0
json_annotation: ^4.4.0
code_builder: ^4.1.0
dart_style: ^2.2.1
dev_dependencies:
lints: ^1.0.0
test: ^1.20.1
build_runner: ^2.1.7
json_serializable: ^6.1.3
And build.yaml looks like this:
builders:
map_gen:
import: "package:map_gen/map_gen.dart"
builder_factories: [ "build" ]
build_extensions: { "$lib$": [ ".map.dart" ] }
auto_apply: dependents
build_to: source
I haven't been able to figure out why this is happening or is there any limitation on using source generator for a package that provides its own generators. Is there any way I can resolve this?
Edit
I am using vscode, but I have tried building from terminal and also getting the same error. Even after running flutter clean | dart pub get | dart run build_runner build --delete-conflicting-outputs same error persists.
Current workaround
Currently I am manually creating .g.dart file and adding the part of statement manually, running build_runner after that results in successful source generation. However if I run build_runner again after I have linked generated methods to my code, the .g.dart files are deleted and again I am facing with the same error. I have to repeat this process every time I want source generation.
I faced the exact same issue and got help from the creator of Drift in Dart Build's Gitter chat room. Quoting the solution here:
you can simply create an empty <project_directory>.build.yaml file in your package's directory. This special build.yaml file will only be used when a build is started from the directory of your package. To the build system, it will look like your builders simply don't exist (and thus it won't attempt to compile them). When you run a build from other packages that depend on your builder package, the <project_directory>.build.yaml file is ignored and all your builders are there.
You can refer to how Drift do it here.

ObjectBox does not build after Dart SDK update

I was using ObjectBox without many problems for a while during a development with Flutter, but now the build_runner fails:
The closest change I have made is a Flutter upgrade yesterday to Flutter 2.5.3 along with Dart 2.14.4.
ObjectBox dependencies in pubspec.yaml are:
objectbox: ^1.2.0
objectbox_flutter_libs: any
Now, although the objectbox-model.json file is there, the objectbox.g.dart file is missing and does not get regenerated.
I then tried to run the two example projects give in the official OB documents, but those failed too with similar results (they ran OK before this).
The complete build stack is as follows:'
Microsoft Windows [Version 10.0.19042.1237] (c) Microsoft Corporation. All rights reserved.
D:\learnedfriend>flutter pub run build_runner watch --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 462ms
[INFO] Setting up file watchers...
[INFO] Setting up file watchers completed, took 11ms
[INFO] Waiting for all file watchers to be ready...
[INFO] Waiting for all file watchers to be ready completed, took 358ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 126ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 6.3s
[INFO] Running build...
[INFO] Running build completed, took 14ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 54ms
[SEVERE] objectbox_generator:generator on lib/$lib$ (cached):
Bad state: lastRelationId 4:6834778133563033891 does not match any standalone relation
[SEVERE] Failed after 85ms
I have found a solution to this problem and am posting it for the benefit of whoever encounters the same issue in future.
You should manually delete the objectbox-model.json file and objectbox.g.dart (if it still exists) and run the command "flutter pub run build_runner watch --delete-conflicting-outputs" at the project folder (without quotes, of course).
Also, it has to be mentioned that, as at the time of writing this post, if ObjectBox is a contemplated choice for your persistence, please be wary that (although it is an excellent package), support for a problem if you get stuck is very low to nil, in stackoverflow. I have not seen more than 2 or 3 contributors and if your question escapes their attention, you are pretty much on your own!

analyzer require 'non-nullable' language feature to be enabled

I did a mistake by migrating to null-safety then every thing become error, after fixing a lot of errors, I still get an error and the error is :
[INFO] Generating build script...
[INFO] Generating build script completed, took 452ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 131ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 791ms
[INFO] Running build...
[INFO] Running build completed, took 30ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 79ms
[SEVERE] json_serializable:json_serializable on lib/injection.config.dart (cached):
This builder requires Dart inputs without syntax errors.
However, package:invoice_app/injection.config.dart (or an existing part) contains the following errors.
injection.config.dart:18:48: This requires the 'non-nullable' language feature to be enabled.
injection.config.dart:18:12: This requires the 'non-nullable' language feature to be enabled.
Try fixing the errors and re-running the build.
[SEVERE] Failed after 123ms
pub finished with exit code 1
it's look like injectable generator have some mix up with the new version of dart that is why when I generate new injection.config.dart file then it gave this error
injection.config.dart:18:12: This requires the 'non-nullable' language feature to be enabled.
so if you want to fix it just open the file then then remove the ? mark like from this
_i1.GetIt $initGetIt(_i1.GetIt get,
{String? environment, _i2.EnvironmentFilter? environmentFilter}) {
final gh = _i2.GetItHelper(get, environment, environmentFilter);
return get;
}
to this
_i1.GetIt $initGetIt(_i1.GetIt get,
{String environment, _i2.EnvironmentFilter environmentFilter}) {
final gh = _i2.GetItHelper(get, environment, environmentFilter);
return get;
}
I know it's not a solution but it works until when I will migrate to non-nullable, I will use this.

flutter: Can't create moor_database.g.dart file

I am trying to learn moor_flutter so i added some dependencies into pupspec.yaml:
dependencies:
flutter:
sdk: flutter
moor_flutter: ^2.1.1
provider: ^4.0.4
flutter_slidable: ^0.5.4
path_provider: ^1.6.5
path: ^1.6.4
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
moor_generator: ^2.4.0
build_runner: ^1.8.1
flutter_test:
sdk: flutter
After installing these dependencies I create a table class inside lib -> data -> moor_database.dart file:
import 'package:moor_flutter/moor_flutter.dart';
part 'moor_database.g.dart';
class Tasks extends Table {
IntColumn get id =>
integer().autoIncrement().call();
TextColumn get name => text().withLength(min: 1, max: 50)();
DateTimeColumn get dueDate => dateTime().nullable()();
BoolColumn get completed => boolean().withDefault(Constant(false))();
}
#UseMoor(tables: [Tasks])
class AppDatabase extends _$AppDatabase {
AppDatabase()
: super(FlutterQueryExecutor.inDatabaseFolder(
path: 'db.sqlite', logStatements: true));
#override
int get schemaVersion => 1;
}
I want to generate dart code by :
flutter packages pub run build_runner watch
But i got this error:
$ flutter packages pub run build_runner watch
[INFO] Generating build script...
[INFO] Generating build script completed, took 349ms
[INFO] Setting up file watchers...
[INFO] Setting up file watchers completed, took 12ms
[INFO] Waiting for all file watchers to be ready...
[INFO] Waiting for all file watchers to be ready completed, took 165ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 68ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 889ms
[INFO] Running build...
[INFO] 1.6s elapsed, 0/1 actions completed.
[INFO] 3.4s elapsed, 0/1 actions completed.
[SEVERE] moor_generator:moor_generator on lib/data/moor_database.dart:
Error running MoorGenerator
NoSuchMethodError: The getter 'typeConverter' was called on null.
Receiver: null
Tried calling: typeConverter
[SEVERE] moor_generator:moor_generator on lib/data/moor_database.dart:
Error running DaoGenerator
NoSuchMethodError: The getter 'typeConverter' was called on null.
Receiver: null
Tried calling: typeConverter
[INFO] Running build completed, took 3.7s
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 50ms
[SEVERE] Failed after 3.7s
After googleing i found this solution :
but after running flutter packages pub run build_runner build --delete-conflicting-outputs i got this error:
flutter packages pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 350ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 79ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 896ms
[INFO] Running build...
[INFO] Running build completed, took 11ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 47ms
[SEVERE] moor_generator:moor_generator on lib/data/moor_database.dart (cached):
Error running MoorGenerator
NoSuchMethodError: The getter 'typeConverter' was called on null.
Receiver: null
Tried calling: typeConverter
[SEVERE] moor_generator:moor_generator on lib/data/moor_database.dart (cached):
Error running DaoGenerator
NoSuchMethodError: The getter 'typeConverter' was called on null.
Receiver: null
Tried calling: typeConverter
[SEVERE] Failed after 71ms
pub finished with exit code 1
I asked a question in it's official repo git and i got this answer :
It works if you replace this with integer().autoIncrement()(). The generator should emit a more helpful error message though, I'll take a look at why that didn't happen here.
I chnaged:
IntColumn get id =>integer().autoIncrement().call();
to :
IntColumn get id =>integer().autoIncrement()();
my problem gone.

AngularDart - stagehand web-angular material_ripple.scss error

Following this
And using cli
stagehand web-angular
pub get
webdev serve
Output:
[INFO] Setting up file watchers completed, took 25ms
[INFO] Waiting for all file watchers to be ready completed, took 201ms
[INFO] Building new asset graph completed, took 1.2s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[SEVERE] angular_components|scss_builder on package:angular_components/material_ripple/material_ripple.scss:
Error: Can't find stylesheet to import.
#import 'const/global',
^^^^^^^^^^^^^^
/private/var/folders/3p/8z23nlbs20qf291vlhjy1l0h0000gn/T/scratch_spaceuuJ2f0/packages/angular_components/css/material/_material.scss 19:9 #import
/private/var/folders/3p/8z23nlbs20qf291vlhjy1l0h0000gn/T/scratch_spaceuuJ2f0/packages/angular_components/material_ripple/material_ripple.scss 5:9 root stylesheet
[SEVERE] angular_components|scss_builder on package:angular_components/material_slider/material_slider.scss:
And the list goes on with a lot more
Do you know how to fix this?
This is a known issue. A work around is to add the following dependency override to your project's pubspec.yaml:
dependency_overrides:
sass: 1.3.2