From f2a954f2b26b012349568b4db268ab6a9317b127 Mon Sep 17 00:00:00 2001 From: Dmytro Puzak Date: Sat, 16 Mar 2024 23:57:21 +0200 Subject: [PATCH] Applyes analysis_options for example project. Resolves the existing analizer warnings. --- example/analysis_options.yaml | 28 ++++ example/lib/database.g.dart | 27 ++-- example/lib/main.dart | 26 ++-- example/pubspec.lock | 132 +++++++++++------- example/pubspec.yaml | 2 + floor/lib/src/sqflite_database_factory.dart | 2 - floor/pubspec.lock | 130 +++++++++-------- floor/pubspec.yaml | 3 +- floor_generator/lib/generator.dart | 2 + .../database_builder_contract_writer.dart | 45 ++++++ .../lib/writer/database_builder_writer.dart | 17 ++- floor_generator/lib/writer/floor_writer.dart | 7 +- floor_generator/pubspec.lock | 118 ++++++++-------- ...atabase_builder__contract_writer_test.dart | 28 ++++ .../writer/database_builder_writer_test.dart | 12 +- .../test/writer/floor_writer_test.dart | 4 +- 16 files changed, 372 insertions(+), 211 deletions(-) create mode 100644 example/analysis_options.yaml create mode 100644 floor_generator/lib/writer/database_builder_contract_writer.dart create mode 100644 floor_generator/test/writer/database_builder__contract_writer_test.dart diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 00000000..5a368c34 --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,28 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at https://dart.dev/lints. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options \ No newline at end of file diff --git a/example/lib/database.g.dart b/example/lib/database.g.dart index c593a4c1..39dcf3a9 100644 --- a/example/lib/database.g.dart +++ b/example/lib/database.g.dart @@ -6,21 +6,32 @@ part of 'database.dart'; // FloorGenerator // ************************************************************************** +abstract class $FlutterDatabaseBuilderContract { + /// Adds migrations to the builder. + $FlutterDatabaseBuilderContract addMigrations(List migrations); + + /// Adds a database [Callback] to the builder. + $FlutterDatabaseBuilderContract addCallback(Callback callback); + + /// Creates the database and initializes it. + Future build(); +} + // ignore: avoid_classes_with_only_static_members class $FloorFlutterDatabase { /// Creates a database builder for a persistent database. /// Once a database is built, you should keep a reference to it and re-use it. - static _$FlutterDatabaseBuilder databaseBuilder(String name) => + static $FlutterDatabaseBuilderContract databaseBuilder(String name) => _$FlutterDatabaseBuilder(name); /// Creates a database builder for an in memory database. /// Information stored in an in memory database disappears when the process is killed. /// Once a database is built, you should keep a reference to it and re-use it. - static _$FlutterDatabaseBuilder inMemoryDatabaseBuilder() => + static $FlutterDatabaseBuilderContract inMemoryDatabaseBuilder() => _$FlutterDatabaseBuilder(null); } -class _$FlutterDatabaseBuilder { +class _$FlutterDatabaseBuilder implements $FlutterDatabaseBuilderContract { _$FlutterDatabaseBuilder(this.name); final String? name; @@ -29,19 +40,19 @@ class _$FlutterDatabaseBuilder { Callback? _callback; - /// Adds migrations to the builder. - _$FlutterDatabaseBuilder addMigrations(List migrations) { + @override + $FlutterDatabaseBuilderContract addMigrations(List migrations) { _migrations.addAll(migrations); return this; } - /// Adds a database [Callback] to the builder. - _$FlutterDatabaseBuilder addCallback(Callback callback) { + @override + $FlutterDatabaseBuilderContract addCallback(Callback callback) { _callback = callback; return this; } - /// Creates the database and initializes it. + @override Future build() async { final path = name != null ? await sqfliteDatabaseFactory.getDatabasePath(name!) diff --git a/example/lib/main.dart b/example/lib/main.dart index bed0fcd0..b0994452 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -17,7 +17,7 @@ Future main() async { class FloorApp extends StatelessWidget { final TaskDao dao; - const FloorApp(this.dao); + const FloorApp(this.dao, {super.key}); @override Widget build(BuildContext context) { @@ -37,10 +37,10 @@ class TasksWidget extends StatefulWidget { final TaskDao dao; const TasksWidget({ - Key? key, + super.key, required this.title, required this.dao, - }) : super(key: key); + }); @override State createState() => TasksWidgetState(); @@ -100,7 +100,6 @@ class TasksWidgetState extends State { } TaskStatus _getMenuType(int index) => TaskStatus.values[index - 1]; - } class TasksListView extends StatelessWidget { @@ -108,10 +107,10 @@ class TasksListView extends StatelessWidget { final TaskStatus? selectedType; const TasksListView({ - Key? key, + super.key, required this.dao, required this.selectedType, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -145,10 +144,10 @@ class TaskListCell extends StatelessWidget { final TaskDao dao; const TaskListCell({ - Key? key, + super.key, required this.task, required this.dao, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -158,22 +157,22 @@ class TaskListCell extends StatelessWidget { padding: const EdgeInsets.only(left: 16), color: Colors.green, child: const Align( + alignment: Alignment.centerLeft, child: Text( 'Change status', style: TextStyle(color: Colors.white), ), - alignment: Alignment.centerLeft, ), ), secondaryBackground: Container( padding: const EdgeInsets.only(right: 16), color: Colors.red, child: const Align( + alignment: Alignment.centerRight, child: Text( 'Delete', style: TextStyle(color: Colors.white), ), - alignment: Alignment.centerRight, ), ), direction: DismissDirection.horizontal, @@ -202,7 +201,7 @@ class TaskListCell extends StatelessWidget { break; } - if (statusMessage != null) { + if (statusMessage != null && context.mounted) { final scaffoldMessengerState = ScaffoldMessenger.of(context); scaffoldMessengerState.hideCurrentSnackBar(); scaffoldMessengerState.showSnackBar( @@ -220,10 +219,9 @@ class TasksTextField extends StatelessWidget { final TaskDao dao; TasksTextField({ - Key? key, + super.key, required this.dao, - }) : _textEditingController = TextEditingController(), - super(key: key); + }) : _textEditingController = TextEditingController(); @override Widget build(BuildContext context) { diff --git a/example/pubspec.lock b/example/pubspec.lock index ad812b07..c54ac45a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: args - sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440" + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.2" async: dependency: transitive description: @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: build_daemon - sha256: "5f02d73eb2ba16483e693f80bee4f088563a820e47d1027d4cdfe62b5bb43e65" + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.1" build_resolvers: dependency: transitive description: @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: "14febe0f5bac5ae474117a36099b4de6f1dbc52df6c5e55534b3da9591bf4292" + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" url: "https://pub.dev" source: hosted - version: "7.2.7" + version: "7.3.0" built_collection: dependency: transitive description: @@ -101,10 +101,10 @@ packages: dependency: transitive description: name: built_value - sha256: "31b7c748fd4b9adf8d25d72a4c4a59ef119f12876cf414f94f8af5131d5fa2b0" + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e url: "https://pub.dev" source: hosted - version: "8.4.4" + version: "8.9.1" characters: dependency: transitive description: @@ -125,10 +125,10 @@ packages: dependency: transitive description: name: checked_yaml - sha256: "3d1505d91afa809d177efd4eed5bb0eb65805097a1463abdd2add076effae311" + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.0.3" clock: dependency: transitive description: @@ -165,18 +165,18 @@ packages: dependency: transitive description: name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" dart_style: dependency: transitive description: name: dart_style - sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" url: "https://pub.dev" source: hosted - version: "2.3.4" + version: "2.3.6" fake_async: dependency: transitive description: @@ -189,18 +189,18 @@ packages: dependency: transitive description: name: ffi - sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978 + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.2" file: dependency: transitive description: name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "7.0.0" fixnum: dependency: transitive description: @@ -235,6 +235,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" + source: hosted + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -252,18 +260,18 @@ packages: dependency: transitive description: name: glob - sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" graphs: dependency: transitive description: name: graphs - sha256: f9e130f3259f52d26f0cfc0e964513796dafed572fa52e45d2f8d6ca14db39b2 + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.3.1" http_multi_server: dependency: transitive description: @@ -292,18 +300,18 @@ packages: dependency: transitive description: name: js - sha256: "323b7c70073cccf6b9b8d8b334be418a3293cfb612a560dc2737160a37bf61bd" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.6.6" + version: "0.6.7" json_annotation: dependency: transitive description: name: json_annotation - sha256: c33da08e136c3df0190bd5bbe51ae1df4a7d96e7954d1d7249fea2968a72d317 + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "4.8.1" leak_tracker: dependency: transitive description: @@ -328,6 +336,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" + lints: + dependency: transitive + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" lists: dependency: transitive description: @@ -340,10 +356,10 @@ packages: dependency: transitive description: name: logging - sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d" + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" matcher: dependency: transitive description: @@ -372,10 +388,10 @@ packages: dependency: transitive description: name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" package_config: dependency: transitive description: @@ -412,26 +428,26 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: ec85d7d55339d85f44ec2b682a82fea340071e8978257e5a43e69f79e98ef50c + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.2.3" shelf: dependency: transitive description: name: shelf - sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.4.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - sha256: a988c0e8d8ffbdb8a28aa7ec8e449c260f3deb808781fe1284d22c5bba7156e8 + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "1.0.4" sky_engine: dependency: transitive description: flutter @@ -454,7 +470,7 @@ packages: source: hosted version: "1.10.0" sqflite: - dependency: transitive + dependency: "direct main" description: name: sqflite sha256: a9016f495c927cb90557c909ff26a6d92d9bd54fc42ba92e19d4e79d61e798c6 @@ -465,18 +481,18 @@ packages: dependency: transitive description: name: sqflite_common - sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5" + sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4" url: "https://pub.dev" source: hosted - version: "2.5.3" + version: "2.5.4" sqflite_common_ffi: dependency: transitive description: name: sqflite_common_ffi - sha256: "754927d82de369a6b9e760fb60640aa81da650f35ffd468d5a992814d6022908" + sha256: "4d6137c29e930d6e4a8ff373989dd9de7bac12e3bc87bce950f6e844e8ad3bb5" url: "https://pub.dev" source: hosted - version: "2.3.2+1" + version: "2.3.3" sqlite3: dependency: transitive description: @@ -489,10 +505,10 @@ packages: dependency: transitive description: name: sqlparser - sha256: dc384bb1f56d1384ce078edb5ff8247976abdab79d0c83e437210c85f06ecb61 + sha256: "7b20045d1ccfb7bc1df7e8f9fee5ae58673fce6ff62cefbb0e0fd7214e90e5a0" url: "https://pub.dev" source: hosted - version: "0.34.0" + version: "0.34.1" stack_trace: dependency: transitive description: @@ -529,18 +545,18 @@ packages: dependency: transitive description: name: strings - sha256: "1f3db7347b8dfd9844ee7fb34883cffbe6cc723a63cb9f4a0aa19e619304b030" + sha256: b33f40c4dd3e597bf6d9e7f4f4dc282dad0f19b07d9f320cb5c2183859cbccf5 url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.1.1" synchronized: dependency: transitive description: name: synchronized - sha256: "33b31b6beb98100bf9add464a36a8dd03eb10c7a8cf15aeec535e9b054aaf04b" + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.0+1" term_glyph: dependency: transitive description: @@ -569,10 +585,10 @@ packages: dependency: transitive description: name: typed_data - sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" unicode: dependency: transitive description: @@ -605,22 +621,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.4" yaml: dependency: transitive description: name: yaml - sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.2" sdks: - dart: ">=3.2.6 <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.7.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9ce5f914..03a4c80b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,11 +14,13 @@ dependencies: path: ../floor/ flutter: sdk: flutter + sqflite: any # This dependency is needed to solve the problem with warning about transitive dependencies dev_dependencies: analyzer: ^6.4.1 build_runner: ^2.4.8 floor_generator: path: ../floor_generator/ + flutter_lints: ^3.0.1 flutter_test: sdk: flutter diff --git a/floor/lib/src/sqflite_database_factory.dart b/floor/lib/src/sqflite_database_factory.dart index 89a48bd7..65aa0614 100644 --- a/floor/lib/src/sqflite_database_factory.dart +++ b/floor/lib/src/sqflite_database_factory.dart @@ -1,8 +1,6 @@ import 'dart:io'; import 'package:path/path.dart'; -// ignore: unnecessary_import -import 'package:sqflite/sqflite.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; // infers factory as nullable without explicit type definition diff --git a/floor/pubspec.lock b/floor/pubspec.lock index e7b7661a..fd264012 100644 --- a/floor/pubspec.lock +++ b/floor/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: args - sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440" + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.2" async: dependency: transitive description: @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: build_daemon - sha256: "5f02d73eb2ba16483e693f80bee4f088563a820e47d1027d4cdfe62b5bb43e65" + sha256: "0343061a33da9c5810b2d6cee51945127d8f4c060b7fbdd9d54917f0a3feaaa1" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.1" build_resolvers: dependency: transitive description: @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: "14febe0f5bac5ae474117a36099b4de6f1dbc52df6c5e55534b3da9591bf4292" + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" url: "https://pub.dev" source: hosted - version: "7.2.7" + version: "7.3.0" built_collection: dependency: transitive description: @@ -101,10 +101,10 @@ packages: dependency: transitive description: name: built_value - sha256: "31b7c748fd4b9adf8d25d72a4c4a59ef119f12876cf414f94f8af5131d5fa2b0" + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e url: "https://pub.dev" source: hosted - version: "8.4.4" + version: "8.9.1" characters: dependency: transitive description: @@ -125,10 +125,10 @@ packages: dependency: transitive description: name: checked_yaml - sha256: "3d1505d91afa809d177efd4eed5bb0eb65805097a1463abdd2add076effae311" + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.0.3" clock: dependency: transitive description: @@ -165,18 +165,18 @@ packages: dependency: transitive description: name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" dart_style: dependency: transitive description: name: dart_style - sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" url: "https://pub.dev" source: hosted - version: "2.3.4" + version: "2.3.6" fake_async: dependency: transitive description: @@ -189,18 +189,18 @@ packages: dependency: transitive description: name: ffi - sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978 + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.1.2" file: dependency: transitive description: name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "7.0.0" fixnum: dependency: transitive description: @@ -245,18 +245,18 @@ packages: dependency: transitive description: name: glob - sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" graphs: dependency: transitive description: name: graphs - sha256: f9e130f3259f52d26f0cfc0e964513796dafed572fa52e45d2f8d6ca14db39b2 + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.3.1" http_multi_server: dependency: transitive description: @@ -285,42 +285,42 @@ packages: dependency: transitive description: name: js - sha256: "323b7c70073cccf6b9b8d8b334be418a3293cfb612a560dc2737160a37bf61bd" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.6.6" + version: "0.6.7" json_annotation: dependency: transitive description: name: json_annotation - sha256: c33da08e136c3df0190bd5bbe51ae1df4a7d96e7954d1d7249fea2968a72d317 + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "4.8.1" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: cdd14e3836065a1f6302a236ec8b5f700695c803c57ae11a1c84df31e6bcf831 + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" url: "https://pub.dev" source: hosted - version: "10.0.3" + version: "10.0.0" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "9b2ef90589911d665277464e0482b209d39882dffaaf4ef69a3561a3354b2ebc" + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "2.0.1" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: fd3cd66cb2bcd7b50dcd3b413af49d78051f809c8b3f6e047962765c15a0d23d + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "2.0.1" lists: dependency: transitive description: @@ -333,10 +333,10 @@ packages: dependency: transitive description: name: logging - sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d" + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" matcher: dependency: "direct dev" description: @@ -365,10 +365,10 @@ packages: dependency: transitive description: name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" mockito: dependency: "direct dev" description: @@ -413,26 +413,26 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: ec85d7d55339d85f44ec2b682a82fea340071e8978257e5a43e69f79e98ef50c + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.2.3" shelf: dependency: transitive description: name: shelf - sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.4.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - sha256: a988c0e8d8ffbdb8a28aa7ec8e449c260f3deb808781fe1284d22c5bba7156e8 + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "1.0.4" sky_engine: dependency: transitive description: flutter @@ -463,21 +463,21 @@ packages: source: hosted version: "2.3.2" sqflite_common: - dependency: "direct dev" + dependency: transitive description: name: sqflite_common - sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5" + sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4" url: "https://pub.dev" source: hosted - version: "2.5.3" + version: "2.5.4" sqflite_common_ffi: dependency: "direct main" description: name: sqflite_common_ffi - sha256: "754927d82de369a6b9e760fb60640aa81da650f35ffd468d5a992814d6022908" + sha256: "4d6137c29e930d6e4a8ff373989dd9de7bac12e3bc87bce950f6e844e8ad3bb5" url: "https://pub.dev" source: hosted - version: "2.3.2+1" + version: "2.3.3" sqlite3: dependency: transitive description: @@ -538,10 +538,10 @@ packages: dependency: transitive description: name: synchronized - sha256: "33b31b6beb98100bf9add464a36a8dd03eb10c7a8cf15aeec535e9b054aaf04b" + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.1.0+1" term_glyph: dependency: transitive description: @@ -554,10 +554,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" timing: dependency: transitive description: @@ -570,10 +570,10 @@ packages: dependency: transitive description: name: typed_data - sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" unicode: dependency: transitive description: @@ -594,10 +594,10 @@ packages: dependency: transitive description: name: vm_service - sha256: a2662fb1f114f4296cf3f5a50786a2d888268d7776cf681aa17d660ffa23b246 + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "14.0.0" + version: "13.0.0" watcher: dependency: transitive description: @@ -606,22 +606,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.4" yaml: dependency: transitive description: name: yaml - sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.2" sdks: - dart: ">=3.2.6 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.7.0" diff --git a/floor/pubspec.yaml b/floor/pubspec.yaml index f1a22f66..74a4988a 100644 --- a/floor/pubspec.yaml +++ b/floor/pubspec.yaml @@ -30,5 +30,4 @@ dev_dependencies: flutter_test: sdk: flutter matcher: ^0.12.16+1 - mockito: ^5.4.4 - sqflite_common: ^2.5.3 \ No newline at end of file + mockito: ^5.4.4 \ No newline at end of file diff --git a/floor_generator/lib/generator.dart b/floor_generator/lib/generator.dart index b7650dfe..033ac62f 100644 --- a/floor_generator/lib/generator.dart +++ b/floor_generator/lib/generator.dart @@ -8,6 +8,7 @@ import 'package:floor_generator/misc/extension/iterable_extension.dart'; import 'package:floor_generator/processor/database_processor.dart'; import 'package:floor_generator/value_object/database.dart'; import 'package:floor_generator/writer/dao_writer.dart'; +import 'package:floor_generator/writer/database_builder_contract_writer.dart'; import 'package:floor_generator/writer/database_builder_writer.dart'; import 'package:floor_generator/writer/database_writer.dart'; import 'package:floor_generator/writer/floor_writer.dart'; @@ -39,6 +40,7 @@ class FloorGenerator extends GeneratorForAnnotation { final library = Library((builder) { builder + ..body.add(DatabaseBuilderContractWriter(database.name).write()) ..body.add(FloorWriter(database.name).write()) ..body.add(DatabaseBuilderWriter(database.name).write()) ..body.add(databaseClass) diff --git a/floor_generator/lib/writer/database_builder_contract_writer.dart b/floor_generator/lib/writer/database_builder_contract_writer.dart new file mode 100644 index 00000000..47c96363 --- /dev/null +++ b/floor_generator/lib/writer/database_builder_contract_writer.dart @@ -0,0 +1,45 @@ +import 'package:code_builder/code_builder.dart'; +import 'package:floor_generator/writer/writer.dart'; + +class DatabaseBuilderContractWriter extends Writer { + final String _databaseName; + + DatabaseBuilderContractWriter(final String databaseName) + : _databaseName = databaseName; + + @override + Class write() { + final databaseBuilderName = '\$${_databaseName}BuilderContract'; + + final addMigrationsMethod = Method((builder) => builder + ..name = 'addMigrations' + ..returns = refer(databaseBuilderName) + ..docs.add('/// Adds migrations to the builder.') + ..requiredParameters.add(Parameter((builder) => builder + ..name = 'migrations' + ..type = refer('List')))); + + final addCallbackMethod = Method((builder) => builder + ..name = 'addCallback' + ..returns = refer(databaseBuilderName) + ..docs.add('/// Adds a database [Callback] to the builder.') + ..requiredParameters.add(Parameter((builder) => builder + ..name = 'callback' + ..type = refer('Callback')))); + + final buildMethod = Method((builder) => builder + ..returns = refer('Future<$_databaseName>') + ..name = 'build' + ..modifier = MethodModifier.async + ..docs.add('/// Creates the database and initializes it.')); + + return Class((builder) => builder + ..name = databaseBuilderName + ..abstract = true + ..methods.addAll([ + addMigrationsMethod, + addCallbackMethod, + buildMethod, + ])); + } +} diff --git a/floor_generator/lib/writer/database_builder_writer.dart b/floor_generator/lib/writer/database_builder_writer.dart index 7e9bbee9..f26043cc 100644 --- a/floor_generator/lib/writer/database_builder_writer.dart +++ b/floor_generator/lib/writer/database_builder_writer.dart @@ -1,4 +1,5 @@ import 'package:code_builder/code_builder.dart'; +import 'package:floor_generator/misc/annotation_expression.dart'; import 'package:floor_generator/writer/writer.dart'; class DatabaseBuilderWriter extends Writer { @@ -10,6 +11,9 @@ class DatabaseBuilderWriter extends Writer { @override Class write() { final databaseBuilderName = '_\$${_databaseName}Builder'; + final databaseBuilderContractRefer = refer( + '\$${_databaseName}BuilderContract', + ); final nameField = Field((builder) => builder ..name = 'name' @@ -32,34 +36,34 @@ class DatabaseBuilderWriter extends Writer { ..name = 'name'))); final addMigrationsMethod = Method((builder) => builder + ..annotations.add(overrideAnnotationExpression) ..name = 'addMigrations' - ..returns = refer(databaseBuilderName) + ..returns = databaseBuilderContractRefer ..body = const Code(''' _migrations.addAll(migrations); return this; ''') - ..docs.add('/// Adds migrations to the builder.') ..requiredParameters.add(Parameter((builder) => builder ..name = 'migrations' ..type = refer('List')))); final addCallbackMethod = Method((builder) => builder + ..annotations.add(overrideAnnotationExpression) ..name = 'addCallback' - ..returns = refer(databaseBuilderName) + ..returns = databaseBuilderContractRefer ..body = const Code(''' _callback = callback; return this; ''') - ..docs.add('/// Adds a database [Callback] to the builder.') ..requiredParameters.add(Parameter((builder) => builder ..name = 'callback' ..type = refer('Callback')))); final buildMethod = Method((builder) => builder + ..annotations.add(overrideAnnotationExpression) ..returns = refer('Future<$_databaseName>') ..name = 'build' ..modifier = MethodModifier.async - ..docs.add('/// Creates the database and initializes it.') ..body = Code(''' final path = name != null ? await sqfliteDatabaseFactory.getDatabasePath(name!) @@ -75,6 +79,9 @@ class DatabaseBuilderWriter extends Writer { return Class((builder) => builder ..name = databaseBuilderName + ..implements.addAll([ + databaseBuilderContractRefer, + ]) ..fields.addAll([ nameField, migrationsField, diff --git a/floor_generator/lib/writer/floor_writer.dart b/floor_generator/lib/writer/floor_writer.dart index 697ae678..674a41d2 100644 --- a/floor_generator/lib/writer/floor_writer.dart +++ b/floor_generator/lib/writer/floor_writer.dart @@ -9,13 +9,16 @@ class FloorWriter extends Writer { @override Class write() { final databaseBuilderName = '_\$${_databaseName}Builder'; + final databaseBuilderContractName = refer( + '\$${_databaseName}BuilderContract', + ); final databaseBuilderMethod = Method((builder) => builder ..name = 'databaseBuilder' ..lambda = true ..static = true ..body = Code('$databaseBuilderName(name)') - ..returns = refer(databaseBuilderName) + ..returns = databaseBuilderContractName ..docs.addAll([ r'/// Creates a database builder for a persistent database.', '/// Once a database is built, you should keep a reference to it and re-use it.' @@ -28,7 +31,7 @@ class FloorWriter extends Writer { ..name = 'inMemoryDatabaseBuilder' ..lambda = true ..static = true - ..returns = refer(databaseBuilderName) + ..returns = databaseBuilderContractName ..docs.addAll([ r'/// Creates a database builder for an in memory database.', '/// Information stored in an in memory database disappears when the process is killed.', diff --git a/floor_generator/pubspec.lock b/floor_generator/pubspec.lock index 11d7e444..7628dc6c 100644 --- a/floor_generator/pubspec.lock +++ b/floor_generator/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: args - sha256: "4cab82a83ffef80b262ddedf47a0a8e56ee6fbf7fe21e6e768b02792034dd440" + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.2" async: dependency: transitive description: @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: built_value - sha256: "31b7c748fd4b9adf8d25d72a4c4a59ef119f12876cf414f94f8af5131d5fa2b0" + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e url: "https://pub.dev" source: hosted - version: "8.4.4" + version: "8.9.1" characters: dependency: transitive description: @@ -101,10 +101,10 @@ packages: dependency: transitive description: name: checked_yaml - sha256: "3d1505d91afa809d177efd4eed5bb0eb65805097a1463abdd2add076effae311" + sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.0.3" code_builder: dependency: "direct main" description: @@ -133,42 +133,42 @@ packages: dependency: transitive description: name: coverage - sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" + sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76" url: "https://pub.dev" source: hosted - version: "1.6.3" + version: "1.7.2" crypto: dependency: transitive description: name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab url: "https://pub.dev" source: hosted - version: "3.0.2" + version: "3.0.3" csslib: dependency: transitive description: name: csslib - sha256: b36c7f7e24c0bdf1bf9a3da461c837d1de64b9f8beb190c9011d8c72a3dfd745 + sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb" url: "https://pub.dev" source: hosted - version: "0.17.2" + version: "1.0.0" dart_style: dependency: "direct dev" description: name: dart_style - sha256: "25b4624c231844a7a70a3817a729a6190a751ef1c07ded256e126a3b72261444" + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" url: "https://pub.dev" source: hosted - version: "2.3.5" + version: "2.3.6" file: dependency: transitive description: name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "7.0.0" fixnum: dependency: transitive description: @@ -196,26 +196,26 @@ packages: dependency: transitive description: name: glob - sha256: "4515b5b6ddb505ebdd242a5f2cc5d22d3d6a80013789debfbda7777f47ea308c" + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" graphs: dependency: transitive description: name: graphs - sha256: f9e130f3259f52d26f0cfc0e964513796dafed572fa52e45d2f8d6ca14db39b2 + sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 url: "https://pub.dev" source: hosted - version: "2.2.0" + version: "2.3.1" html: dependency: transitive description: name: html - sha256: "79d498e6d6761925a34ee5ea8fa6dfef38607781d2fa91e37523474282af55cb" + sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a" url: "https://pub.dev" source: hosted - version: "0.15.2" + version: "0.15.4" http_multi_server: dependency: transitive description: @@ -244,18 +244,18 @@ packages: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" json_annotation: dependency: transitive description: name: json_annotation - sha256: c33da08e136c3df0190bd5bbe51ae1df4a7d96e7954d1d7249fea2968a72d317 + sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "4.8.1" lists: dependency: transitive description: @@ -268,10 +268,10 @@ packages: dependency: transitive description: name: logging - sha256: "04094f2eb032cbb06c6f6e8d3607edcfcb0455e2bb6cbc010cb01171dcb64e6d" + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" matcher: dependency: transitive description: @@ -292,10 +292,10 @@ packages: dependency: transitive description: name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" mockito: dependency: "direct dev" description: @@ -348,42 +348,42 @@ packages: dependency: transitive description: name: pubspec_parse - sha256: ec85d7d55339d85f44ec2b682a82fea340071e8978257e5a43e69f79e98ef50c + sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.2.3" shelf: dependency: transitive description: name: shelf - sha256: c24a96135a2ccd62c64b69315a14adc5c3419df63b4d7c05832a346fdb73682c + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.4.1" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler - sha256: aef74dc9195746a384843102142ab65b6a4735bb3beea791e63527b88cc83306 + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" shelf_static: dependency: transitive description: name: shelf_static - sha256: e792b76b96a36d4a41b819da593aff4bdd413576b3ba6150df5d8d9996d2e74c + sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.2" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - sha256: a988c0e8d8ffbdb8a28aa7ec8e449c260f3deb808781fe1284d22c5bba7156e8 + sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "1.0.4" source_gen: dependency: "direct main" description: @@ -420,18 +420,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" stream_transform: dependency: transitive description: @@ -501,10 +501,10 @@ packages: dependency: transitive description: name: typed_data - sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" unicode: dependency: transitive description: @@ -517,10 +517,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f6deed8ed625c52864792459709183da231ebf66ff0cf09e69b573227c377efe + sha256: e7d5ecd604e499358c5fe35ee828c0298a320d54455e791e9dcf73486bc8d9f0 url: "https://pub.dev" source: hosted - version: "11.3.0" + version: "14.1.0" watcher: dependency: transitive description: @@ -529,29 +529,37 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b + sha256: "1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.4" webkit_inspection_protocol: dependency: transitive description: name: webkit_inspection_protocol - sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d" + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" yaml: dependency: transitive description: name: yaml - sha256: "23812a9b125b48d4007117254bca50abb6c712352927eece9e155207b1db2370" + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.2" sdks: - dart: ">=3.2.6 <=3.3.8" + dart: ">=3.3.0 <=3.3.8" diff --git a/floor_generator/test/writer/database_builder__contract_writer_test.dart b/floor_generator/test/writer/database_builder__contract_writer_test.dart new file mode 100644 index 00000000..c20f1061 --- /dev/null +++ b/floor_generator/test/writer/database_builder__contract_writer_test.dart @@ -0,0 +1,28 @@ +import 'package:code_builder/code_builder.dart'; +import 'package:floor_generator/writer/database_builder_contract_writer.dart'; +import 'package:test/test.dart'; + +import '../test_utils.dart'; + +void main() { + useDartfmt(); + + test('generate database builder contract', () async { + const databaseName = 'FooBar'; + + final actual = DatabaseBuilderContractWriter(databaseName).write(); + + expect(actual, equalsDart(r''' + abstract class $FooBarBuilderContract { + /// Adds migrations to the builder. + $FooBarBuilderContract addMigrations(List migrations); + + /// Adds a database [Callback] to the builder. + $FooBarBuilderContract addCallback(Callback callback); + + /// Creates the database and initializes it. + Future build(); + } + ''')); + }); +} diff --git a/floor_generator/test/writer/database_builder_writer_test.dart b/floor_generator/test/writer/database_builder_writer_test.dart index a677a078..72f8e07c 100644 --- a/floor_generator/test/writer/database_builder_writer_test.dart +++ b/floor_generator/test/writer/database_builder_writer_test.dart @@ -13,7 +13,7 @@ void main() { final actual = DatabaseBuilderWriter(databaseName).write(); expect(actual, equalsDart(r''' - class _$FooBarBuilder { + class _$FooBarBuilder implements $FooBarBuilderContract { _$FooBarBuilder(this.name); final String? name; @@ -22,19 +22,19 @@ void main() { Callback? _callback; - /// Adds migrations to the builder. - _$FooBarBuilder addMigrations(List migrations) { + @override + $FooBarBuilderContract addMigrations(List migrations) { _migrations.addAll(migrations); return this; } - /// Adds a database [Callback] to the builder. - _$FooBarBuilder addCallback(Callback callback) { + @override + $FooBarBuilderContract addCallback(Callback callback) { _callback = callback; return this; } - /// Creates the database and initializes it. + @override Future build() async { final path = name != null ? await sqfliteDatabaseFactory.getDatabasePath(name!) diff --git a/floor_generator/test/writer/floor_writer_test.dart b/floor_generator/test/writer/floor_writer_test.dart index 39fd5d69..9efa2290 100644 --- a/floor_generator/test/writer/floor_writer_test.dart +++ b/floor_generator/test/writer/floor_writer_test.dart @@ -17,13 +17,13 @@ void main() { class $FloorFooBar { /// Creates a database builder for a persistent database. /// Once a database is built, you should keep a reference to it and re-use it. - static _$FooBarBuilder databaseBuilder(String name) => + static $FooBarBuilderContract databaseBuilder(String name) => _$FooBarBuilder(name); /// Creates a database builder for an in memory database. /// Information stored in an in memory database disappears when the process is killed. /// Once a database is built, you should keep a reference to it and re-use it. - static _$FooBarBuilder inMemoryDatabaseBuilder() => + static $FooBarBuilderContract inMemoryDatabaseBuilder() => _$FooBarBuilder(null); } '''));