6

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.

2
  • 5
    I think you are missing hive_generator: ^1.1.1 in the dev dependencies. Sep 10, 2021 at 13:07
  • 2
    That was the solution regarding the build. And I had to assign a typeId in the @HiveType annotation like so: @HiveType(typeId : 1). Thanks a lot for the hint.
    – ThommyB
    Sep 10, 2021 at 16:10

9 Answers 9

9

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
1
  • 1
    That helped..=^
    – Febin K R
    Jul 13 at 18:18
5

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

3
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

1
1

try this,

flutter packages pub run build_runner watch --use-polling-watcher --delete-conflicting-outputs
1

Don't forget to add hive_generator at the dev_dependencies. Here's the link https://pub.dev/packages/hive_generator

0

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.

0

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;
....
}
0
 flutter packages pub run build_runner build --delete-conflicting-outputs
1
  • 2
    Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?
    – Tyler2P
    Nov 5, 2022 at 11:11
-1

I was getting the following when typing flutter packages pub run build_runner build in my console.

Deprecated. Use `dart run` instead.
Could not find package "build_runner". Did you forget to add a dependency?

This command worked for me instead: dart run build_runner build

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.