drift
drift copied to clipboard
Build_runner is not generating .g files
I have been attempting to generate .g files using build_runner, but nothing happens in the project I am currently working on. I created a sample project where build_runner successfully generates the .g files. However, in my main project, it doesn't generate the .g files at all.
Here is the code.
task_dao.dart:
import 'package:drift/drift.dart';
import 'package:noti/core/local_db/database_repo.dart';
import 'package:noti/core/local_db/tables/task_table.dart';
part 'task_dao.g.dart';
@DriftAccessor(tables: [TaskDatabaseTable])
class TaskDao extends DatabaseAccessor<AppDatabase> {
TaskDao(super.attachedDatabase);
Future<int> addTask(TaskDatabaseTableCompanion task) {
return into(db.taskDatabaseTable).insert(task);
}
Future<List<TaskDatabaseTableData>> loadAllTasks() async {
final List<TaskDatabaseTableData> tasks =
await db.taskDatabaseTable.all().get();
return tasks;
}
Future<void> deleteTask(String taskId) async {
await (delete(db.taskDatabaseTable)..where((t) => t.taskId.equals(taskId)))
.go();
}
Future<void> updateTask(Task task) async {
await (update(db.taskDatabaseTable)
..where((t) => t.taskId.equals(task.taskId)))
.write(task.toCompanion());
}
}
task_table.dart:
import 'package:drift/drift.dart';
class TaskDatabaseTable extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get taskId => text()();
IntColumn get notificationID => integer()();
TextColumn get taskTitle => text()();
TextColumn get taskDesc => text()();
DateTimeColumn get dueDate => dateTime()();
BoolColumn get isCompleted => boolean()();
IntColumn get totalFocusedSessionsInSeconds =>
integer().withDefault(const Constant(0))();
DateTimeColumn get reminderDateTime => dateTime().nullable()();
BoolColumn get repeat => boolean().withDefault(const Constant(false))();
}
database_repo.dart:
import 'package:drift/drift.dart';
import 'package:drift_flutter/drift_flutter.dart';
import 'package:noti/core/local_db/dao/task_dao.dart';
import 'package:noti/core/local_db/tables/task_table.dart';
part 'database_repo.g.dart';
@DriftDatabase(tables: [TaskDatabaseTable])
class AppDatabase extends _$AppDatabase {
static final _instance = AppDatabase._internal();
factory AppDatabase() => _instance;
AppDatabase._internal() : super(_openConnection());
@override
int get schemaVersion => 1;
static QueryExecutor _openConnection() {
return driftDatabase(name: 'my_database');
}
TaskDao get taskDao => TaskDao(this);
}
pubspec.yaml:
dependencies:
flutter:
sdk: flutter
another_flutter_splash_screen: ^1.2.1
app_links: ^6.3.2
auto_animated: ^3.2.0
awesome_notifications: ^0.10.0
awesome_notifications_core: ^0.10.1
cached_network_image: ^3.3.0
# card_swiper: ^3.0.1
cloud_firestore: ^5.4.5
firebase_core: ^3.7.0
cloud_functions: ^5.0.3
collection: any
crypto: any
cupertino_icons: ^1.0.6
# easy_localization: ^3.0.3
# easy_localization_loader: ^2.0.0
emoji_picker_flutter: ^4.3.0
envied: ^1.1.1
envied_generator: ^1.1.1
firebase_analytics: ^11.2.0
firebase_auth: ^5.2.0
firebase_crashlytics: ^4.0.3
firebase_database: ^11.0.3
firebase_in_app_messaging: ^0.8.0+7
firebase_messaging: ^15.0.3
firebase_storage: ^12.1.2
flutter_riverpod: ^2.5.1
# flutter_keyboard_visibility: ^6.0.0
flutter_screenutil: ^5.9.0
flutter_slidable: ^3.0.1
fluttertoast: ^8.2.4
gap: ^3.0.1
go_router: ^15.1.1
google_fonts: ^6.2.1
google_sign_in: ^6.1.6
image_cropper: ^9.1.0
image_picker: ^1.0.4
in_app_review: ^2.0.8
json_annotation: ^4.8.1
path: any
path_provider: ^2.1.1
provider: ^6.1.1
purchases_flutter: ^8.8.0
# sembast: ^3.5.0
share_plus: ^11.0.0
shared_preferences: ^2.2.2
sign_in_with_apple: ^7.0.1
# sqflite: ^2.3.0
upgrader: ^11.3.1
url_launcher: ^6.3.0
url_strategy: ^0.3.0
wiredash: ^2.2.1
youtube_player_flutter: ^9.1.1
responsive_framework: ^1.5.1
package_info_plus: ^8.3.0
get_it: ^8.0.3
freezed_annotation: ^2.4.4
freezed: ^2.5.7
uuid: ^4.5.1
drift: ^2.23.0
drift_flutter: ^0.2.4
sqlite3_flutter_libs: ^0.5.33
flutter_localizations:
sdk: flutter
intl: any
flutter_image_compress: ^2.4.0
dev_dependencies:
build_runner: ^2.4.7
flutter_lints: ^5.0.0
drift_dev: ^2.23.0
flutter_test:
sdk: flutter
# json_serializable: ^6.7.1
Are no files being generated at all? What's the path of the database code, is it in lib/?
Are no files being generated at all? What's the path of the database code? Is it in
lib/?
Build_Runner is working for the 'freezed' package but not for any of the local database packages. I have tried object box and drift, but no .g files are generated. Here is my file structure of the lib folder:
├── constants
│ ├── constants_export.dart
│ ├── data_constants.dart
│ ├── extension_constants.dart
│ ├── show_hide_loading.dart
│ ├── string_constant.dart
│ └── ui_constants.dart
├── core
│ ├── local_db ------------------------> Here it is.
│ │ ├── dao
│ │ │ └── task_dao.dart
│ │ ├── database_repo.dart
│ │ └── tables
│ │ └── task_table.dart
│ ├── provider
│ │ ├── habitbee_user_provider.dart
│ │ ├── onboarding_provider.dart
│ │ ├── package_info_provider.dart
│ │ ├── shared_prefs_provider.dart
│ │ └── text_field_name_provider.dart
│ ├── repositories
│ │ └── user_repository.dart
│ └── services
│ ├── dialog_services.dart
│ ├── firebase_references.dart
│ ├── firestorage_service.dart
│ ├── image_picker_service.dart
│ ├── notifications_service.dart
│ └── subscription_services.dart
├── features
│ ├── app_intro
│ │ ├── intro_screen.dart
│ │ ├── intro_screen1.dart
│ │ ├── intro_screen2.dart
│ │ ├── intro_screen3.dart
│ │ ├── intro_screen4.dart
│ │ ├── intro_screen5.dart
│ │ ├── intro_screen6.dart
│ │ ├── intro_screen7.dart
│ │ ├── intro_screen8.dart
│ │ └── intro_screen9.dart
│ ├── auth
│ │ ├── provider
│ │ │ └── auth_provider.dart
│ │ ├── repository
│ │ │ ├── apple_auth_repo.dart
│ │ │ ├── auth_repo.dart
│ │ │ └── google_auth_repo.dart
│ │ └── screen
│ │ └── login_screen.dart
│ ├── home
│ │ ├── provider
│ │ │ └── home_provider.dart
│ │ ├── repository
│ │ │ └── home_repo.dart
│ │ └── screen
│ │ ├── add_collaborator_screen.dart
│ │ ├── category_screen
│ │ │ ├── add_category_screen.dart
│ │ │ └── category_dialogue.dart
│ │ ├── home_screen.dart
│ │ └── widgets
│ │ ├── add_note_overlay.dart
│ │ ├── note_card.dart
│ │ ├── reminder_custom_date_dialogue.dart
│ │ ├── reminder_time_dialogue.dart
│ │ ├── reminder_widget.dart
│ │ └── select_date_widget.dart
│ ├── onboarding
│ │ └── screens
│ │ └── widgets
│ │ ├── animation_screen.dart
│ │ ├── card_widget.dart
│ │ ├── login_screen.dart
│ │ ├── notification_screen.dart
│ │ ├── onboarding_screen_2.dart
│ │ ├── onboarding_screen_3.dart
│ │ ├── onboarding_screen_4.dart
│ │ ├── review_card.dart
│ │ ├── review_screen.dart
│ │ ├── subscription_free_trail_screen.dart
│ │ ├── survey_screen.dart
│ │ └── welcome_screen_1.dart
│ ├── premium
│ │ └── screens
│ │ └── get_pro_info_card_widget.dart
│ ├── profile
│ │ ├── edit_profile.dart
│ │ ├── profile_secreen.dart
│ │ ├── provider
│ │ │ ├── profile_provider.dart
│ │ │ └── profile_provider_state.dart
│ │ └── widgets
│ │ ├── delete_account_dailog.dart
│ │ ├── pick_image_bottomsheet_widget.dart
│ │ └── profile_card_widget.dart
│ ├── setting
│ │ ├── privacy_policy.dart
│ │ └── terms_and_condition.dart
│ └── splash_screen.dart
├── firebase_option
│ └── firebase_options.dart
├── l10n
│ ├── intl_de.arb
│ ├── intl_en.arb
│ ├── intl_es.arb
│ └── intl_fr.arb
├── main.dart
├── models
│ ├── audit_info
│ │ ├── audit_info.dart
│ │ ├── audit_info.freezed.dart
│ │ └── audit_info.g.dart
│ ├── collaborator
│ │ ├── collaborator.dart
│ │ ├── collaborator.freezed.dart
│ │ └── collaborator.g.dart
│ ├── dummy
│ ├── env
│ │ ├── env.dart
│ │ └── env.g.dart
│ ├── note_category
│ │ ├── note_category.dart
│ │ ├── note_category.freezed.dart
│ │ └── note_category.g.dart
│ ├── notes
│ │ ├── notes.dart
│ │ ├── notes.freezed.dart
│ │ └── notes.g.dart
│ ├── noti_user
│ │ ├── noti_user.dart
│ │ ├── noti_user.freezed.dart
│ │ └── noti_user.g.dart
│ ├── random_emojis.dart
│ └── response
│ └── response.dart
├── routes
│ └── routes.dart
├── theme
│ ├── app_colors.dart
│ ├── app_theme.dart
│ └── theme_export.dart
├── utils
│ ├── core_app_imports.dart
│ ├── dependency_injection.dart
│ └── navigator_service.dart
└── widgets
├── action_button.dart
├── app_textfield.dart
└── custom_app_bar.dart
Here is my build.yaml file:
targets:
$default:
builders:
json_serializable:
options:
explicit_to_json: true
# global_options:
# freezed:freezed:
# runs_before:
# - isar_generator:isar_generator
This is my flutter version:
Flutter 3.24.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision dec2ee5c1f (6 months ago) • 2024-11-13 11:13:06 -0800
Engine • revision a18df97ca5
Tools • Dart 3.5.4 • DevTools 2.37.3
These are my build_runner logs:
Built build_runner:build_runner.
[INFO] Generating build script completed, took 200ms
[INFO] Reading cached asset graph completed, took 102ms
[INFO] Checking for updates since last build completed, took 901ms
[INFO] Running build completed, took 1.5s
[INFO] Caching finalized dependency graph completed, took 76ms
[INFO] Succeeded after 1.6s with 10 outputs (23 actions)
Try put.dart files inside lib/data/local/ for example lib/data/local/task_dao.dart: