hhtokpinar / sqfEntity

SqfEntity ORM for Flutter/Dart lets you build and execute SQL commands on SQLite database easily and quickly with the help of fluent methods similar to .Net Entity Framework. SqfEntity also generates add/edit forms with validations and special controls (DropDown List, DateTime pickers, Checkboxes.. etc) for your table.
377 stars 99 forks source link

Version 2.3.0 does not respect modelName field with upperCase when creating model.g.view.dart file #278

Closed GoedertDalmolin closed 2 years ago

GoedertDalmolin commented 2 years ago

When I create the following table model (SqfEntityTable) in model.dart file:

const tableTest = SqfEntityTable(
  tableName: 'test',
  modelName: 'TestDB',
  primaryKeyName: 'id',
  primaryKeyType: PrimaryKeyType.integer_unique,
  fields: [
    SqfEntityField('description', DbType.text),
    SqfEntityField('dateRecord', DbType.datetime, defaultValue: 'DateTime.now()'),
  ],
);

Note that the "modelName" attribute is filled with a string in which upper and lower case letters are present. When adding this table inside the database creation model (SqfEntityModel), in the attribute "databaseTables" and "formTables".

When completed the following command by the terminal: flutter pub run build_runner build --delete-conflicting-outputs

At the end of the file generation process, the file "model.g.view.dart" with errors will be generated.

Generated file:

    Widget buildRowDateRecord() {
    return Row(children: <Widget>[
      Expanded(
        flex: 1,
        child: TextFormField(
          onTap: () => UITools.showDateTimePicker(context,
              minTime: DateTime.parse('1900-01-01'),
              onConfirm: (sqfSelectedDate) {
            txtDateRecord.text = UITools.convertDate(sqfSelectedDate);
            txtTimeForDataCadastro.text = UITools.convertTime(sqfSelectedDate);
            setState(() {
              final d = DateTime.tryParse(txtDateRecord.text) ??
                  testdb.dateRecord ??
                  DateTime.now();
              testdb.dateRecord = DateTime(sqfSelectedDate.year,
                      sqfSelectedDate.month, sqfSelectedDate.day)
                  .add(Duration(
                      hours: d.hour, minutes: d.minute, seconds: d.second));
            });
          },
              currentTime: DateTime.tryParse(txtDateRecord.text) ??
                  testdb.dateRecord ??
                  DateTime.now()),
          controller: txtDateRecord,
          decoration: InputDecoration(labelText: 'DateRecord'),
        ),
      ),
      Expanded(
          flex: 1,
          child: TextFormField(
            onTap: () => UITools.showDateTimePicker(context,
                onConfirm: (sqfSelectedDate) {
              txtTimeForDateRecord.text =
                  UITools.convertTime(sqfSelectedDate);
              setState(() {
                final d = DateTime.tryParse(txtDateRecord.text) ??
                    testdb.dateRecord ??
                    DateTime.now();
                testdb.dateRecord = DateTime(d.year, d.month, d.day)
                    .add(Duration(
                        hours: sqfSelectedDate.hour,
                        minutes: sqfSelectedDate.minute,
                        seconds: sqfSelectedDate.second));
                txtDateRecord.text =
                    UITools.convertDate(testdb.dateRecord!);
              });
            },
                currentTime: DateTime.tryParse(
                        '${UITools.convertDate(DateTime.now())} ${txtTimeForDateRecord.text}') ??
                    testdb.dateRecord ??
                    DateTime.now()),
            controller: txtTimeForDateRecord,
            decoration: InputDecoration(labelText: 'time'),
          ))
    ]);
  }

According to dart's compilation output:

lib/ORM_NEW/model/model.g.view.dart:360:21: Error: The getter 'testdb' isn't defined for the class 'TestDBAddState'.
 - 'TestDBAddState' is from 'package:my_wms/ORM_NEW/model/model.dart' ('lib/ORM_NEW/model/model.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'testdb'.
                    testdb.dateRecord??
                    ^^^^^^^^^^^^^^^^

When checking the error, note that the capital letters entered in the "modelName" field of the "SqfEntityTable" were not respected. It should be "TestDB" but "testdb" was generated.

But if I manually change it to "testDB" it also works.

hhtokpinar commented 2 years ago

Sorry! PR #271 caused this. I fixed now pls try the latest sqfentity_gen 2.3.0+1

@a7mdragab Notice that you shouldn't have changed the definitions of tablename, modelname, or canceled tolower() or something ok? :)

GoedertDalmolin commented 2 years ago

I ran tests and concluded that the problem was fixed.

Note: This was my first official issue. As this issue has been fixed, I am closing the issue.

Thank you very much.