I have a model like so:
import 'package:uuid/uuid.dart';
import 'package:hive/hive.dart';
part 'config_item.g.dart';
#HiveType()
class ConfigItem {
#HiveField(0)
String _id; // this can be a uuid or a MongoDB ObjectID
#HiveField(1)
final String deviceName;
....
}
I like to generate the Adapter file but it does not want to do it! When I call flutter packages pub run build_runner build --delete-conflicting-outputs I get the following output:
flutter packages pub run build_runner build --delete-conflicting-outputs main ✭ ✈
[INFO] Generating build script...
[INFO] Generating build script completed, took 399ms
[SEVERE] Nothing can be built, yet a build was requested.
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 45ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 399ms
[INFO] Running build...
[INFO] Running build completed, took 3ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 35ms
[INFO] Succeeded after 53ms with 0 outputs (0 actions)
In my pubspec.yaml I have:
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
bottom_navy_bar: ^6.0.0
get_it: ^7.2.0
get_it_mixin: ^3.1.3
servicestack: ^2.0.0
font_awesome_flutter: ^9.1.0
hive: ^2.0.4
hive_flutter: ^1.1.0
path_provider: ^2.0.3
uuid: ^3.0.4
dev_dependencies:
flutter_test:
sdk: flutter
build_runner:
I tried all sort of things like
Delete .dart_tool folder
Adding *.g.dart to .gitignore
flutter clean
and a lot more I found when searching the net.
But nothing helps! Any idea what is missing?
I am using the latest (stable) versions of flutter, dart SDK and AndroidStudio.
Run this command :
flutter packages pub run build_runner build
But before that, you will have to import the generator.
Example : If your file name is project_database.dart, then in that file :
Import,
import 'package:hive/hive.dart';
part 'project_database.g.dart'; //this will show an error initially but if
// you run the above command, it will generate the generator file
I faced the same issue but I was missing hive_generator: ^1.1.1. I didn't find it in the original Docs.
Special thanks to #Denny Mueller's comment
try this,
flutter packages pub run build_runner watch --use-polling-watcher --delete-conflicting-outputs
i had same problem. i solved by saving my changes in pubspec.yaml.
just press ctrl + s in pubspec.yaml then run flutter packages pub run build_runner build again.
pub run build_runner build
after got the part .save it and the error will gone
Also add hive_generator in ur dev_dependecies.
hive_generator package can automatically generate TypeAdapters for almost any class.
If you have any other problem
refer here
Give TypeId for #HiveType.
In your Case :
import 'package:uuid/uuid.dart';
import 'package:hive/hive.dart';
part 'config_item.g.dart';
#HiveType(typeId: 0)
class ConfigItem {
#HiveField(0)
String _id; // this can be a uuid or a MongoDB ObjectID
#HiveField(1)
final String deviceName;
....
}
flutter packages pub run build_runner build --delete-conflicting-outputs
Don't forget to add hive_generator at the dev_dependencies. Here's the link
https://pub.dev/packages/hive_generator
Related
build failed after flutter upgrade.
$ flutter pub run build_runner build
[INFO] Generating build script completed, took 331ms
[WARNING] ../../.pub-cache/hosted/pub.dev/floor_generator-1.4.1/lib/misc/type_utils.dart:25:26: Error: The getter 'element' isn't defined for the class 'DartType'.
- 'DartType' is from 'package:analyzer/dart/element/type.dart' ('../../.pub-cache/hosted/pub.dev/analyzer-5.0.0/lib/dart/element/type.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'element'.
bool get isEnumType => element is EnumElement;
how to fix it ?
form pubspec.yaml:
floor_generator: ^1.4.1
build_runner: ^2.1.2
Make sure to run flutter pub get after your flutter upgrade. Then flutter pub cache repair.
I fixed this error by adding a line to pubspec.yaml
dependency_overrides:
analyzer: ^5.4.0
I am migrating my flutter project to 3.3.0 and i am calling API with retrofit which was working fine, after upgrading all packages i delete .g.dart file and run the following command to rebuild the .g.dart file
flutter pub run build_runner build it thrown the following error.
Error: No named parameter with the name 'autoCastResponse'.
autoCastResponse: annotation?.peek('autoCastResponse')?.boolValue,
^^^^^^^^^^^^^^^^
/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pub-cache/hosted/pub.dartlang.org/retrofit-3.3.0/lib/http.dart:66:9: Context: Found this candidate, but th
e arguments don't match.
const RestApi({
^^^^^^^
/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pub-cache/hosted/pub.dartlang.org/retrofit_generator-4.1.2/lib/src/generator.dart:494:27: Error: The getter 'autoCastResponse' isn't defined for the class 'RestApi'.
- 'RestApi' is from 'package:retrofit/http.dart' ('/E:/ahmad/Android/Android%20Bundle%20Setup/flutter/.pubcache/hosted/pub.dartlang.org/retrofit-3.3.0/lib/http.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'autoCastResponse'.
(clientAnnotation.autoCastResponse ?? true);
^^^^^^^^^^^^^^^^
[INFO] Precompiling build script... completed, took 900ms
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
pub finished with exit code 78
I also try this command flutter packages pub run build_runner build --delete-conflicting-outputs
But the result remains the same.
Here is how my abstract class looks like,
part 'rest_client.g.dart';
#RestApi(baseUrl: "https://myapi.com/")
abstract class RestClient {
factory RestClient(Dio dio, {String baseUrl}) = _RestClient;
#POST("/Flag")
Future<LoginResponse> login(#Body() LoginRequest loginRequest)`;}`
These are my packages version:
retrofit: ^3.3.0
dev_dependencies:
flutter_test:
sdk: flutter
retrofit_generator: ^4.1.2
build_runner: ^2.2.1
json_serializable: ^6.4.1
dependency_overrides:
analyzer: '5.1.0'
According to this githubLink
retrofit: 3.3.0 had bugs and the author forgot to publish the generator accordingly. So after resolving that bug using retrofit: ^3.3.1 and retrofit_generator: 4.2.0 is working fine
You will need to upgrade the package retrofit_generator to 4.2.0
you need to take care of the file naming your file name should be like what you will generate if you will generate [users.g.dart] your file name should be [ users.dart] or it will not create the file
and also upgrade your package to retrofit_generator: ^4.0.3+1
Describe my issue, i have modularization project so will be have different pubspec.yaml, every pubspec i use package for testing :
mockito: ^5.0.8
build_runner: ^2.0.4
dependency_overrides:
analyzer: ^1.7.0
so after generate flutter pub run build_runner build --delete-conflicting-outputs i get issue's, then i search google i it this cause analyzer, then i follow step to change analyze version, still error, in this error :
(base) dendimuhmd#macbook-pro datasources % flutter pub run build_runner build
Changing current working directory to: /Users/dendimuhmd/Documents/dev/flutter/dicoding/creative-movie/core
Failed to build build_runner:build_runner:
../../../../../../.pub-cache/hosted/pub.dartlang.org/build_resolvers-2.0.6/lib/src/resolver.dart:18:8: Error: Error when reading '../../../../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.2/lib/src/clients/build_resolvers/build_resolvers.dart': No such file or directory
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart';
^
../../../../../../.pub-cache/hosted/pub.dartlang.org/build_resolvers-2.0.6/lib/src/analysis_driver.dart:9:8: Error: Error when reading '../../../../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.2/lib/src/clients/build_resolvers/build_resolvers.dart': No such file or directory
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart';
^
../../../../../../.pub-cache/hosted/pub.dartlang.org/build_resolvers-2.0.6/lib/src/build_asset_uri_resolver.dart:11:8: Error: Error when reading '../../../../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.2/lib/src/clients/build_resolvers/build_resolvers.dart': No such file or directory
import 'package:analyzer/src/clients/build_resolvers/build_resolvers.dart';......
what is issue with analyzer, it this cause analyzer or?
Modularization structure
I'm using a package in my project called card_settings and it unfortunately depends on another package called flutter_cupertino_settings. Actually the last one does not support cupertino_icons v1.0.0 an I need to update icons package.
I've tried to use the forked repository by jibiel used to generate the pull request as flutter_cupertino_settings package override but I receive an error that I'm not able to solve:
Running "flutter pub get" in my_app...
Because my_app depends on dependency_overrides from unknown source "flutter_cupertino_settings", version solving failed.
pub get failed (1; Because my_app depends on dependency_overrides from unknown source "flutter_cupertino_settings", version solving failed.)
exit code 1
and this is my dependency override
card_settings: ^1.14.0
dependency_overrides:
flutter_cupertino_settings:
git:
url: https://github.com/jibiel/flutter_cupertino_settings.git
ref: dfb575c82b67ff76d6df240ccda9fefb53596709
Just paste this into your pubspec.yaml file:
card_settings: ^1.14.0
flutter_cupertino_settings: ^0.3.1
cupertino_icons: ^0.1.3
I created an example project inside a my flutter package and inside my example project i did:
dependencies:
flutter:
sdk: flutter
my_package:
path: ../
my_package used rxdart and i received an error after run my example project
Error: Could not resolve the package 'rxdart' in
'package:rxdart/rxdart.dart'.
I ran flutter packages get but the error is still here.
I just ran into the same issue. To solve it follow these steps:
Kill your app if it's running
Run flutter clean in both your main project directory and your my_package directory
Run flutter pub get in both your main project directory and your my_package directory
Now when you build your app you should be all set.
Check first, if you added rxdart package to your pubspec.yaml as shown below:
dependencies:
flutter:
sdk: flutter
rxdart: ^0.24.1
Run flutter pub get