pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
967 stars 191 forks source link

Generating duplicated definitions with @transaction #748

Open balenaultra opened 1 year ago

balenaultra commented 1 year ago

After updating my project and running the build_runner i got an error in database.g.dart on my insert commands with the @transaction annotation.

I don't know if is a bug or just my misunderstood by using this property

My DAO

@dao
abstract class CartDAO {
  @insert
  @transaction
  Future<int> insertCart(DatabaseCart cart);
}

generated database file.

@override
  Future<int> insertCart(DatabaseCart cart) {
    return _databaseCartInsertionAdapter.insertAndReturnId(
        cart, OnConflictStrategy.abort);
  }

  @override
  Future<int> insertCart(DatabaseCart cart) async {
    if (database is sqflite.Transaction) {
      return super.insertCart(cart);
    } else {
      return (database as sqflite.Database)
          .transaction<int>((transaction) async {
        final transactionDatabase = _$AppDatabase(changeListener)
          ..database = transaction;
        return transactionDatabase.cartDAO.insertCart(cart);
      });
    }
  }

problem

The name 'insertCart' is already defined.
Try renaming one of the declarations.

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-x64, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.76.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

My example project. flutter_floor_bug.zip

JuanFcoMiranda commented 1 year ago

Same problem here.

dkaera commented 1 year ago

@balenaultra @JuanFcoMiranda Floor transactions work differently than Room transactions in some cases. The transaction annotation is used to perform multiple operations in a single atomic transaction, here is an example of how it is used in the doc. On the other hand, if you want to insert a list of items, this operation is performed in a transaction under the hood, so you no need to declare transaction there.

SEGVeenstra commented 1 year ago

@balenaultra @JuanFcoMiranda , Did the answer of @dkaera help you? Can I close the issue?