Hive: I did build typeAdapter, but it's not working

Created on 22 Nov 2019  路  1Comment  路  Source: hivedb/hive

Question
I did build typeAdapter, but it's not working.
Why it did not create user.g.dart ?

flutter packages pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 321ms

[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 100ms

[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 886ms

[WARNING] Invalidating asset graph due to build script update!
[INFO] Cleaning up outputs from previous builds....
[INFO] Cleaning up outputs from previous builds. completed, took 5ms

[INFO] Generating build script...
[INFO] Generating build script completed, took 72ms

[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 11.3s

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 729ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms

[INFO] Running build...
[INFO] 1.0s elapsed, 0/16 actions completed.
[INFO] 2.1s elapsed, 0/16 actions completed.
[INFO] 3.1s elapsed, 0/16 actions completed.
[INFO] 4.2s elapsed, 0/16 actions completed.
[INFO] 5.3s elapsed, 0/16 actions completed.
[INFO] 7.2s elapsed, 1/16 actions completed.
[INFO] 8.7s elapsed, 1/17 actions completed.
[INFO] 11.2s elapsed, 2/17 actions completed.
[INFO] 12.3s elapsed, 13/27 actions completed.
[INFO] 13.3s elapsed, 54/55 actions completed.
[WARNING] hive_generator:hive_generator on lib/models/user.dart:
Missing "part 'user.g.dart';".
[INFO] Running build completed, took 14.1s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 96ms

[INFO] Succeeded after 14.2s with 2 outputs (166 actions)

Code sample
import 'package:meta/meta.dart';
import 'package:hive/hive.dart';

@HiveType()
enum AttendanceStatus {
@HiveField(0)
all,
@HiveField(1)
checked,
@HiveField(2)
waiting,
@HiveField(3)
absent,
}

@HiveType()
enum TimeType {
@HiveField(0)
none,
@HiveField(1)
work,
@HiveField(2)
undertime,
@HiveField(3)
overtime,
@HiveField(4)
vacation,
@HiveField(5)
leave,
}

/**

  • @HiveType() is generate an adapter class calld '[ClassName]Adapter'.
  • You can change that name with the optional adapterName parameter of @HiveType(params)
    */
    @immutable
    @HiveType()
    class User extends HiveObject {
    User({
    @required this.uid,
    this.email,
    this.displayName,
    this.photoUrl,
    this.phoneNumber,
    this.status,
    this.imageUrl,
    this.history,
    });

/**

  • Hive field numbers can be in the range 0-255.
  • Each Hive field has a unique number (unique per class).
  • If you want add the fields, just add fields with @HiveField(index).
  • But do not change the fields number for any existing fields.
  • ref.) https://docs.hivedb.dev/custom-objects/generate_adapter
    */
    @HiveField(0)
    final String uid;
    @HiveField(1)
    final String email;
    @HiveField(2)
    final String displayName;
    @HiveField(3)
    final String photoUrl;
    @HiveField(4)
    final String phoneNumber;
    @HiveField(5)
    final AttendanceStatus status;
    @HiveField(6)
    final String imageUrl;
    @HiveField(7)
    final Map history;
    }

Version

  • Platform: iOS, Android, Mac, Windows, Linux, Web
  • Flutter version: 1.12.4
  • Hive version: hive 1.1.1 , hive_flutter 0.2.1 , hive_generator 0.5.2
question

Most helpful comment

@sweetginger you forget to add line before running code generation.
you need add next line

part 'user.g.dart';

here

import 'package:meta/meta.dart';
import 'package:hive/hive.dart';

part 'user.g.dart';

@HiveType()
enum AttendanceStatus {
...

actually take a look to the log. there is error about it:
image

>All comments

@sweetginger you forget to add line before running code generation.
you need add next line

part 'user.g.dart';

here

import 'package:meta/meta.dart';
import 'package:hive/hive.dart';

part 'user.g.dart';

@HiveType()
enum AttendanceStatus {
...

actually take a look to the log. there is error about it:
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamesdixon picture jamesdixon  路  3Comments

azilvl picture azilvl  路  3Comments

ProfileID picture ProfileID  路  4Comments

aminjoharinia picture aminjoharinia  路  3Comments

cachapa picture cachapa  路  4Comments